-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.custom_radio_checkbox.js
78 lines (75 loc) · 1.94 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
67
68
69
70
71
72
73
74
75
76
77
78
//##############################
// jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms
// By Dharmavirsinh Jhala - [email protected]
// Date of Release: 13th March 10
// Version: 0.8
/*
USAGE:
$(document).ready(function(){
$(":radio").behaveLikeCheckbox();
}
*/
var elmHeight = "25"; // should be specified based on image size
// 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).mousedown(function() { $(this).dgEffect(); });
$(this).mouseup(function() { $(this).dgHandle(); });
},
dgClear: function()
{
if($(this).data("checked") == true)
{
$(this).css("backgroundPosition","center -"+(elmHeight*2)+"px");
}
else
{
$(this).css("backgroundPosition","center 0");
}
},
dgEffect: function()
{
if($(this).data("checked") == true)
$(this).css({backgroundPosition:"center -"+(elmHeight*3)+"px"});
else
$(this).css({backgroundPosition:"center -"+(elmHeight)+"px"});
},
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).css({backgroundPosition:"center -"+(elmHeight*2)+"px"});
},
dgUncheck: function(div)
{
$(this).attr("checked",false);
if(div != -1)
$(div).data('checked',false).css({backgroundPosition:"center 0"});
else
$(this).parent().data("checked",false).css({backgroundPosition:"center 0"});
}
});