-
Notifications
You must be signed in to change notification settings - Fork 2
/
customRadioCheck.js
39 lines (33 loc) · 1.07 KB
/
customRadioCheck.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
/*
* customRadioCheck: jQuery plguin for checkbox and radio replacement
* Usage: $('input[type=checkbox], input[type=radio]').customRadioCheck();
* Author: Cedric Ruiz
* License: MIT
*/
;(function(){
$.fn.customRadioCheck = function() {
return this.each(function() {
var $this = $(this);
var $span = $('<span/>');
$span.addClass('custom-'+ ($this.is(':checkbox') ? 'check' : 'radio'));
$this.is(':checked') && $span.addClass('checked'); // init
$span.insertAfter($this);
$this.parent('label').addClass('custom-label')
.attr('onclick', ''); // Fix clicking label in iOS
// hide by shifting left
$this.css({ position: 'absolute', left: '-9999px' });
// Events
$this.on({
change: function() {
if ($this.is(':radio')) {
$this.parent().siblings('label')
.find('.custom-radio').removeClass('checked');
}
$span.toggleClass('checked', $this.is(':checked'));
},
focus: function() { $span.addClass('focus'); },
blur: function() { $span.removeClass('focus'); }
});
});
};
}());