, , . . , , .
, .
init jQuery.data(), , simpleSwitchUpdate . , , , $.extend $.fn.simpleSwitch newOptions. , .
(function($) {
var Switch = {
init : function(options, elm) {
var self = this;
self.$elm = $(elm);
self.$elm.empty();
self.options = $.extend({}, $.fn.simpleSwitch.options, options);
self.$elm.data("switchData", self.options);
self.$elm.append(self.createSwitch());
},
createSwitch : function() {
}
};
$.fn.simpleSwitch = function(options) {
return this.each(function() {
var simpleSwitch = Object.create(Switch);
simpleSwitch.init(options, this);
});
};
$.fn.simpleSwitchUpdate = function(options) {
var switchData = this.data("switchData");
var newOptions;
if (switchData) {
newOptions = $.extend({}, switchData, options);
} else {
newOptions = $.extend({}, $.fn.simpleSwitch.options, options);
}
return this.simpleSwitch(newOptions);
};
$.fn.simpleSwitch.options = {
width : 25,
height : 15,
on : true,
onDirection : "right",
easing : "easeOutQuint",
roundBorder : true,
onColor : "orange",
offColor : "lightgray",
onToggle : null
};
})(jQuery);
JSFIDDLE LINK