1/* 2 * jQuery mSwitch v.1 3 * 4 * Copyright (c) 2018 Dario Montalbano 5 * 6 * For use this library is necessary include jquery-ui autocomplete in your project 7 * 8 */ 9 10(function($) { 11 12 $.fn.extend({ 13 mSwitch: function(params) { 14 15 var elements; 16 params = $.extend({}, $.mSwitch.defaults, params); 17 18 if (this && this.length > 0){ 19 elements = this.each(function() { 20 new $.mSwitch(this, params); 21 }); 22 23 if (params.onRendered && typeof params.onRendered == 'function'){ 24 params.onRendered($(this)); 25 } 26 } 27 28 return elements; 29 30 } 31 }); 32 33 $.mSwitch = function(_this, params) { 34 if ($(_this) && $(_this).is(":checkbox")){ 35 $(_this).addClass("m_switch_check"); 36 var element_parent = $(_this).parent(); 37 var element = $(_this).detach().html(); 38 var $div = $("<div/>").attr("class", "m_switch"); 39 var $b = $("<b/>").attr("class", "m_switch_b m_switch_element"); 40 $b.appendTo($div); 41 $(_this).detach().prependTo($div); 42 element_parent.append($div); 43 44 if ($(_this).is(":checked")){ 45 $.mSwitch.turnOn($(_this)); 46 }else{ 47 $.mSwitch.turnOff($(_this)); 48 } 49 50 if (params.onRender && typeof params.onRender == 'function'){ 51 params.onRender($(_this)); 52 } 53 54 $(_this).change(function(){ 55 if ($(_this).is(":checked")){ 56 if (params.onTurnOn && typeof params.onTurnOn == 'function'){ 57 params.onTurnOn($(this)); 58 } 59 $.mSwitch.turnOn($(this)); 60 }else if (!$(_this).is(":checked")){ 61 if (params.onTurnOff && typeof params.onTurnOff == 'function'){ 62 params.onTurnOff($(this)); 63 } 64 $.mSwitch.turnOff($(this)); 65 } 66 }); 67 } 68 } 69 70 $.mSwitch.turnOn = function(elem){ 71 if (elem.parent(".m_switch").length > 0){ 72 if (!elem.parent(".m_switch").hasClass("m_switch_color")){ 73 elem.parent(".m_switch").addClass("m_switch_color"); 74 } 75 } 76 if (elem.next("b.m_switch_b").length > 0){ 77 if (!elem.next("b.m_switch_b").hasClass("m_switch_checked")){ 78 elem.next("b.m_switch_b").addClass("m_switch_checked"); 79 } 80 } 81 if (elem.parent(".m_switch").hasClass("m_switch_color") && 82 elem.next("b.m_switch_b").hasClass("m_switch_checked")){ 83 elem.attr('checked', true); 84 } 85 } 86 87 $.mSwitch.turnOff = function(elem){ 88 if (elem.parent(".m_switch").length > 0){ 89 if (elem.parent(".m_switch").hasClass("m_switch_color")){ 90 elem.parent(".m_switch").removeClass("m_switch_color"); 91 } 92 } 93 if (elem.next("b.m_switch_b").length > 0){ 94 if (elem.next("b.m_switch_b").hasClass("m_switch_checked")){ 95 elem.next("b.m_switch_b").removeClass("m_switch_checked"); 96 } 97 } 98 if (!elem.parent(".m_switch").hasClass("m_switch_color") && 99 !elem.next("b.m_switch_b").hasClass("m_switch_checked")){ 100 elem.attr('checked', false); 101 } 102 } 103 104 $.mSwitch.isOn = function(elem){ 105 var res = false; 106 if (elem.is(":checked")){ 107 res = true; 108 } 109 return res; 110 } 111 112 $.mSwitch.defaults = { 113 onRendered: function(){}, 114 onRender: function(elem){}, 115 onTurnOn: function(elem){ 116 return true; 117 }, 118 onTurnOff: function(elem){ 119 return true; 120 } 121 } 122 123}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.