1/* 2 * blueimp helper JS 1.2.0 3 * https://github.com/blueimp/Gallery 4 * 5 * Copyright 2013, Sebastian Tschan 6 * https://blueimp.net 7 * 8 * Licensed under the MIT license: 9 * http://www.opensource.org/licenses/MIT 10 */ 11 12/* global define, window, document */ 13 14(function () { 15 'use strict'; 16 17 function extend(obj1, obj2) { 18 var prop; 19 for (prop in obj2) { 20 if (obj2.hasOwnProperty(prop)) { 21 obj1[prop] = obj2[prop]; 22 } 23 } 24 return obj1; 25 } 26 27 function Helper(query) { 28 if (!this || this.find !== Helper.prototype.find) { 29 // Called as function instead of as constructor, 30 // so we simply return a new instance: 31 return new Helper(query); 32 } 33 this.length = 0; 34 if (query) { 35 if (typeof query === 'string') { 36 query = this.find(query); 37 } 38 if (query.nodeType || query === query.window) { 39 // Single HTML element 40 this.length = 1; 41 this[0] = query; 42 } else { 43 // HTML element collection 44 var i = query.length; 45 this.length = i; 46 while (i) { 47 i -= 1; 48 this[i] = query[i]; 49 } 50 } 51 } 52 } 53 54 Helper.extend = extend; 55 56 Helper.contains = function (container, element) { 57 do { 58 element = element.parentNode; 59 if (element === container) { 60 return true; 61 } 62 } while (element); 63 return false; 64 }; 65 66 Helper.parseJSON = function (string) { 67 return window.JSON && JSON.parse(string); 68 }; 69 70 extend(Helper.prototype, { 71 72 find: function (query) { 73 var container = this[0] || document; 74 if (typeof query === 'string') { 75 if (container.querySelectorAll) { 76 query = container.querySelectorAll(query); 77 } else if (query.charAt(0) === '#') { 78 query = container.getElementById(query.slice(1)); 79 } else { 80 query = container.getElementsByTagName(query); 81 } 82 } 83 return new Helper(query); 84 }, 85 86 hasClass: function (className) { 87 if (!this[0]) { 88 return false; 89 } 90 return new RegExp('(^|\\s+)' + className + 91 '(\\s+|$)').test(this[0].className); 92 }, 93 94 addClass: function (className) { 95 var i = this.length, 96 element; 97 while (i) { 98 i -= 1; 99 element = this[i]; 100 if (!element.className) { 101 element.className = className; 102 return this; 103 } 104 if (this.hasClass(className)) { 105 return this; 106 } 107 element.className += ' ' + className; 108 } 109 return this; 110 }, 111 112 removeClass: function (className) { 113 var regexp = new RegExp('(^|\\s+)' + className + '(\\s+|$)'), 114 i = this.length, 115 element; 116 while (i) { 117 i -= 1; 118 element = this[i]; 119 element.className = element.className.replace(regexp, ' '); 120 } 121 return this; 122 }, 123 124 on: function (eventName, handler) { 125 var eventNames = eventName.split(/\s+/), 126 i, 127 element; 128 while (eventNames.length) { 129 eventName = eventNames.shift(); 130 i = this.length; 131 while (i) { 132 i -= 1; 133 element = this[i]; 134 if (element.addEventListener) { 135 element.addEventListener(eventName, handler, false); 136 } else if (element.attachEvent) { 137 element.attachEvent('on' + eventName, handler); 138 } 139 } 140 } 141 return this; 142 }, 143 144 off: function (eventName, handler) { 145 var eventNames = eventName.split(/\s+/), 146 i, 147 element; 148 while (eventNames.length) { 149 eventName = eventNames.shift(); 150 i = this.length; 151 while (i) { 152 i -= 1; 153 element = this[i]; 154 if (element.removeEventListener) { 155 element.removeEventListener(eventName, handler, false); 156 } else if (element.detachEvent) { 157 element.detachEvent('on' + eventName, handler); 158 } 159 } 160 } 161 return this; 162 }, 163 164 empty: function () { 165 var i = this.length, 166 element; 167 while (i) { 168 i -= 1; 169 element = this[i]; 170 while (element.hasChildNodes()) { 171 element.removeChild(element.lastChild); 172 } 173 } 174 return this; 175 }, 176 177 first: function () { 178 return new Helper(this[0]); 179 } 180 181 }); 182 183 if (typeof define === 'function' && define.amd) { 184 define(function () { 185 return Helper; 186 }); 187 } else { 188 window.blueimp = window.blueimp || {}; 189 window.blueimp.helper = Helper; 190 } 191}());
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.