-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCHSwitchBox.js
70 lines (62 loc) · 2.5 KB
/
CHSwitchBox.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
/*CHSwitchBox.js
Description: An extremely simple but attractive toggle switch you can use in place of a standard input checkbox.
Author: Collin Henderson
Website: http://syropia.net
Contact: [email protected]
Version: 1.3
*/
(function($) {
//Attach this new method to jQuery
$.fn.extend({
CHSwitchBox: function(options) {
//Set up defaults
var defaults = {
onLabel: 'On',
offLabel: 'Off'
};
var options = $.extend({}, defaults, options)
//Iterate over the current set of matched elements
return this.each(function() {
var $markup = $('<div class="switch"><span class="green">'+options.onLabel+'</span><span class="red">'+options.offLabel+'</span><div class="thumb"></div></div>');
$markup.insertAfter($(this));
$(this).hide();
$('div.switch').toggle(function()
{
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))
{
$(this).children('div.thumb').css({
'-webkit-transition-duration': '300ms',
'-webkit-transform': 'translate3d(53px,0,0)'
});
}
else
{
$(this).children('div.thumb').animate({
left: 26
},
300);
}
$(this).prev('input').attr('checked', true);
},
function()
{
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))
{
$(this).children('div.thumb').css({
'-webkit-transition-duration': '300ms',
'-webkit-transform': 'translate3d(0,0,0)'
});
}
else
{
$(this).children('div.thumb').animate({
left: -27
},
300);
}
$(this).prev('input').attr('checked', false);
});
});
}
});
})(jQuery);