1(function() { 2 3 var sooCheckbox = function(el, cloned) { 4 this.$el = $(el); 5 this.defaultChecked = this.$el[0].checked; 6 this.htmlOff = this.$el.attr('data-html-on') || '<i class="far fa-square"></i>'; 7 this.htmlOn = this.$el.attr('data-html-off') || '<i class="fas fa-check-square"></i>'; 8 this.$label = this.$el.closest('label'); 9 this.render(cloned); 10 this.events(); 11 }; 12 13 sooCheckbox.prototype.render = function(cloned) { 14 15 this.$el.css({ visibility: 'hidden', width: 0, height: 0 }); 16 17 if (cloned) { 18 this.$el.next('.soo-checkbox-wrapper').remove(); 19 } 20 21 var html = this.$el[0].checked? this.htmlOn : this.htmlOff; 22 this.$wrapper = $('<span class="soo-checkbox-wrapper" style="cursor:pointer;user-select:none">' + html + '</span>'); 23 this.$wrapper.insertAfter(this.$el); 24 25 this.$label.css({ cursor: 'pointer', 'user-select': 'none' }); 26 }; 27 28 sooCheckbox.prototype.events = function() { 29 30 var that = this; 31 32 this.$wrapper.on('click', function(e) { 33 e.preventDefault(); 34 that.toggle(); 35 return false; 36 }); 37 38 this.$label.on('click', function(e) { 39 40 if ($(e.target).is('a')) { 41 return true; 42 } 43 44 e.preventDefault(); 45 that.toggle(); 46 return false; 47 }); 48 49 this.$el.on('click', function(e) { 50 e.preventDefault(); 51 that.toggle(); 52 return false; 53 }); 54 55 this.$el.on('change', function(e) { 56 that.update(); 57 }); 58 59 this.$el.closest('form').on('reset', function(e) { 60 that.defaultChecked? that.$el.attr('checked', 'checked') : that.$el.removeAttr('checked') 61 that.update(); 62 }); 63 }; 64 65 sooCheckbox.prototype.toggle = function() { 66 this.$el[0].checked? this.$el.removeAttr('checked') : this.$el.attr('checked', 'checked'); 67 this.$el.trigger('toggle'); 68 this.update(); 69 }; 70 71 sooCheckbox.prototype.update = function() { 72 this.$wrapper.html(this.$el[0].checked? this.htmlOn : this.htmlOff); 73 this.$el[0].checked? this.$wrapper.addClass('soo-checkbox-checked') : this.$wrapper.removeClass('soo-checkbox-checked'); 74 this.$el[0].checked? this.$label.addClass('soo-checkbox-checked-label') : this.$label.removeClass('soo-checkbox-checked-label'); 75 }; 76 77 $.fn.sooCheckbox = function() { 78 return this.each(function() { 79 if (!$(this).attr('data-soo-checkbox')) { 80 $(this).attr('data-soo-checkbox', true); 81 new sooCheckbox(this, false); 82 } 83 }); 84 }; 85 86 $('.soo-checkbox').sooCheckbox(); 87 88 $.fn.sooCheckboxCloned = function() { 89 return this.each(function() { 90 if ($(this).attr('data-soo-checkbox')) { 91 new sooCheckbox(this, true); 92 } 93 }); 94 }; 95 96})();
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.