-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmCheck.js
30 lines (25 loc) · 1.12 KB
/
mCheck.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
(function ($) {
$.fn.mCheck = function (options) {
var settings = $.extend({
// Settings here!
}, options);
var originalCheckbox = $(this);
if (originalCheckbox.attr('type') != 'checkbox') {
console.error('The object in selector is not of type \'checkbox\'!');
return false;
}
originalCheckbox.hide();
var newCheckbox = originalCheckbox.wrap($('<span class="mCheck"></span>')).parent();
var newCheckboxInner = $('<span class="mCheckState"></span>').prependTo(newCheckbox);
newCheckbox.outerWidth(originalCheckbox.width());
newCheckbox.outerHeight(originalCheckbox.height());
originalCheckbox.change(function () {
newCheckboxInner.removeClass('mCheckOn mCheckOff');
newCheckboxInner.addClass(originalCheckbox.prop('checked') ? 'mCheckOn' : 'mCheckOff');
}).trigger('change');
newCheckbox.off('click').click(function () {
originalCheckbox.prop('checked', !originalCheckbox.prop('checked')).change();
});
return originalCheckbox;
};
}(jQuery));