|
| 1 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys |
| 2 | +if (!Object.keys) { |
| 3 | + Object.keys = (function () { |
| 4 | + var hasOwnProperty = Object.prototype.hasOwnProperty, |
| 5 | + hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), |
| 6 | + dontEnums = [ |
| 7 | + 'toString', |
| 8 | + 'toLocaleString', |
| 9 | + 'valueOf', |
| 10 | + 'hasOwnProperty', |
| 11 | + 'isPrototypeOf', |
| 12 | + 'propertyIsEnumerable', |
| 13 | + 'constructor' |
| 14 | + ], |
| 15 | + dontEnumsLength = dontEnums.length; |
| 16 | + |
| 17 | + return function (obj) { |
| 18 | + if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object'); |
| 19 | + |
| 20 | + var result = []; |
| 21 | + |
| 22 | + for (var prop in obj) { |
| 23 | + if (hasOwnProperty.call(obj, prop)) result.push(prop); |
| 24 | + } |
| 25 | + |
| 26 | + if (hasDontEnumBug) { |
| 27 | + for (var i=0; i < dontEnumsLength; i++) { |
| 28 | + if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]); |
| 29 | + } |
| 30 | + } |
| 31 | + return result; |
| 32 | + }; |
| 33 | + })(); |
| 34 | +} |
| 35 | + |
| 36 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter |
| 37 | +if (!Array.prototype.filter) |
| 38 | +{ |
| 39 | + Array.prototype.filter = function(fun /*, thisp */) |
| 40 | + { |
| 41 | + "use strict"; |
| 42 | + |
| 43 | + if (this == null) |
| 44 | + throw new TypeError(); |
| 45 | + |
| 46 | + var t = Object(this); |
| 47 | + var len = t.length >>> 0; |
| 48 | + if (typeof fun != "function") |
| 49 | + throw new TypeError(); |
| 50 | + |
| 51 | + var res = []; |
| 52 | + var thisp = arguments[1]; |
| 53 | + for (var i = 0; i < len; i++) |
| 54 | + { |
| 55 | + if (i in t) |
| 56 | + { |
| 57 | + var val = t[i]; // in case fun mutates this |
| 58 | + if (fun.call(thisp, val, i, t)) |
| 59 | + res.push(val); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return res; |
| 64 | + }; |
| 65 | +} |
| 66 | + |
| 67 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim |
| 68 | +if (!String.prototype.trim) { |
| 69 | + String.prototype.trim = function () { |
| 70 | + return this.replace(/^\s+|\s+$/g, ''); |
| 71 | + }; |
| 72 | +} |
| 73 | + |
| 74 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach |
| 75 | +if (!Array.prototype.forEach) |
| 76 | +{ |
| 77 | + Array.prototype.forEach = function(fun /*, thisArg */) |
| 78 | + { |
| 79 | + "use strict"; |
| 80 | + |
| 81 | + if (this === void 0 || this === null) |
| 82 | + throw new TypeError(); |
| 83 | + |
| 84 | + var t = Object(this); |
| 85 | + var len = t.length >>> 0; |
| 86 | + if (typeof fun !== "function") |
| 87 | + throw new TypeError(); |
| 88 | + |
| 89 | + var thisArg = arguments.length >= 2 ? arguments[1] : void 0; |
| 90 | + for (var i = 0; i < len; i++) |
| 91 | + { |
| 92 | + if (i in t) |
| 93 | + fun.call(thisArg, t[i], i, t); |
| 94 | + } |
| 95 | + }; |
| 96 | +} |
| 97 | + |
| 98 | +// Production steps of ECMA-262, Edition 5, 15.4.4.19 |
| 99 | +// Reference: http://es5.github.com/#x15.4.4.19 |
| 100 | +if (!Array.prototype.map) { |
| 101 | + Array.prototype.map = function(callback, thisArg) { |
| 102 | + |
| 103 | + var T, A, k; |
| 104 | + |
| 105 | + if (this == null) { |
| 106 | + throw new TypeError(" this is null or not defined"); |
| 107 | + } |
| 108 | + |
| 109 | + // 1. Let O be the result of calling ToObject passing the |this| value as the argument. |
| 110 | + var O = Object(this); |
| 111 | + |
| 112 | + // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". |
| 113 | + // 3. Let len be ToUint32(lenValue). |
| 114 | + var len = O.length >>> 0; |
| 115 | + |
| 116 | + // 4. If IsCallable(callback) is false, throw a TypeError exception. |
| 117 | + // See: http://es5.github.com/#x9.11 |
| 118 | + if (typeof callback !== "function") { |
| 119 | + throw new TypeError(callback + " is not a function"); |
| 120 | + } |
| 121 | + |
| 122 | + // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. |
| 123 | + if (thisArg) { |
| 124 | + T = thisArg; |
| 125 | + } |
| 126 | + |
| 127 | + // 6. Let A be a new array created as if by the expression new Array(len) where Array is |
| 128 | + // the standard built-in constructor with that name and len is the value of len. |
| 129 | + A = new Array(len); |
| 130 | + |
| 131 | + // 7. Let k be 0 |
| 132 | + k = 0; |
| 133 | + |
| 134 | + // 8. Repeat, while k < len |
| 135 | + while(k < len) { |
| 136 | + |
| 137 | + var kValue, mappedValue; |
| 138 | + |
| 139 | + // a. Let Pk be ToString(k). |
| 140 | + // This is implicit for LHS operands of the in operator |
| 141 | + // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. |
| 142 | + // This step can be combined with c |
| 143 | + // c. If kPresent is true, then |
| 144 | + if (k in O) { |
| 145 | + |
| 146 | + // i. Let kValue be the result of calling the Get internal method of O with argument Pk. |
| 147 | + kValue = O[ k ]; |
| 148 | + |
| 149 | + // ii. Let mappedValue be the result of calling the Call internal method of callback |
| 150 | + // with T as the this value and argument list containing kValue, k, and O. |
| 151 | + mappedValue = callback.call(T, kValue, k, O); |
| 152 | + |
| 153 | + // iii. Call the DefineOwnProperty internal method of A with arguments |
| 154 | + // Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true}, |
| 155 | + // and false. |
| 156 | + |
| 157 | + // In browsers that support Object.defineProperty, use the following: |
| 158 | + // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true }); |
| 159 | + |
| 160 | + // For best browser support, use the following: |
| 161 | + A[ k ] = mappedValue; |
| 162 | + } |
| 163 | + // d. Increase k by 1. |
| 164 | + k++; |
| 165 | + } |
| 166 | + |
| 167 | + // 9. return A |
| 168 | + return A; |
| 169 | + }; |
| 170 | +} |
| 171 | + |
| 172 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf |
| 173 | +if (!Array.prototype.indexOf) { |
| 174 | + Array.prototype.indexOf = function (searchElement, fromIndex) { |
| 175 | + if ( this === undefined || this === null ) { |
| 176 | + throw new TypeError( '"this" is null or not defined' ); |
| 177 | + } |
| 178 | + |
| 179 | + var length = this.length >>> 0; // Hack to convert object.length to a UInt32 |
| 180 | + |
| 181 | + fromIndex = +fromIndex || 0; |
| 182 | + |
| 183 | + if (Math.abs(fromIndex) === Infinity) { |
| 184 | + fromIndex = 0; |
| 185 | + } |
| 186 | + |
| 187 | + if (fromIndex < 0) { |
| 188 | + fromIndex += length; |
| 189 | + if (fromIndex < 0) { |
| 190 | + fromIndex = 0; |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + for (;fromIndex < length; fromIndex++) { |
| 195 | + if (this[fromIndex] === searchElement) { |
| 196 | + return fromIndex; |
| 197 | + } |
| 198 | + } |
| 199 | + |
| 200 | + return -1; |
| 201 | + }; |
| 202 | +} |
| 203 | +// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray |
| 204 | + |
| 205 | +if (! Array.isArray) { |
| 206 | + Array.isArray = function(obj) { |
| 207 | + return Object.prototype.toString.call(obj) === "[object Array]"; |
| 208 | + }; |
| 209 | +} |
| 210 | + |
| 211 | +// https://github.com/ttaubert/node-arraybuffer-slice |
| 212 | +// (c) 2013 Tim Taubert <[email protected]> |
| 213 | +// arraybuffer-slice may be freely distributed under the MIT license. |
| 214 | + |
| 215 | +"use strict"; |
| 216 | + |
| 217 | +if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) { |
| 218 | + ArrayBuffer.prototype.slice = function (begin, end) { |
| 219 | + begin = (begin|0) || 0; |
| 220 | + var num = this.byteLength; |
| 221 | + end = end === (void 0) ? num : (end|0); |
| 222 | + |
| 223 | + // Handle negative values. |
| 224 | + if (begin < 0) begin += num; |
| 225 | + if (end < 0) end += num; |
| 226 | + |
| 227 | + if (num === 0 || begin >= num || begin >= end) { |
| 228 | + return new ArrayBuffer(0); |
| 229 | + } |
| 230 | + |
| 231 | + var length = Math.min(num - begin, end - begin); |
| 232 | + var target = new ArrayBuffer(length); |
| 233 | + var targetArray = new Uint8Array(target); |
| 234 | + targetArray.set(new Uint8Array(this, begin, length)); |
| 235 | + return target; |
| 236 | + }; |
| 237 | +} |
| 238 | + |
| 239 | +// https://github.com/davidchambers/Base64.js |
| 240 | +// (C) 2015 David Chambers |
| 241 | +// Base64.js may be freely distributed under the Apache 2.0 License. |
| 242 | +;(function () { |
| 243 | + |
| 244 | + var object = |
| 245 | + typeof exports != 'undefined' ? exports : |
| 246 | + typeof self != 'undefined' ? self : // #8: web workers |
| 247 | + $.global; // #31: ExtendScript |
| 248 | + |
| 249 | + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; |
| 250 | + |
| 251 | + function InvalidCharacterError(message) { |
| 252 | + this.message = message; |
| 253 | + } |
| 254 | + InvalidCharacterError.prototype = new Error; |
| 255 | + InvalidCharacterError.prototype.name = 'InvalidCharacterError'; |
| 256 | + |
| 257 | + // encoder |
| 258 | + // [https://gist.github.com/999166] by [https://github.com/nignag] |
| 259 | + object.btoa || ( |
| 260 | + object.btoa = function (input) { |
| 261 | + var str = String(input); |
| 262 | + for ( |
| 263 | + // initialize result and counter |
| 264 | + var block, charCode, idx = 0, map = chars, output = ''; |
| 265 | + // if the next str index does not exist: |
| 266 | + // change the mapping table to "=" |
| 267 | + // check if d has no fractional digits |
| 268 | + str.charAt(idx | 0) || (map = '=', idx % 1); |
| 269 | + // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 |
| 270 | + output += map.charAt(63 & block >> 8 - idx % 1 * 8) |
| 271 | + ) { |
| 272 | + charCode = str.charCodeAt(idx += 3/4); |
| 273 | + if (charCode > 0xFF) { |
| 274 | + throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); |
| 275 | + } |
| 276 | + block = block << 8 | charCode; |
| 277 | + } |
| 278 | + return output; |
| 279 | + }); |
| 280 | + |
| 281 | + // decoder |
| 282 | + // [https://gist.github.com/1020396] by [https://github.com/atk] |
| 283 | + object.atob || ( |
| 284 | + object.atob = function (input) { |
| 285 | + var str = String(input).replace(/[=]+$/, ''); // #31: ExtendScript bad parse of /= |
| 286 | + if (str.length % 4 == 1) { |
| 287 | + throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); |
| 288 | + } |
| 289 | + for ( |
| 290 | + // initialize result and counters |
| 291 | + var bc = 0, bs, buffer, idx = 0, output = ''; |
| 292 | + // get next character |
| 293 | + buffer = str.charAt(idx++); |
| 294 | + // character found in table? initialize bit storage and add its ascii value; |
| 295 | + ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, |
| 296 | + // and if not first of each 4 characters, |
| 297 | + // convert the first 8 bits to one ascii character |
| 298 | + bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0 |
| 299 | + ) { |
| 300 | + // try to find character in table (0-63, not found => -1) |
| 301 | + buffer = chars.indexOf(buffer); |
| 302 | + } |
| 303 | + return output; |
| 304 | + }); |
| 305 | +}()); |
| 306 | + |
| 307 | + |
| 308 | +// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString |
| 309 | +if (!Date.prototype.toISOString) { |
| 310 | + (function() { |
| 311 | + |
| 312 | + function pad(number) { |
| 313 | + if (number < 10) { |
| 314 | + return '0' + number; |
| 315 | + } |
| 316 | + return number; |
| 317 | + } |
| 318 | + |
| 319 | + Date.prototype.toISOString = function() { |
| 320 | + return this.getUTCFullYear() + |
| 321 | + '-' + pad(this.getUTCMonth() + 1) + |
| 322 | + '-' + pad(this.getUTCDate()) + |
| 323 | + 'T' + pad(this.getUTCHours()) + |
| 324 | + ':' + pad(this.getUTCMinutes()) + |
| 325 | + ':' + pad(this.getUTCSeconds()) + |
| 326 | + '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + |
| 327 | + 'Z'; |
| 328 | + }; |
| 329 | + |
| 330 | + }()); |
| 331 | +} |
| 332 | + |
| 333 | +// note: MDN shim will not work in IE |
| 334 | +if(typeof Uint8Array !== 'undefined' && !Uint8Array.prototype.slice) Uint8Array.prototype.slice = function(start, end) { |
| 335 | + if(start < 0) { start += this.length; if(start < 0) start = 0; } |
| 336 | + if(start >= this.length) return new Uint8Array(0); |
| 337 | + if(end == null) end = this.length; |
| 338 | + if(end < 0) { end += this.length; if(end < 0) end = 0; } |
| 339 | + if(end > this.length) end = this.length; |
| 340 | + var out = new Uint8Array(end - start); |
| 341 | + while(start <= --end) out[end - start] = this[end]; |
| 342 | + return out; |
| 343 | +}; |
0 commit comments