1/* Simple JavaScript Inheritance 2 * By John Resig http://ejohn.org/ 3 * https://johnresig.com/blog/simple-javascript-inheritance/ 4 * MIT Licensed. 5 */ 6(function(){ 7 var initializing = false; 8 9 window.JQClass = function(){}; 10 11 JQClass.classes = {}; 12 13 JQClass.extend = function extender(prop) { 14 var base = this.prototype; 15 16 initializing = true; 17 var prototype = new this(); 18 initializing = false; 19 20 for (var name in prop) { 21 22 prototype[name] = typeof prop[name] == 'function' && 23 typeof base[name] == 'function' ? 24 (function(name, fn){ 25 return function() { 26 var __super = this._super; 27 28 this._super = function(args) { 29 return base[name].apply(this, args || []); 30 }; 31 32 var ret = fn.apply(this, arguments); 33 34 this._super = __super; 35 36 return ret; 37 }; 38 })(name, prop[name]) : 39 prop[name]; 40 } 41 42 function JQClass() { 43 44 if (!initializing && this._init) { 45 this._init.apply(this, arguments); 46 } 47 } 48 49 JQClass.prototype = prototype; 50 51 JQClass.prototype.constructor = JQClass; 52 53 JQClass.extend = extender; 54 55 return JQClass; 56 }; 57})(); 58 59(function($) { 60 JQClass.classes.JQPlugin = JQClass.extend({ 61 62 name: 'plugin', 63 64 defaultOptions: {}, 65 66 regionalOptions: {}, 67 68 _getters: [], 69 70 _getMarker: function() { 71 return 'is-' + this.name; 72 }, 73 74 _init: function() { 75 76 $.extend(this.defaultOptions, (this.regionalOptions && this.regionalOptions['']) || {}); 77 78 var jqName = camelCase(this.name); 79 80 $[jqName] = this; 81 82 $.fn[jqName] = function(options) { 83 var otherArgs = Array.prototype.slice.call(arguments, 1); 84 if ($[jqName]._isNotChained(options, otherArgs)) { 85 return $[jqName][options].apply($[jqName], [this[0]].concat(otherArgs)); 86 } 87 return this.each(function() { 88 if (typeof options === 'string') { 89 if (options[0] === '_' || !$[jqName][options]) { 90 throw 'Unknown method: ' + options; 91 } 92 $[jqName][options].apply($[jqName], [this].concat(otherArgs)); 93 } 94 else { 95 $[jqName]._attach(this, options); 96 } 97 }); 98 }; 99 }, 100 101 setDefaults: function(options) { 102 $.extend(this.defaultOptions, options || {}); 103 }, 104 105 _isNotChained: function(name, otherArgs) { 106 if (name === 'option' && (otherArgs.length === 0 || 107 (otherArgs.length === 1 && typeof otherArgs[0] === 'string'))) { 108 return true; 109 } 110 return $.inArray(name, this._getters) > -1; 111 }, 112 113 _attach: function(elem, options) { 114 elem = $(elem); 115 if (elem.hasClass(this._getMarker())) { 116 return; 117 } 118 elem.addClass(this._getMarker()); 119 options = $.extend({}, this.defaultOptions, this._getMetadata(elem), options || {}); 120 var inst = $.extend({name: this.name, elem: elem, options: options}, 121 this._instSettings(elem, options)); 122 elem.data(this.name, inst); // Save instance against element 123 this._postAttach(elem, inst); 124 this.option(elem, options); 125 }, 126 127 _instSettings: function(elem, options) { 128 return {}; 129 }, 130 131 _postAttach: function(elem, inst) { 132 }, 133 134 _getMetadata: function(elem) { 135 try { 136 var data = elem.data(this.name.toLowerCase()) || ''; 137 data = data.replace(/'/g, '"'); 138 data = data.replace(/([a-zA-Z0-9]+):/g, function(match, group, i) { 139 var count = data.substring(0, i).match(/"/g); // Handle embedded ':' 140 return (!count || count.length % 2 === 0 ? '"' + group + '":' : group + ':'); 141 }); 142 data = $.parseJSON('{' + data + '}'); 143 for (var name in data) { // Convert dates 144 var value = data[name]; 145 if (typeof value === 'string' && value.match(/^new Date\((.*)\)$/)) { 146 data[name] = eval(value); 147 } 148 } 149 return data; 150 } 151 catch (e) { 152 return {}; 153 } 154 }, 155 156 _getInst: function(elem) { 157 return $(elem).data(this.name) || {}; 158 }, 159 160 option: function(elem, name, value) { 161 elem = $(elem); 162 var inst = elem.data(this.name); 163 if (!name || (typeof name === 'string' && value == null)) { 164 var options = (inst || {}).options; 165 return (options && name ? options[name] : options); 166 } 167 if (!elem.hasClass(this._getMarker())) { 168 return; 169 } 170 var options = name || {}; 171 if (typeof name === 'string') { 172 options = {}; 173 options[name] = value; 174 } 175 this._optionsChanged(elem, inst, options); 176 $.extend(inst.options, options); 177 }, 178 179 _optionsChanged: function(elem, inst, options) { 180 }, 181 182 destroy: function(elem) { 183 elem = $(elem); 184 if (!elem.hasClass(this._getMarker())) { 185 return; 186 } 187 this._preDestroy(elem, this._getInst(elem)); 188 elem.removeData(this.name).removeClass(this._getMarker()); 189 }, 190 191 _preDestroy: function(elem, inst) { 192 } 193 }); 194 195 function camelCase(name) { 196 return name.replace(/-([a-z])/g, function(match, group) { 197 return group.toUpperCase(); 198 }); 199 } 200 201 $.JQPlugin = { 202 203 createPlugin: function(superClass, overrides) { 204 if (typeof superClass === 'object') { 205 overrides = superClass; 206 superClass = 'JQPlugin'; 207 } 208 superClass = camelCase(superClass); 209 var className = camelCase(overrides.name); 210 JQClass.classes[className] = JQClass.classes[superClass].extend(overrides); 211 new JQClass.classes[className](); 212 } 213 }; 214 215})(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.