-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.custom_radio_checkbox.js
66 lines (64 loc) · 1.67 KB
/
jquery.custom_radio_checkbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//##############################
// jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms
// By Dharmavirsinh Jhala - [email protected]
// Revised by Chelsea Robb - github.com/chelsea
// Date of update: 4th February 2011
// Version: 0.9
//
// Switched to add or remove a checked class on the bound
// element. Simply set a .checked class in your css to display
// however you want
/*
USAGE:
$(document).ready(function(){
$("radioWrapper").dgCheck();
}
*/
// Extend JQuery Functionality For Custom Radio Button Functionality
jQuery.fn.extend({
dgStyle: function()
{
// Initialize with initial load time control state
$.each($(this), function(){
var elm = $(this).children().get(0);
elmType = $(elm).attr("type");
$(this).data('type',elmType);
$(this).data('checked',$(elm).attr("checked"));
$(this).dgClear();
});
$(this).mouseup(function() { $(this).dgHandle(); });
},
dgClear: function()
{
if($(this).data("checked") == true)
$(this).addClass("checked");
else
$(this).removeClass("checked");
},
dgHandle: function()
{
var elm = $(this).children().get(0);
if($(this).data("checked") == true)
$(elm).dgUncheck(this);
else
$(elm).dgCheck(this);
if($(this).data('type') == 'radio')
{
$.each($("input[name='"+$(elm).attr("name")+"']"),function()
{
if(elm!=this)
$(this).dgUncheck(-1);
});
}
},
dgCheck: function(div)
{
$(this).attr("checked",true);
$(div).data('checked',true).addClass('checked');
},
dgUncheck: function(div)
{
$(this).attr("checked",false);
$(this).parent().data("checked",false).removeClass("checked");
}
});