jquery.tzCheckbox_wev8.js
2.48 KB
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
79
(function($){
$.fn.tzCheckbox = function(options){
// Default On / Off labels:
options = $.extend({
labels : ['ON','OFF']
},options);
return this.each(function(){
var originalCheckBox = $(this),
labels = [];
// Checking for the data-on / data-off HTML5 data attributes:
if(originalCheckBox.data('on')){
labels[0] = originalCheckBox.data('on');
labels[1] = originalCheckBox.data('off');
}
else labels = options.labels;
// Creating the new checkbox markup:
var checkBox = $('<span>',{
"class": 'tzCheckBox '+(this.checked?'checked':''),
"html": '<span class="tzCBContent">'+labels[this.checked?0:1]+
'</span><span class="tzCBPart"></span>'
});
if(originalCheckBox.attr('disabled')){
checkBox.attr("title",SystemEnv.getHtmlNoteName(3508,readCookie("languageidweaver"))).attr('disabled',true);
}
// Inserting the new checkbox, and hiding the original:
if(originalCheckBox.next().is("span") && (originalCheckBox.next().attr("class")==="tzCheckBox " || originalCheckBox.next().attr("class")==="tzCheckBox checked")){
}else{
checkBox.insertAfter(originalCheckBox.hide());
}
checkBox.click(function(){
if(originalCheckBox.attr('disabled')) return;
checkBox.toggleClass('checked');
var isChecked = checkBox.hasClass('checked');
// Synchronizing the original checkbox:
originalCheckBox.attr('checked',isChecked);
originalCheckBox.trigger("click");
originalCheckBox.attr('checked',isChecked);
checkBox.find('.tzCBContent').html(labels[isChecked?0:1]);
});
// Listening for changes on the original and affecting the new one:
});
};
})(jQuery);
function changeSwitchStatus(obj,checked){
if(checked==true||checked==false){
jQuery(obj).attr("checked",checked);
}
if(checked){
jQuery(obj).next("span.tzCheckBox").addClass("checked");
}else{
jQuery(obj).next("span.tzCheckBox").removeClass("checked");
}
}
function disOrEnableSwitch(obj,disabled){
if(disabled==true||disabled==false){
jQuery(obj).attr("disabled",disabled);
}
if(disabled){
jQuery(obj).next("span.tzCheckBox").attr("title",SystemEnv.getHtmlNoteName(3508,readCookie("languageidweaver"))).attr('disabled',true);
}else{
jQuery(obj).next("span.tzCheckBox").removeAttr("title").removeAttr('disabled');
}
}
function removeBeatySwitch(obj){
if(jQuery(obj).next("span.tzCheckBox").length==0)return;
jQuery(obj).css("display","");
var tzCheckBox = jQuery(obj).next("span.tzCheckBox");
tzCheckBox.remove();
}