amazeui 2.5.2a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2293 @@
1
+ /*! Amaze UI v2.5.2 ~ IE8 Fucker | by Amaze UI Team | (c) 2016 AllMobilize, Inc. | Licensed under MIT | 2016-01-26T11:06:52+0800 */
2
+ // Console-polyfill. MIT license.
3
+ // https://github.com/paulmillr/console-polyfill
4
+ // Make it safe to do console.log() always.
5
+ (function(global) {
6
+ 'use strict';
7
+ global.console = global.console || {};
8
+ var con = global.console;
9
+ var prop, method;
10
+ var empty = {};
11
+ var dummy = function() {};
12
+ var properties = 'memory'.split(',');
13
+ var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
14
+ 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +
15
+ 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');
16
+ while (prop = properties.pop()) if (!con[prop]) con[prop] = empty;
17
+ while (method = methods.pop()) if (!con[method]) con[method] = dummy;
18
+ })(typeof window === 'undefined' ? this : window);
19
+ // Using `this` for web workers while maintaining compatibility with browser
20
+ // targeted script loaders such as Browserify or Webpack where the only way to
21
+ // get to the global object is via `window`.
22
+
23
+ /*!
24
+ * https://github.com/es-shims/es5-shim
25
+ * @license es5-shim Copyright 2009-2015 by contributors, MIT License
26
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
27
+ */
28
+
29
+ // vim: ts=4 sts=4 sw=4 expandtab
30
+
31
+ // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
32
+ ;
33
+
34
+ // UMD (Universal Module Definition)
35
+ // see https://github.com/umdjs/umd/blob/master/returnExports.js
36
+ (function (root, factory) {
37
+ 'use strict';
38
+
39
+ /* global define, exports, module */
40
+ if (typeof define === 'function' && define.amd) {
41
+ // AMD. Register as an anonymous module.
42
+ define(factory);
43
+ } else if (typeof exports === 'object') {
44
+ // Node. Does not work with strict CommonJS, but
45
+ // only CommonJS-like enviroments that support module.exports,
46
+ // like Node.
47
+ module.exports = factory();
48
+ } else {
49
+ // Browser globals (root is window)
50
+ root.returnExports = factory();
51
+ }
52
+ }(this, function () {
53
+
54
+ var call = Function.prototype.call;
55
+ var prototypeOfObject = Object.prototype;
56
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
57
+
58
+ // If JS engine supports accessors creating shortcuts.
59
+ var defineGetter;
60
+ var defineSetter;
61
+ var lookupGetter;
62
+ var lookupSetter;
63
+ var supportsAccessors = owns(prototypeOfObject, '__defineGetter__');
64
+ if (supportsAccessors) {
65
+ /* eslint-disable no-underscore-dangle */
66
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
67
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
68
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
69
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
70
+ /* eslint-enable no-underscore-dangle */
71
+ }
72
+
73
+ // ES5 15.2.3.2
74
+ // http://es5.github.com/#x15.2.3.2
75
+ if (!Object.getPrototypeOf) {
76
+ // https://github.com/es-shims/es5-shim/issues#issue/2
77
+ // http://ejohn.org/blog/objectgetprototypeof/
78
+ // recommended by fschaefer on github
79
+ //
80
+ // sure, and webreflection says ^_^
81
+ // ... this will nerever possibly return null
82
+ // ... Opera Mini breaks here with infinite loops
83
+ Object.getPrototypeOf = function getPrototypeOf(object) {
84
+ /* eslint-disable no-proto */
85
+ var proto = object.__proto__;
86
+ /* eslint-enable no-proto */
87
+ if (proto || proto === null) {
88
+ return proto;
89
+ } else if (object.constructor) {
90
+ return object.constructor.prototype;
91
+ } else {
92
+ return prototypeOfObject;
93
+ }
94
+ };
95
+ }
96
+
97
+ // ES5 15.2.3.3
98
+ // http://es5.github.com/#x15.2.3.3
99
+
100
+ var doesGetOwnPropertyDescriptorWork = function doesGetOwnPropertyDescriptorWork(object) {
101
+ try {
102
+ object.sentinel = 0;
103
+ return Object.getOwnPropertyDescriptor(object, 'sentinel').value === 0;
104
+ } catch (exception) {
105
+ return false;
106
+ }
107
+ };
108
+
109
+ // check whether getOwnPropertyDescriptor works if it's given. Otherwise, shim partially.
110
+ if (Object.defineProperty) {
111
+ var getOwnPropertyDescriptorWorksOnObject = doesGetOwnPropertyDescriptorWork({});
112
+ var getOwnPropertyDescriptorWorksOnDom = typeof document === 'undefined' ||
113
+ doesGetOwnPropertyDescriptorWork(document.createElement('div'));
114
+ if (!getOwnPropertyDescriptorWorksOnDom || !getOwnPropertyDescriptorWorksOnObject) {
115
+ var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
116
+ }
117
+ }
118
+
119
+ if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
120
+ var ERR_NON_OBJECT = 'Object.getOwnPropertyDescriptor called on a non-object: ';
121
+
122
+ /* eslint-disable no-proto */
123
+ Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
124
+ if ((typeof object !== 'object' && typeof object !== 'function') || object === null) {
125
+ throw new TypeError(ERR_NON_OBJECT + object);
126
+ }
127
+
128
+ // make a valiant attempt to use the real getOwnPropertyDescriptor
129
+ // for I8's DOM elements.
130
+ if (getOwnPropertyDescriptorFallback) {
131
+ try {
132
+ return getOwnPropertyDescriptorFallback.call(Object, object, property);
133
+ } catch (exception) {
134
+ // try the shim if the real one doesn't work
135
+ }
136
+ }
137
+
138
+ var descriptor;
139
+
140
+ // If object does not owns property return undefined immediately.
141
+ if (!owns(object, property)) {
142
+ return descriptor;
143
+ }
144
+
145
+ // If object has a property then it's for sure both `enumerable` and
146
+ // `configurable`.
147
+ descriptor = { enumerable: true, configurable: true };
148
+
149
+ // If JS engine supports accessor properties then property may be a
150
+ // getter or setter.
151
+ if (supportsAccessors) {
152
+ // Unfortunately `__lookupGetter__` will return a getter even
153
+ // if object has own non getter property along with a same named
154
+ // inherited getter. To avoid misbehavior we temporary remove
155
+ // `__proto__` so that `__lookupGetter__` will return getter only
156
+ // if it's owned by an object.
157
+ var prototype = object.__proto__;
158
+ var notPrototypeOfObject = object !== prototypeOfObject;
159
+ // avoid recursion problem, breaking in Opera Mini when
160
+ // Object.getOwnPropertyDescriptor(Object.prototype, 'toString')
161
+ // or any other Object.prototype accessor
162
+ if (notPrototypeOfObject) {
163
+ object.__proto__ = prototypeOfObject;
164
+ }
165
+
166
+ var getter = lookupGetter(object, property);
167
+ var setter = lookupSetter(object, property);
168
+
169
+ if (notPrototypeOfObject) {
170
+ // Once we have getter and setter we can put values back.
171
+ object.__proto__ = prototype;
172
+ }
173
+
174
+ if (getter || setter) {
175
+ if (getter) {
176
+ descriptor.get = getter;
177
+ }
178
+ if (setter) {
179
+ descriptor.set = setter;
180
+ }
181
+ // If it was accessor property we're done and return here
182
+ // in order to avoid adding `value` to the descriptor.
183
+ return descriptor;
184
+ }
185
+ }
186
+
187
+ // If we got this far we know that object has an own property that is
188
+ // not an accessor so we set it as a value and return descriptor.
189
+ descriptor.value = object[property];
190
+ descriptor.writable = true;
191
+ return descriptor;
192
+ };
193
+ /* eslint-enable no-proto */
194
+ }
195
+
196
+ // ES5 15.2.3.4
197
+ // http://es5.github.com/#x15.2.3.4
198
+ if (!Object.getOwnPropertyNames) {
199
+ Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
200
+ return Object.keys(object);
201
+ };
202
+ }
203
+
204
+ // ES5 15.2.3.5
205
+ // http://es5.github.com/#x15.2.3.5
206
+ if (!Object.create) {
207
+
208
+ // Contributed by Brandon Benvie, October, 2012
209
+ var createEmpty;
210
+ var supportsProto = !({ __proto__: null } instanceof Object);
211
+ // the following produces false positives
212
+ // in Opera Mini => not a reliable check
213
+ // Object.prototype.__proto__ === null
214
+
215
+ // Check for document.domain and active x support
216
+ // No need to use active x approach when document.domain is not set
217
+ // see https://github.com/es-shims/es5-shim/issues/150
218
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
219
+ /* global ActiveXObject */
220
+ var shouldUseActiveX = function shouldUseActiveX() {
221
+ // return early if document.domain not set
222
+ if (!document.domain) {
223
+ return false;
224
+ }
225
+
226
+ try {
227
+ return !!new ActiveXObject('htmlfile');
228
+ } catch (exception) {
229
+ return false;
230
+ }
231
+ };
232
+
233
+ // This supports IE8 when document.domain is used
234
+ // see https://github.com/es-shims/es5-shim/issues/150
235
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
236
+ var getEmptyViaActiveX = function getEmptyViaActiveX() {
237
+ var empty;
238
+ var xDoc;
239
+
240
+ xDoc = new ActiveXObject('htmlfile');
241
+
242
+ xDoc.write('<script><\/script>');
243
+ xDoc.close();
244
+
245
+ empty = xDoc.parentWindow.Object.prototype;
246
+ xDoc = null;
247
+
248
+ return empty;
249
+ };
250
+
251
+ // The original implementation using an iframe
252
+ // before the activex approach was added
253
+ // see https://github.com/es-shims/es5-shim/issues/150
254
+ var getEmptyViaIFrame = function getEmptyViaIFrame() {
255
+ var iframe = document.createElement('iframe');
256
+ var parent = document.body || document.documentElement;
257
+ var empty;
258
+
259
+ iframe.style.display = 'none';
260
+ parent.appendChild(iframe);
261
+ /* eslint-disable no-script-url */
262
+ iframe.src = 'javascript:';
263
+ /* eslint-enable no-script-url */
264
+
265
+ empty = iframe.contentWindow.Object.prototype;
266
+ parent.removeChild(iframe);
267
+ iframe = null;
268
+
269
+ return empty;
270
+ };
271
+
272
+ /* global document */
273
+ if (supportsProto || typeof document === 'undefined') {
274
+ createEmpty = function () {
275
+ return { __proto__: null };
276
+ };
277
+ } else {
278
+ // In old IE __proto__ can't be used to manually set `null`, nor does
279
+ // any other method exist to make an object that inherits from nothing,
280
+ // aside from Object.prototype itself. Instead, create a new global
281
+ // object and *steal* its Object.prototype and strip it bare. This is
282
+ // used as the prototype to create nullary objects.
283
+ createEmpty = function () {
284
+ // Determine which approach to use
285
+ // see https://github.com/es-shims/es5-shim/issues/150
286
+ var empty = shouldUseActiveX() ? getEmptyViaActiveX() : getEmptyViaIFrame();
287
+
288
+ delete empty.constructor;
289
+ delete empty.hasOwnProperty;
290
+ delete empty.propertyIsEnumerable;
291
+ delete empty.isPrototypeOf;
292
+ delete empty.toLocaleString;
293
+ delete empty.toString;
294
+ delete empty.valueOf;
295
+ /* eslint-disable no-proto */
296
+ empty.__proto__ = null;
297
+ /* eslint-enable no-proto */
298
+
299
+ var Empty = function Empty() {};
300
+ Empty.prototype = empty;
301
+ // short-circuit future calls
302
+ createEmpty = function () {
303
+ return new Empty();
304
+ };
305
+ return new Empty();
306
+ };
307
+ }
308
+
309
+ Object.create = function create(prototype, properties) {
310
+
311
+ var object;
312
+ var Type = function Type() {}; // An empty constructor.
313
+
314
+ if (prototype === null) {
315
+ object = createEmpty();
316
+ } else {
317
+ if (typeof prototype !== 'object' && typeof prototype !== 'function') {
318
+ // In the native implementation `parent` can be `null`
319
+ // OR *any* `instanceof Object` (Object|Function|Array|RegExp|etc)
320
+ // Use `typeof` tho, b/c in old IE, DOM elements are not `instanceof Object`
321
+ // like they are in modern browsers. Using `Object.create` on DOM elements
322
+ // is...err...probably inappropriate, but the native version allows for it.
323
+ throw new TypeError('Object prototype may only be an Object or null'); // same msg as Chrome
324
+ }
325
+ Type.prototype = prototype;
326
+ object = new Type();
327
+ // IE has no built-in implementation of `Object.getPrototypeOf`
328
+ // neither `__proto__`, but this manually setting `__proto__` will
329
+ // guarantee that `Object.getPrototypeOf` will work as expected with
330
+ // objects created using `Object.create`
331
+ /* eslint-disable no-proto */
332
+ object.__proto__ = prototype;
333
+ /* eslint-enable no-proto */
334
+ }
335
+
336
+ if (properties !== void 0) {
337
+ Object.defineProperties(object, properties);
338
+ }
339
+
340
+ return object;
341
+ };
342
+ }
343
+
344
+ // ES5 15.2.3.6
345
+ // http://es5.github.com/#x15.2.3.6
346
+
347
+ // Patch for WebKit and IE8 standard mode
348
+ // Designed by hax <hax.github.com>
349
+ // related issue: https://github.com/es-shims/es5-shim/issues#issue/5
350
+ // IE8 Reference:
351
+ // http://msdn.microsoft.com/en-us/library/dd282900.aspx
352
+ // http://msdn.microsoft.com/en-us/library/dd229916.aspx
353
+ // WebKit Bugs:
354
+ // https://bugs.webkit.org/show_bug.cgi?id=36423
355
+
356
+ var doesDefinePropertyWork = function doesDefinePropertyWork(object) {
357
+ try {
358
+ Object.defineProperty(object, 'sentinel', {});
359
+ return 'sentinel' in object;
360
+ } catch (exception) {
361
+ return false;
362
+ }
363
+ };
364
+
365
+ // check whether defineProperty works if it's given. Otherwise,
366
+ // shim partially.
367
+ if (Object.defineProperty) {
368
+ var definePropertyWorksOnObject = doesDefinePropertyWork({});
369
+ var definePropertyWorksOnDom = typeof document === 'undefined' ||
370
+ doesDefinePropertyWork(document.createElement('div'));
371
+ if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
372
+ var definePropertyFallback = Object.defineProperty,
373
+ definePropertiesFallback = Object.defineProperties;
374
+ }
375
+ }
376
+
377
+ if (!Object.defineProperty || definePropertyFallback) {
378
+ var ERR_NON_OBJECT_DESCRIPTOR = 'Property description must be an object: ';
379
+ var ERR_NON_OBJECT_TARGET = 'Object.defineProperty called on non-object: ';
380
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'getters & setters can not be defined on this javascript engine';
381
+
382
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
383
+ if ((typeof object !== 'object' && typeof object !== 'function') || object === null) {
384
+ throw new TypeError(ERR_NON_OBJECT_TARGET + object);
385
+ }
386
+ if ((typeof descriptor !== 'object' && typeof descriptor !== 'function') || descriptor === null) {
387
+ throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
388
+ }
389
+ // make a valiant attempt to use the real defineProperty
390
+ // for I8's DOM elements.
391
+ if (definePropertyFallback) {
392
+ try {
393
+ return definePropertyFallback.call(Object, object, property, descriptor);
394
+ } catch (exception) {
395
+ // try the shim if the real one doesn't work
396
+ }
397
+ }
398
+
399
+ // If it's a data property.
400
+ if ('value' in descriptor) {
401
+ // fail silently if 'writable', 'enumerable', or 'configurable'
402
+ // are requested but not supported
403
+ /*
404
+ // alternate approach:
405
+ if ( // can't implement these features; allow false but not true
406
+ ('writable' in descriptor && !descriptor.writable) ||
407
+ ('enumerable' in descriptor && !descriptor.enumerable) ||
408
+ ('configurable' in descriptor && !descriptor.configurable)
409
+ ))
410
+ throw new RangeError(
411
+ 'This implementation of Object.defineProperty does not support configurable, enumerable, or writable.'
412
+ );
413
+ */
414
+
415
+ if (supportsAccessors && (lookupGetter(object, property) || lookupSetter(object, property))) {
416
+ // As accessors are supported only on engines implementing
417
+ // `__proto__` we can safely override `__proto__` while defining
418
+ // a property to make sure that we don't hit an inherited
419
+ // accessor.
420
+ /* eslint-disable no-proto */
421
+ var prototype = object.__proto__;
422
+ object.__proto__ = prototypeOfObject;
423
+ // Deleting a property anyway since getter / setter may be
424
+ // defined on object itself.
425
+ delete object[property];
426
+ object[property] = descriptor.value;
427
+ // Setting original `__proto__` back now.
428
+ object.__proto__ = prototype;
429
+ /* eslint-enable no-proto */
430
+ } else {
431
+ object[property] = descriptor.value;
432
+ }
433
+ } else {
434
+ if (!supportsAccessors) {
435
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
436
+ }
437
+ // If we got that far then getters and setters can be defined !!
438
+ if ('get' in descriptor) {
439
+ defineGetter(object, property, descriptor.get);
440
+ }
441
+ if ('set' in descriptor) {
442
+ defineSetter(object, property, descriptor.set);
443
+ }
444
+ }
445
+ return object;
446
+ };
447
+ }
448
+
449
+ // ES5 15.2.3.7
450
+ // http://es5.github.com/#x15.2.3.7
451
+ if (!Object.defineProperties || definePropertiesFallback) {
452
+ Object.defineProperties = function defineProperties(object, properties) {
453
+ // make a valiant attempt to use the real defineProperties
454
+ if (definePropertiesFallback) {
455
+ try {
456
+ return definePropertiesFallback.call(Object, object, properties);
457
+ } catch (exception) {
458
+ // try the shim if the real one doesn't work
459
+ }
460
+ }
461
+
462
+ Object.keys(properties).forEach(function (property) {
463
+ if (property !== '__proto__') {
464
+ Object.defineProperty(object, property, properties[property]);
465
+ }
466
+ });
467
+ return object;
468
+ };
469
+ }
470
+
471
+ // ES5 15.2.3.8
472
+ // http://es5.github.com/#x15.2.3.8
473
+ if (!Object.seal) {
474
+ Object.seal = function seal(object) {
475
+ if (Object(object) !== object) {
476
+ throw new TypeError('Object.seal can only be called on Objects.');
477
+ }
478
+ // this is misleading and breaks feature-detection, but
479
+ // allows "securable" code to "gracefully" degrade to working
480
+ // but insecure code.
481
+ return object;
482
+ };
483
+ }
484
+
485
+ // ES5 15.2.3.9
486
+ // http://es5.github.com/#x15.2.3.9
487
+ if (!Object.freeze) {
488
+ Object.freeze = function freeze(object) {
489
+ if (Object(object) !== object) {
490
+ throw new TypeError('Object.freeze can only be called on Objects.');
491
+ }
492
+ // this is misleading and breaks feature-detection, but
493
+ // allows "securable" code to "gracefully" degrade to working
494
+ // but insecure code.
495
+ return object;
496
+ };
497
+ }
498
+
499
+ // detect a Rhino bug and patch it
500
+ try {
501
+ Object.freeze(function () {});
502
+ } catch (exception) {
503
+ Object.freeze = (function (freezeObject) {
504
+ return function freeze(object) {
505
+ if (typeof object === 'function') {
506
+ return object;
507
+ } else {
508
+ return freezeObject(object);
509
+ }
510
+ };
511
+ }(Object.freeze));
512
+ }
513
+
514
+ // ES5 15.2.3.10
515
+ // http://es5.github.com/#x15.2.3.10
516
+ if (!Object.preventExtensions) {
517
+ Object.preventExtensions = function preventExtensions(object) {
518
+ if (Object(object) !== object) {
519
+ throw new TypeError('Object.preventExtensions can only be called on Objects.');
520
+ }
521
+ // this is misleading and breaks feature-detection, but
522
+ // allows "securable" code to "gracefully" degrade to working
523
+ // but insecure code.
524
+ return object;
525
+ };
526
+ }
527
+
528
+ // ES5 15.2.3.11
529
+ // http://es5.github.com/#x15.2.3.11
530
+ if (!Object.isSealed) {
531
+ Object.isSealed = function isSealed(object) {
532
+ if (Object(object) !== object) {
533
+ throw new TypeError('Object.isSealed can only be called on Objects.');
534
+ }
535
+ return false;
536
+ };
537
+ }
538
+
539
+ // ES5 15.2.3.12
540
+ // http://es5.github.com/#x15.2.3.12
541
+ if (!Object.isFrozen) {
542
+ Object.isFrozen = function isFrozen(object) {
543
+ if (Object(object) !== object) {
544
+ throw new TypeError('Object.isFrozen can only be called on Objects.');
545
+ }
546
+ return false;
547
+ };
548
+ }
549
+
550
+ // ES5 15.2.3.13
551
+ // http://es5.github.com/#x15.2.3.13
552
+ if (!Object.isExtensible) {
553
+ Object.isExtensible = function isExtensible(object) {
554
+ // 1. If Type(O) is not Object throw a TypeError exception.
555
+ if (Object(object) !== object) {
556
+ throw new TypeError('Object.isExtensible can only be called on Objects.');
557
+ }
558
+ // 2. Return the Boolean value of the [[Extensible]] internal property of O.
559
+ var name = '';
560
+ while (owns(object, name)) {
561
+ name += '?';
562
+ }
563
+ object[name] = true;
564
+ var returnValue = owns(object, name);
565
+ delete object[name];
566
+ return returnValue;
567
+ };
568
+ }
569
+
570
+ }));
571
+
572
+ /*!
573
+ * https://github.com/es-shims/es5-shim
574
+ * @license es5-shim Copyright 2009-2015 by contributors, MIT License
575
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
576
+ */
577
+
578
+ // vim: ts=4 sts=4 sw=4 expandtab
579
+
580
+ // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
581
+ ;
582
+
583
+ // UMD (Universal Module Definition)
584
+ // see https://github.com/umdjs/umd/blob/master/returnExports.js
585
+ (function (root, factory) {
586
+ 'use strict';
587
+
588
+ /* global define, exports, module */
589
+ if (typeof define === 'function' && define.amd) {
590
+ // AMD. Register as an anonymous module.
591
+ define(factory);
592
+ } else if (typeof exports === 'object') {
593
+ // Node. Does not work with strict CommonJS, but
594
+ // only CommonJS-like enviroments that support module.exports,
595
+ // like Node.
596
+ module.exports = factory();
597
+ } else {
598
+ // Browser globals (root is window)
599
+ root.returnExports = factory();
600
+ }
601
+ }(this, function () {
602
+
603
+ /**
604
+ * Brings an environment as close to ECMAScript 5 compliance
605
+ * as is possible with the facilities of erstwhile engines.
606
+ *
607
+ * Annotated ES5: http://es5.github.com/ (specific links below)
608
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
609
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
610
+ */
611
+
612
+ // Shortcut to an often accessed properties, in order to avoid multiple
613
+ // dereference that costs universally.
614
+ var ArrayPrototype = Array.prototype;
615
+ var ObjectPrototype = Object.prototype;
616
+ var FunctionPrototype = Function.prototype;
617
+ var StringPrototype = String.prototype;
618
+ var NumberPrototype = Number.prototype;
619
+ var array_slice = ArrayPrototype.slice;
620
+ var array_splice = ArrayPrototype.splice;
621
+ var array_push = ArrayPrototype.push;
622
+ var array_unshift = ArrayPrototype.unshift;
623
+ var array_concat = ArrayPrototype.concat;
624
+ var call = FunctionPrototype.call;
625
+
626
+ // Having a toString local variable name breaks in Opera so use to_string.
627
+ var to_string = ObjectPrototype.toString;
628
+
629
+ var isArray = Array.isArray || function isArray(obj) {
630
+ return to_string.call(obj) === '[object Array]';
631
+ };
632
+
633
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
634
+ var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
635
+ var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
636
+ var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };
637
+
638
+ var isArguments = function isArguments(value) {
639
+ var str = to_string.call(value);
640
+ var isArgs = str === '[object Arguments]';
641
+ if (!isArgs) {
642
+ isArgs = !isArray(value) &&
643
+ value !== null &&
644
+ typeof value === 'object' &&
645
+ typeof value.length === 'number' &&
646
+ value.length >= 0 &&
647
+ isCallable(value.callee);
648
+ }
649
+ return isArgs;
650
+ };
651
+
652
+ /* inlined from http://npmjs.com/define-properties */
653
+ var defineProperties = (function (has) {
654
+ var supportsDescriptors = Object.defineProperty && (function () {
655
+ try {
656
+ var obj = {};
657
+ Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
658
+ for (var _ in obj) { return false; }
659
+ return obj.x === obj;
660
+ } catch (e) { /* this is ES3 */
661
+ return false;
662
+ }
663
+ }());
664
+
665
+ // Define configurable, writable and non-enumerable props
666
+ // if they don't exist.
667
+ var defineProperty;
668
+ if (supportsDescriptors) {
669
+ defineProperty = function (object, name, method, forceAssign) {
670
+ if (!forceAssign && (name in object)) { return; }
671
+ Object.defineProperty(object, name, {
672
+ configurable: true,
673
+ enumerable: false,
674
+ writable: true,
675
+ value: method
676
+ });
677
+ };
678
+ } else {
679
+ defineProperty = function (object, name, method, forceAssign) {
680
+ if (!forceAssign && (name in object)) { return; }
681
+ object[name] = method;
682
+ };
683
+ }
684
+ return function defineProperties(object, map, forceAssign) {
685
+ for (var name in map) {
686
+ if (has.call(map, name)) {
687
+ defineProperty(object, name, map[name], forceAssign);
688
+ }
689
+ }
690
+ };
691
+ }(ObjectPrototype.hasOwnProperty));
692
+
693
+ //
694
+ // Util
695
+ // ======
696
+ //
697
+
698
+ /* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
699
+ var isPrimitive = function isPrimitive(input) {
700
+ var type = typeof input;
701
+ return input === null || (type !== 'object' && type !== 'function');
702
+ };
703
+
704
+ var ES = {
705
+ // ES5 9.4
706
+ // http://es5.github.com/#x9.4
707
+ // http://jsperf.com/to-integer
708
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
709
+ ToInteger: function ToInteger(num) {
710
+ var n = +num;
711
+ if (n !== n) { // isNaN
712
+ n = 0;
713
+ } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
714
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
715
+ }
716
+ return n;
717
+ },
718
+
719
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
720
+ ToPrimitive: function ToPrimitive(input) {
721
+ var val, valueOf, toStr;
722
+ if (isPrimitive(input)) {
723
+ return input;
724
+ }
725
+ valueOf = input.valueOf;
726
+ if (isCallable(valueOf)) {
727
+ val = valueOf.call(input);
728
+ if (isPrimitive(val)) {
729
+ return val;
730
+ }
731
+ }
732
+ toStr = input.toString;
733
+ if (isCallable(toStr)) {
734
+ val = toStr.call(input);
735
+ if (isPrimitive(val)) {
736
+ return val;
737
+ }
738
+ }
739
+ throw new TypeError();
740
+ },
741
+
742
+ // ES5 9.9
743
+ // http://es5.github.com/#x9.9
744
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
745
+ ToObject: function (o) {
746
+ /* jshint eqnull: true */
747
+ if (o == null) { // this matches both null and undefined
748
+ throw new TypeError("can't convert " + o + ' to object');
749
+ }
750
+ return Object(o);
751
+ },
752
+
753
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
754
+ ToUint32: function ToUint32(x) {
755
+ return x >>> 0;
756
+ }
757
+ };
758
+
759
+ //
760
+ // Function
761
+ // ========
762
+ //
763
+
764
+ // ES-5 15.3.4.5
765
+ // http://es5.github.com/#x15.3.4.5
766
+
767
+ var Empty = function Empty() {};
768
+
769
+ defineProperties(FunctionPrototype, {
770
+ bind: function bind(that) { // .length is 1
771
+ // 1. Let Target be the this value.
772
+ var target = this;
773
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
774
+ if (!isCallable(target)) {
775
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
776
+ }
777
+ // 3. Let A be a new (possibly empty) internal list of all of the
778
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
779
+ // XXX slicedArgs will stand in for "A" if used
780
+ var args = array_slice.call(arguments, 1); // for normal call
781
+ // 4. Let F be a new native ECMAScript object.
782
+ // 11. Set the [[Prototype]] internal property of F to the standard
783
+ // built-in Function prototype object as specified in 15.3.3.1.
784
+ // 12. Set the [[Call]] internal property of F as described in
785
+ // 15.3.4.5.1.
786
+ // 13. Set the [[Construct]] internal property of F as described in
787
+ // 15.3.4.5.2.
788
+ // 14. Set the [[HasInstance]] internal property of F as described in
789
+ // 15.3.4.5.3.
790
+ var bound;
791
+ var binder = function () {
792
+
793
+ if (this instanceof bound) {
794
+ // 15.3.4.5.2 [[Construct]]
795
+ // When the [[Construct]] internal method of a function object,
796
+ // F that was created using the bind function is called with a
797
+ // list of arguments ExtraArgs, the following steps are taken:
798
+ // 1. Let target be the value of F's [[TargetFunction]]
799
+ // internal property.
800
+ // 2. If target has no [[Construct]] internal method, a
801
+ // TypeError exception is thrown.
802
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
803
+ // property.
804
+ // 4. Let args be a new list containing the same values as the
805
+ // list boundArgs in the same order followed by the same
806
+ // values as the list ExtraArgs in the same order.
807
+ // 5. Return the result of calling the [[Construct]] internal
808
+ // method of target providing args as the arguments.
809
+
810
+ var result = target.apply(
811
+ this,
812
+ array_concat.call(args, array_slice.call(arguments))
813
+ );
814
+ if (Object(result) === result) {
815
+ return result;
816
+ }
817
+ return this;
818
+
819
+ } else {
820
+ // 15.3.4.5.1 [[Call]]
821
+ // When the [[Call]] internal method of a function object, F,
822
+ // which was created using the bind function is called with a
823
+ // this value and a list of arguments ExtraArgs, the following
824
+ // steps are taken:
825
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
826
+ // property.
827
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
828
+ // property.
829
+ // 3. Let target be the value of F's [[TargetFunction]] internal
830
+ // property.
831
+ // 4. Let args be a new list containing the same values as the
832
+ // list boundArgs in the same order followed by the same
833
+ // values as the list ExtraArgs in the same order.
834
+ // 5. Return the result of calling the [[Call]] internal method
835
+ // of target providing boundThis as the this value and
836
+ // providing args as the arguments.
837
+
838
+ // equiv: target.call(this, ...boundArgs, ...args)
839
+ return target.apply(
840
+ that,
841
+ array_concat.call(args, array_slice.call(arguments))
842
+ );
843
+
844
+ }
845
+
846
+ };
847
+
848
+ // 15. If the [[Class]] internal property of Target is "Function", then
849
+ // a. Let L be the length property of Target minus the length of A.
850
+ // b. Set the length own property of F to either 0 or L, whichever is
851
+ // larger.
852
+ // 16. Else set the length own property of F to 0.
853
+
854
+ var boundLength = Math.max(0, target.length - args.length);
855
+
856
+ // 17. Set the attributes of the length own property of F to the values
857
+ // specified in 15.3.5.1.
858
+ var boundArgs = [];
859
+ for (var i = 0; i < boundLength; i++) {
860
+ boundArgs.push('$' + i);
861
+ }
862
+
863
+ // XXX Build a dynamic function with desired amount of arguments is the only
864
+ // way to set the length property of a function.
865
+ // In environments where Content Security Policies enabled (Chrome extensions,
866
+ // for ex.) all use of eval or Function costructor throws an exception.
867
+ // However in all of these environments Function.prototype.bind exists
868
+ // and so this code will never be executed.
869
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
870
+
871
+ if (target.prototype) {
872
+ Empty.prototype = target.prototype;
873
+ bound.prototype = new Empty();
874
+ // Clean up dangling references.
875
+ Empty.prototype = null;
876
+ }
877
+
878
+ // TODO
879
+ // 18. Set the [[Extensible]] internal property of F to true.
880
+
881
+ // TODO
882
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
883
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
884
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
885
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
886
+ // false.
887
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
888
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
889
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
890
+ // and false.
891
+
892
+ // TODO
893
+ // NOTE Function objects created using Function.prototype.bind do not
894
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
895
+ // [[Scope]] internal properties.
896
+ // XXX can't delete prototype in pure-js.
897
+
898
+ // 22. Return F.
899
+ return bound;
900
+ }
901
+ });
902
+
903
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
904
+ // us it in defining shortcuts.
905
+ var owns = call.bind(ObjectPrototype.hasOwnProperty);
906
+
907
+ //
908
+ // Array
909
+ // =====
910
+ //
911
+
912
+ // ES5 15.4.4.12
913
+ // http://es5.github.com/#x15.4.4.12
914
+ var spliceNoopReturnsEmptyArray = (function () {
915
+ var a = [1, 2];
916
+ var result = a.splice();
917
+ return a.length === 2 && isArray(result) && result.length === 0;
918
+ }());
919
+ defineProperties(ArrayPrototype, {
920
+ // Safari 5.0 bug where .splice() returns undefined
921
+ splice: function splice(start, deleteCount) {
922
+ if (arguments.length === 0) {
923
+ return [];
924
+ } else {
925
+ return array_splice.apply(this, arguments);
926
+ }
927
+ }
928
+ }, !spliceNoopReturnsEmptyArray);
929
+
930
+ var spliceWorksWithEmptyObject = (function () {
931
+ var obj = {};
932
+ ArrayPrototype.splice.call(obj, 0, 0, 1);
933
+ return obj.length === 1;
934
+ }());
935
+ defineProperties(ArrayPrototype, {
936
+ splice: function splice(start, deleteCount) {
937
+ if (arguments.length === 0) { return []; }
938
+ var args = arguments;
939
+ this.length = Math.max(ES.ToInteger(this.length), 0);
940
+ if (arguments.length > 0 && typeof deleteCount !== 'number') {
941
+ args = array_slice.call(arguments);
942
+ if (args.length < 2) {
943
+ args.push(this.length - start);
944
+ } else {
945
+ args[1] = ES.ToInteger(deleteCount);
946
+ }
947
+ }
948
+ return array_splice.apply(this, args);
949
+ }
950
+ }, !spliceWorksWithEmptyObject);
951
+
952
+ // ES5 15.4.4.12
953
+ // http://es5.github.com/#x15.4.4.13
954
+ // Return len+argCount.
955
+ // [bugfix, ielt8]
956
+ // IE < 8 bug: [].unshift(0) === undefined but should be "1"
957
+ var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
958
+ defineProperties(ArrayPrototype, {
959
+ unshift: function () {
960
+ array_unshift.apply(this, arguments);
961
+ return this.length;
962
+ }
963
+ }, hasUnshiftReturnValueBug);
964
+
965
+ // ES5 15.4.3.2
966
+ // http://es5.github.com/#x15.4.3.2
967
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
968
+ defineProperties(Array, { isArray: isArray });
969
+
970
+ // The IsCallable() check in the Array functions
971
+ // has been replaced with a strict check on the
972
+ // internal class of the object to trap cases where
973
+ // the provided function was actually a regular
974
+ // expression literal, which in V8 and
975
+ // JavaScriptCore is a typeof "function". Only in
976
+ // V8 are regular expression literals permitted as
977
+ // reduce parameters, so it is desirable in the
978
+ // general case for the shim to match the more
979
+ // strict and common behavior of rejecting regular
980
+ // expressions.
981
+
982
+ // ES5 15.4.4.18
983
+ // http://es5.github.com/#x15.4.4.18
984
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
985
+
986
+ // Check failure of by-index access of string characters (IE < 9)
987
+ // and failure of `0 in boxedString` (Rhino)
988
+ var boxedString = Object('a');
989
+ var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
990
+
991
+ var properlyBoxesContext = function properlyBoxed(method) {
992
+ // Check node 0.6.21 bug where third parameter is not boxed
993
+ var properlyBoxesNonStrict = true;
994
+ var properlyBoxesStrict = true;
995
+ if (method) {
996
+ method.call('foo', function (_, __, context) {
997
+ if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
998
+ });
999
+
1000
+ method.call([1], function () {
1001
+ 'use strict';
1002
+
1003
+ properlyBoxesStrict = typeof this === 'string';
1004
+ }, 'x');
1005
+ }
1006
+ return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
1007
+ };
1008
+
1009
+ defineProperties(ArrayPrototype, {
1010
+ forEach: function forEach(callbackfn /*, thisArg*/) {
1011
+ var object = ES.ToObject(this);
1012
+ var self = splitString && isString(this) ? this.split('') : object;
1013
+ var i = -1;
1014
+ var length = self.length >>> 0;
1015
+ var T;
1016
+ if (arguments.length > 1) {
1017
+ T = arguments[1];
1018
+ }
1019
+
1020
+ // If no callback function or if callback is not a callable function
1021
+ if (!isCallable(callbackfn)) {
1022
+ throw new TypeError('Array.prototype.forEach callback must be a function');
1023
+ }
1024
+
1025
+ while (++i < length) {
1026
+ if (i in self) {
1027
+ // Invoke the callback function with call, passing arguments:
1028
+ // context, property value, property key, thisArg object
1029
+ if (typeof T !== 'undefined') {
1030
+ callbackfn.call(T, self[i], i, object);
1031
+ } else {
1032
+ callbackfn(self[i], i, object);
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ }, !properlyBoxesContext(ArrayPrototype.forEach));
1038
+
1039
+ // ES5 15.4.4.19
1040
+ // http://es5.github.com/#x15.4.4.19
1041
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
1042
+ defineProperties(ArrayPrototype, {
1043
+ map: function map(callbackfn/*, thisArg*/) {
1044
+ var object = ES.ToObject(this);
1045
+ var self = splitString && isString(this) ? this.split('') : object;
1046
+ var length = self.length >>> 0;
1047
+ var result = Array(length);
1048
+ var T;
1049
+ if (arguments.length > 1) {
1050
+ T = arguments[1];
1051
+ }
1052
+
1053
+ // If no callback function or if callback is not a callable function
1054
+ if (!isCallable(callbackfn)) {
1055
+ throw new TypeError('Array.prototype.map callback must be a function');
1056
+ }
1057
+
1058
+ for (var i = 0; i < length; i++) {
1059
+ if (i in self) {
1060
+ if (typeof T !== 'undefined') {
1061
+ result[i] = callbackfn.call(T, self[i], i, object);
1062
+ } else {
1063
+ result[i] = callbackfn(self[i], i, object);
1064
+ }
1065
+ }
1066
+ }
1067
+ return result;
1068
+ }
1069
+ }, !properlyBoxesContext(ArrayPrototype.map));
1070
+
1071
+ // ES5 15.4.4.20
1072
+ // http://es5.github.com/#x15.4.4.20
1073
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
1074
+ defineProperties(ArrayPrototype, {
1075
+ filter: function filter(callbackfn /*, thisArg*/) {
1076
+ var object = ES.ToObject(this);
1077
+ var self = splitString && isString(this) ? this.split('') : object;
1078
+ var length = self.length >>> 0;
1079
+ var result = [];
1080
+ var value;
1081
+ var T;
1082
+ if (arguments.length > 1) {
1083
+ T = arguments[1];
1084
+ }
1085
+
1086
+ // If no callback function or if callback is not a callable function
1087
+ if (!isCallable(callbackfn)) {
1088
+ throw new TypeError('Array.prototype.filter callback must be a function');
1089
+ }
1090
+
1091
+ for (var i = 0; i < length; i++) {
1092
+ if (i in self) {
1093
+ value = self[i];
1094
+ if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
1095
+ result.push(value);
1096
+ }
1097
+ }
1098
+ }
1099
+ return result;
1100
+ }
1101
+ }, !properlyBoxesContext(ArrayPrototype.filter));
1102
+
1103
+ // ES5 15.4.4.16
1104
+ // http://es5.github.com/#x15.4.4.16
1105
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
1106
+ defineProperties(ArrayPrototype, {
1107
+ every: function every(callbackfn /*, thisArg*/) {
1108
+ var object = ES.ToObject(this);
1109
+ var self = splitString && isString(this) ? this.split('') : object;
1110
+ var length = self.length >>> 0;
1111
+ var T;
1112
+ if (arguments.length > 1) {
1113
+ T = arguments[1];
1114
+ }
1115
+
1116
+ // If no callback function or if callback is not a callable function
1117
+ if (!isCallable(callbackfn)) {
1118
+ throw new TypeError('Array.prototype.every callback must be a function');
1119
+ }
1120
+
1121
+ for (var i = 0; i < length; i++) {
1122
+ if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
1123
+ return false;
1124
+ }
1125
+ }
1126
+ return true;
1127
+ }
1128
+ }, !properlyBoxesContext(ArrayPrototype.every));
1129
+
1130
+ // ES5 15.4.4.17
1131
+ // http://es5.github.com/#x15.4.4.17
1132
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
1133
+ defineProperties(ArrayPrototype, {
1134
+ some: function some(callbackfn/*, thisArg */) {
1135
+ var object = ES.ToObject(this);
1136
+ var self = splitString && isString(this) ? this.split('') : object;
1137
+ var length = self.length >>> 0;
1138
+ var T;
1139
+ if (arguments.length > 1) {
1140
+ T = arguments[1];
1141
+ }
1142
+
1143
+ // If no callback function or if callback is not a callable function
1144
+ if (!isCallable(callbackfn)) {
1145
+ throw new TypeError('Array.prototype.some callback must be a function');
1146
+ }
1147
+
1148
+ for (var i = 0; i < length; i++) {
1149
+ if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
1150
+ return true;
1151
+ }
1152
+ }
1153
+ return false;
1154
+ }
1155
+ }, !properlyBoxesContext(ArrayPrototype.some));
1156
+
1157
+ // ES5 15.4.4.21
1158
+ // http://es5.github.com/#x15.4.4.21
1159
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
1160
+ var reduceCoercesToObject = false;
1161
+ if (ArrayPrototype.reduce) {
1162
+ reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object';
1163
+ }
1164
+ defineProperties(ArrayPrototype, {
1165
+ reduce: function reduce(callbackfn /*, initialValue*/) {
1166
+ var object = ES.ToObject(this);
1167
+ var self = splitString && isString(this) ? this.split('') : object;
1168
+ var length = self.length >>> 0;
1169
+
1170
+ // If no callback function or if callback is not a callable function
1171
+ if (!isCallable(callbackfn)) {
1172
+ throw new TypeError('Array.prototype.reduce callback must be a function');
1173
+ }
1174
+
1175
+ // no value to return if no initial value and an empty array
1176
+ if (length === 0 && arguments.length === 1) {
1177
+ throw new TypeError('reduce of empty array with no initial value');
1178
+ }
1179
+
1180
+ var i = 0;
1181
+ var result;
1182
+ if (arguments.length >= 2) {
1183
+ result = arguments[1];
1184
+ } else {
1185
+ do {
1186
+ if (i in self) {
1187
+ result = self[i++];
1188
+ break;
1189
+ }
1190
+
1191
+ // if array contains no values, no initial value to return
1192
+ if (++i >= length) {
1193
+ throw new TypeError('reduce of empty array with no initial value');
1194
+ }
1195
+ } while (true);
1196
+ }
1197
+
1198
+ for (; i < length; i++) {
1199
+ if (i in self) {
1200
+ result = callbackfn(result, self[i], i, object);
1201
+ }
1202
+ }
1203
+
1204
+ return result;
1205
+ }
1206
+ }, !reduceCoercesToObject);
1207
+
1208
+ // ES5 15.4.4.22
1209
+ // http://es5.github.com/#x15.4.4.22
1210
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
1211
+ var reduceRightCoercesToObject = false;
1212
+ if (ArrayPrototype.reduceRight) {
1213
+ reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object';
1214
+ }
1215
+ defineProperties(ArrayPrototype, {
1216
+ reduceRight: function reduceRight(callbackfn/*, initial*/) {
1217
+ var object = ES.ToObject(this);
1218
+ var self = splitString && isString(this) ? this.split('') : object;
1219
+ var length = self.length >>> 0;
1220
+
1221
+ // If no callback function or if callback is not a callable function
1222
+ if (!isCallable(callbackfn)) {
1223
+ throw new TypeError('Array.prototype.reduceRight callback must be a function');
1224
+ }
1225
+
1226
+ // no value to return if no initial value, empty array
1227
+ if (length === 0 && arguments.length === 1) {
1228
+ throw new TypeError('reduceRight of empty array with no initial value');
1229
+ }
1230
+
1231
+ var result;
1232
+ var i = length - 1;
1233
+ if (arguments.length >= 2) {
1234
+ result = arguments[1];
1235
+ } else {
1236
+ do {
1237
+ if (i in self) {
1238
+ result = self[i--];
1239
+ break;
1240
+ }
1241
+
1242
+ // if array contains no values, no initial value to return
1243
+ if (--i < 0) {
1244
+ throw new TypeError('reduceRight of empty array with no initial value');
1245
+ }
1246
+ } while (true);
1247
+ }
1248
+
1249
+ if (i < 0) {
1250
+ return result;
1251
+ }
1252
+
1253
+ do {
1254
+ if (i in self) {
1255
+ result = callbackfn(result, self[i], i, object);
1256
+ }
1257
+ } while (i--);
1258
+
1259
+ return result;
1260
+ }
1261
+ }, !reduceRightCoercesToObject);
1262
+
1263
+ // ES5 15.4.4.14
1264
+ // http://es5.github.com/#x15.4.4.14
1265
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
1266
+ var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
1267
+ defineProperties(ArrayPrototype, {
1268
+ indexOf: function indexOf(searchElement /*, fromIndex */) {
1269
+ var self = splitString && isString(this) ? this.split('') : ES.ToObject(this);
1270
+ var length = self.length >>> 0;
1271
+
1272
+ if (length === 0) {
1273
+ return -1;
1274
+ }
1275
+
1276
+ var i = 0;
1277
+ if (arguments.length > 1) {
1278
+ i = ES.ToInteger(arguments[1]);
1279
+ }
1280
+
1281
+ // handle negative indices
1282
+ i = i >= 0 ? i : Math.max(0, length + i);
1283
+ for (; i < length; i++) {
1284
+ if (i in self && self[i] === searchElement) {
1285
+ return i;
1286
+ }
1287
+ }
1288
+ return -1;
1289
+ }
1290
+ }, hasFirefox2IndexOfBug);
1291
+
1292
+ // ES5 15.4.4.15
1293
+ // http://es5.github.com/#x15.4.4.15
1294
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
1295
+ var hasFirefox2LastIndexOfBug = Array.prototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
1296
+ defineProperties(ArrayPrototype, {
1297
+ lastIndexOf: function lastIndexOf(searchElement /*, fromIndex */) {
1298
+ var self = splitString && isString(this) ? this.split('') : ES.ToObject(this);
1299
+ var length = self.length >>> 0;
1300
+
1301
+ if (length === 0) {
1302
+ return -1;
1303
+ }
1304
+ var i = length - 1;
1305
+ if (arguments.length > 1) {
1306
+ i = Math.min(i, ES.ToInteger(arguments[1]));
1307
+ }
1308
+ // handle negative indices
1309
+ i = i >= 0 ? i : length - Math.abs(i);
1310
+ for (; i >= 0; i--) {
1311
+ if (i in self && searchElement === self[i]) {
1312
+ return i;
1313
+ }
1314
+ }
1315
+ return -1;
1316
+ }
1317
+ }, hasFirefox2LastIndexOfBug);
1318
+
1319
+ //
1320
+ // Object
1321
+ // ======
1322
+ //
1323
+
1324
+ // ES5 15.2.3.14
1325
+ // http://es5.github.com/#x15.2.3.14
1326
+
1327
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
1328
+ var hasDontEnumBug = !({ 'toString': null }).propertyIsEnumerable('toString'),
1329
+ hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype'),
1330
+ hasStringEnumBug = !owns('x', '0'),
1331
+ dontEnums = [
1332
+ 'toString',
1333
+ 'toLocaleString',
1334
+ 'valueOf',
1335
+ 'hasOwnProperty',
1336
+ 'isPrototypeOf',
1337
+ 'propertyIsEnumerable',
1338
+ 'constructor'
1339
+ ],
1340
+ dontEnumsLength = dontEnums.length;
1341
+
1342
+ defineProperties(Object, {
1343
+ keys: function keys(object) {
1344
+ var isFn = isCallable(object),
1345
+ isArgs = isArguments(object),
1346
+ isObject = object !== null && typeof object === 'object',
1347
+ isStr = isObject && isString(object);
1348
+
1349
+ if (!isObject && !isFn && !isArgs) {
1350
+ throw new TypeError('Object.keys called on a non-object');
1351
+ }
1352
+
1353
+ var theKeys = [];
1354
+ var skipProto = hasProtoEnumBug && isFn;
1355
+ if ((isStr && hasStringEnumBug) || isArgs) {
1356
+ for (var i = 0; i < object.length; ++i) {
1357
+ theKeys.push(String(i));
1358
+ }
1359
+ }
1360
+
1361
+ if (!isArgs) {
1362
+ for (var name in object) {
1363
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
1364
+ theKeys.push(String(name));
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ if (hasDontEnumBug) {
1370
+ var ctor = object.constructor,
1371
+ skipConstructor = ctor && ctor.prototype === object;
1372
+ for (var j = 0; j < dontEnumsLength; j++) {
1373
+ var dontEnum = dontEnums[j];
1374
+ if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
1375
+ theKeys.push(dontEnum);
1376
+ }
1377
+ }
1378
+ }
1379
+ return theKeys;
1380
+ }
1381
+ });
1382
+
1383
+ var keysWorksWithArguments = Object.keys && (function () {
1384
+ // Safari 5.0 bug
1385
+ return Object.keys(arguments).length === 2;
1386
+ }(1, 2));
1387
+ var originalKeys = Object.keys;
1388
+ defineProperties(Object, {
1389
+ keys: function keys(object) {
1390
+ if (isArguments(object)) {
1391
+ return originalKeys(ArrayPrototype.slice.call(object));
1392
+ } else {
1393
+ return originalKeys(object);
1394
+ }
1395
+ }
1396
+ }, !keysWorksWithArguments);
1397
+
1398
+ //
1399
+ // Date
1400
+ // ====
1401
+ //
1402
+
1403
+ // ES5 15.9.5.43
1404
+ // http://es5.github.com/#x15.9.5.43
1405
+ // This function returns a String value represent the instance in time
1406
+ // represented by this Date object. The format of the String is the Date Time
1407
+ // string format defined in 15.9.1.15. All fields are present in the String.
1408
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
1409
+ // this object is not a finite Number a RangeError exception is thrown.
1410
+ var negativeDate = -62198755200000;
1411
+ var negativeYearString = '-000001';
1412
+ var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
1413
+
1414
+ defineProperties(Date.prototype, {
1415
+ toISOString: function toISOString() {
1416
+ var result, length, value, year, month;
1417
+ if (!isFinite(this)) {
1418
+ throw new RangeError('Date.prototype.toISOString called on non-finite value.');
1419
+ }
1420
+
1421
+ year = this.getUTCFullYear();
1422
+
1423
+ month = this.getUTCMonth();
1424
+ // see https://github.com/es-shims/es5-shim/issues/111
1425
+ year += Math.floor(month / 12);
1426
+ month = (month % 12 + 12) % 12;
1427
+
1428
+ // the date time string format is specified in 15.9.1.15.
1429
+ result = [month + 1, this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
1430
+ year = (
1431
+ (year < 0 ? '-' : (year > 9999 ? '+' : '')) +
1432
+ ('00000' + Math.abs(year)).slice((0 <= year && year <= 9999) ? -4 : -6)
1433
+ );
1434
+
1435
+ length = result.length;
1436
+ while (length--) {
1437
+ value = result[length];
1438
+ // pad months, days, hours, minutes, and seconds to have two
1439
+ // digits.
1440
+ if (value < 10) {
1441
+ result[length] = '0' + value;
1442
+ }
1443
+ }
1444
+ // pad milliseconds to have three digits.
1445
+ return (
1446
+ year + '-' + result.slice(0, 2).join('-') +
1447
+ 'T' + result.slice(2).join(':') + '.' +
1448
+ ('000' + this.getUTCMilliseconds()).slice(-3) + 'Z'
1449
+ );
1450
+ }
1451
+ }, hasNegativeDateBug);
1452
+
1453
+ // ES5 15.9.5.44
1454
+ // http://es5.github.com/#x15.9.5.44
1455
+ // This function provides a String representation of a Date object for use by
1456
+ // JSON.stringify (15.12.3).
1457
+ var dateToJSONIsSupported = (function () {
1458
+ try {
1459
+ return Date.prototype.toJSON &&
1460
+ new Date(NaN).toJSON() === null &&
1461
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
1462
+ Date.prototype.toJSON.call({ // generic
1463
+ toISOString: function () { return true; }
1464
+ });
1465
+ } catch (e) {
1466
+ return false;
1467
+ }
1468
+ }());
1469
+ if (!dateToJSONIsSupported) {
1470
+ Date.prototype.toJSON = function toJSON(key) {
1471
+ // When the toJSON method is called with argument key, the following
1472
+ // steps are taken:
1473
+
1474
+ // 1. Let O be the result of calling ToObject, giving it the this
1475
+ // value as its argument.
1476
+ // 2. Let tv be ES.ToPrimitive(O, hint Number).
1477
+ var O = Object(this);
1478
+ var tv = ES.ToPrimitive(O);
1479
+ // 3. If tv is a Number and is not finite, return null.
1480
+ if (typeof tv === 'number' && !isFinite(tv)) {
1481
+ return null;
1482
+ }
1483
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
1484
+ // O with argument "toISOString".
1485
+ var toISO = O.toISOString;
1486
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1487
+ if (!isCallable(toISO)) {
1488
+ throw new TypeError('toISOString property is not callable');
1489
+ }
1490
+ // 6. Return the result of calling the [[Call]] internal method of
1491
+ // toISO with O as the this value and an empty argument list.
1492
+ return toISO.call(O);
1493
+
1494
+ // NOTE 1 The argument is ignored.
1495
+
1496
+ // NOTE 2 The toJSON function is intentionally generic; it does not
1497
+ // require that its this value be a Date object. Therefore, it can be
1498
+ // transferred to other kinds of objects for use as a method. However,
1499
+ // it does require that any such object have a toISOString method. An
1500
+ // object is free to use the argument key to filter its
1501
+ // stringification.
1502
+ };
1503
+ }
1504
+
1505
+ // ES5 15.9.4.2
1506
+ // http://es5.github.com/#x15.9.4.2
1507
+ // based on work shared by Daniel Friesen (dantman)
1508
+ // http://gist.github.com/303249
1509
+ var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
1510
+ var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
1511
+ var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
1512
+ if (!Date.parse || doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
1513
+ // XXX global assignment won't work in embeddings that use
1514
+ // an alternate object for the context.
1515
+ /* global Date: true */
1516
+ /* eslint-disable no-undef */
1517
+ Date = (function (NativeDate) {
1518
+ /* eslint-enable no-undef */
1519
+ // Date.length === 7
1520
+ var DateShim = function Date(Y, M, D, h, m, s, ms) {
1521
+ var length = arguments.length;
1522
+ var date;
1523
+ if (this instanceof NativeDate) {
1524
+ date = length === 1 && String(Y) === Y ? // isString(Y)
1525
+ // We explicitly pass it through parse:
1526
+ new NativeDate(DateShim.parse(Y)) :
1527
+ // We have to manually make calls depending on argument
1528
+ // length here
1529
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
1530
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
1531
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
1532
+ length >= 4 ? new NativeDate(Y, M, D, h) :
1533
+ length >= 3 ? new NativeDate(Y, M, D) :
1534
+ length >= 2 ? new NativeDate(Y, M) :
1535
+ length >= 1 ? new NativeDate(Y) :
1536
+ new NativeDate();
1537
+ } else {
1538
+ date = NativeDate.apply(this, arguments);
1539
+ }
1540
+ // Prevent mixups with unfixed Date object
1541
+ defineProperties(date, { constructor: DateShim }, true);
1542
+ return date;
1543
+ };
1544
+
1545
+ // 15.9.1.15 Date Time String Format.
1546
+ var isoDateExpression = new RegExp('^' +
1547
+ '(\\d{4}|[+-]\\d{6})' + // four-digit year capture or sign +
1548
+ // 6-digit extended year
1549
+ '(?:-(\\d{2})' + // optional month capture
1550
+ '(?:-(\\d{2})' + // optional day capture
1551
+ '(?:' + // capture hours:minutes:seconds.milliseconds
1552
+ 'T(\\d{2})' + // hours capture
1553
+ ':(\\d{2})' + // minutes capture
1554
+ '(?:' + // optional :seconds.milliseconds
1555
+ ':(\\d{2})' + // seconds capture
1556
+ '(?:(\\.\\d{1,}))?' + // milliseconds capture
1557
+ ')?' +
1558
+ '(' + // capture UTC offset component
1559
+ 'Z|' + // UTC capture
1560
+ '(?:' + // offset specifier +/-hours:minutes
1561
+ '([-+])' + // sign capture
1562
+ '(\\d{2})' + // hours offset capture
1563
+ ':(\\d{2})' + // minutes offset capture
1564
+ ')' +
1565
+ ')?)?)?)?' +
1566
+ '$');
1567
+
1568
+ var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
1569
+
1570
+ var dayFromMonth = function dayFromMonth(year, month) {
1571
+ var t = month > 1 ? 1 : 0;
1572
+ return (
1573
+ months[month] +
1574
+ Math.floor((year - 1969 + t) / 4) -
1575
+ Math.floor((year - 1901 + t) / 100) +
1576
+ Math.floor((year - 1601 + t) / 400) +
1577
+ 365 * (year - 1970)
1578
+ );
1579
+ };
1580
+
1581
+ var toUTC = function toUTC(t) {
1582
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
1583
+ };
1584
+
1585
+ // Copy any custom methods a 3rd party library may have added
1586
+ for (var key in NativeDate) {
1587
+ if (owns(NativeDate, key)) {
1588
+ DateShim[key] = NativeDate[key];
1589
+ }
1590
+ }
1591
+
1592
+ // Copy "native" methods explicitly; they may be non-enumerable
1593
+ defineProperties(DateShim, {
1594
+ now: NativeDate.now,
1595
+ UTC: NativeDate.UTC
1596
+ }, true);
1597
+ DateShim.prototype = NativeDate.prototype;
1598
+ defineProperties(DateShim.prototype, {
1599
+ constructor: DateShim
1600
+ }, true);
1601
+
1602
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
1603
+ var parseShim = function parse(string) {
1604
+ var match = isoDateExpression.exec(string);
1605
+ if (match) {
1606
+ // parse months, days, hours, minutes, seconds, and milliseconds
1607
+ // provide default values if necessary
1608
+ // parse the UTC offset component
1609
+ var year = Number(match[1]),
1610
+ month = Number(match[2] || 1) - 1,
1611
+ day = Number(match[3] || 1) - 1,
1612
+ hour = Number(match[4] || 0),
1613
+ minute = Number(match[5] || 0),
1614
+ second = Number(match[6] || 0),
1615
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
1616
+ // When time zone is missed, local offset should be used
1617
+ // (ES 5.1 bug)
1618
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1619
+ isLocalTime = Boolean(match[4] && !match[8]),
1620
+ signOffset = match[9] === '-' ? 1 : -1,
1621
+ hourOffset = Number(match[10] || 0),
1622
+ minuteOffset = Number(match[11] || 0),
1623
+ result;
1624
+ if (
1625
+ hour < (
1626
+ minute > 0 || second > 0 || millisecond > 0 ?
1627
+ 24 : 25
1628
+ ) &&
1629
+ minute < 60 && second < 60 && millisecond < 1000 &&
1630
+ month > -1 && month < 12 && hourOffset < 24 &&
1631
+ minuteOffset < 60 && // detect invalid offsets
1632
+ day > -1 &&
1633
+ day < (
1634
+ dayFromMonth(year, month + 1) -
1635
+ dayFromMonth(year, month)
1636
+ )
1637
+ ) {
1638
+ result = (
1639
+ (dayFromMonth(year, month) + day) * 24 +
1640
+ hour +
1641
+ hourOffset * signOffset
1642
+ ) * 60;
1643
+ result = (
1644
+ (result + minute + minuteOffset * signOffset) * 60 +
1645
+ second
1646
+ ) * 1000 + millisecond;
1647
+ if (isLocalTime) {
1648
+ result = toUTC(result);
1649
+ }
1650
+ if (-8.64e15 <= result && result <= 8.64e15) {
1651
+ return result;
1652
+ }
1653
+ }
1654
+ return NaN;
1655
+ }
1656
+ return NativeDate.parse.apply(this, arguments);
1657
+ };
1658
+ defineProperties(DateShim, { parse: parseShim });
1659
+
1660
+ return DateShim;
1661
+ }(Date));
1662
+ /* global Date: false */
1663
+ }
1664
+
1665
+ // ES5 15.9.4.4
1666
+ // http://es5.github.com/#x15.9.4.4
1667
+ if (!Date.now) {
1668
+ Date.now = function now() {
1669
+ return new Date().getTime();
1670
+ };
1671
+ }
1672
+
1673
+ //
1674
+ // Number
1675
+ // ======
1676
+ //
1677
+
1678
+ // ES5.1 15.7.4.5
1679
+ // http://es5.github.com/#x15.7.4.5
1680
+ var hasToFixedBugs = NumberPrototype.toFixed && (
1681
+ (0.00008).toFixed(3) !== '0.000' ||
1682
+ (0.9).toFixed(0) !== '1' ||
1683
+ (1.255).toFixed(2) !== '1.25' ||
1684
+ (1000000000000000128).toFixed(0) !== '1000000000000000128'
1685
+ );
1686
+
1687
+ var toFixedHelpers = {
1688
+ base: 1e7,
1689
+ size: 6,
1690
+ data: [0, 0, 0, 0, 0, 0],
1691
+ multiply: function multiply(n, c) {
1692
+ var i = -1;
1693
+ var c2 = c;
1694
+ while (++i < toFixedHelpers.size) {
1695
+ c2 += n * toFixedHelpers.data[i];
1696
+ toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
1697
+ c2 = Math.floor(c2 / toFixedHelpers.base);
1698
+ }
1699
+ },
1700
+ divide: function divide(n) {
1701
+ var i = toFixedHelpers.size, c = 0;
1702
+ while (--i >= 0) {
1703
+ c += toFixedHelpers.data[i];
1704
+ toFixedHelpers.data[i] = Math.floor(c / n);
1705
+ c = (c % n) * toFixedHelpers.base;
1706
+ }
1707
+ },
1708
+ numToString: function numToString() {
1709
+ var i = toFixedHelpers.size;
1710
+ var s = '';
1711
+ while (--i >= 0) {
1712
+ if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
1713
+ var t = String(toFixedHelpers.data[i]);
1714
+ if (s === '') {
1715
+ s = t;
1716
+ } else {
1717
+ s += '0000000'.slice(0, 7 - t.length) + t;
1718
+ }
1719
+ }
1720
+ }
1721
+ return s;
1722
+ },
1723
+ pow: function pow(x, n, acc) {
1724
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1725
+ },
1726
+ log: function log(x) {
1727
+ var n = 0;
1728
+ var x2 = x;
1729
+ while (x2 >= 4096) {
1730
+ n += 12;
1731
+ x2 /= 4096;
1732
+ }
1733
+ while (x2 >= 2) {
1734
+ n += 1;
1735
+ x2 /= 2;
1736
+ }
1737
+ return n;
1738
+ }
1739
+ };
1740
+
1741
+ defineProperties(NumberPrototype, {
1742
+ toFixed: function toFixed(fractionDigits) {
1743
+ var f, x, s, m, e, z, j, k;
1744
+
1745
+ // Test for NaN and round fractionDigits down
1746
+ f = Number(fractionDigits);
1747
+ f = f !== f ? 0 : Math.floor(f);
1748
+
1749
+ if (f < 0 || f > 20) {
1750
+ throw new RangeError('Number.toFixed called with invalid number of decimals');
1751
+ }
1752
+
1753
+ x = Number(this);
1754
+
1755
+ // Test for NaN
1756
+ if (x !== x) {
1757
+ return 'NaN';
1758
+ }
1759
+
1760
+ // If it is too big or small, return the string value of the number
1761
+ if (x <= -1e21 || x >= 1e21) {
1762
+ return String(x);
1763
+ }
1764
+
1765
+ s = '';
1766
+
1767
+ if (x < 0) {
1768
+ s = '-';
1769
+ x = -x;
1770
+ }
1771
+
1772
+ m = '0';
1773
+
1774
+ if (x > 1e-21) {
1775
+ // 1e-21 < x < 1e21
1776
+ // -70 < log2(x) < 70
1777
+ e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
1778
+ z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
1779
+ z *= 0x10000000000000; // Math.pow(2, 52);
1780
+ e = 52 - e;
1781
+
1782
+ // -18 < e < 122
1783
+ // x = z / 2 ^ e
1784
+ if (e > 0) {
1785
+ toFixedHelpers.multiply(0, z);
1786
+ j = f;
1787
+
1788
+ while (j >= 7) {
1789
+ toFixedHelpers.multiply(1e7, 0);
1790
+ j -= 7;
1791
+ }
1792
+
1793
+ toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
1794
+ j = e - 1;
1795
+
1796
+ while (j >= 23) {
1797
+ toFixedHelpers.divide(1 << 23);
1798
+ j -= 23;
1799
+ }
1800
+
1801
+ toFixedHelpers.divide(1 << j);
1802
+ toFixedHelpers.multiply(1, 1);
1803
+ toFixedHelpers.divide(2);
1804
+ m = toFixedHelpers.numToString();
1805
+ } else {
1806
+ toFixedHelpers.multiply(0, z);
1807
+ toFixedHelpers.multiply(1 << (-e), 0);
1808
+ m = toFixedHelpers.numToString() + '0.00000000000000000000'.slice(2, 2 + f);
1809
+ }
1810
+ }
1811
+
1812
+ if (f > 0) {
1813
+ k = m.length;
1814
+
1815
+ if (k <= f) {
1816
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1817
+ } else {
1818
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1819
+ }
1820
+ } else {
1821
+ m = s + m;
1822
+ }
1823
+
1824
+ return m;
1825
+ }
1826
+ }, hasToFixedBugs);
1827
+
1828
+ //
1829
+ // String
1830
+ // ======
1831
+ //
1832
+
1833
+ // ES5 15.5.4.14
1834
+ // http://es5.github.com/#x15.5.4.14
1835
+
1836
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1837
+ // Many browsers do not split properly with regular expressions or they
1838
+ // do not perform the split correctly under obscure conditions.
1839
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1840
+ // I've tested in many browsers and this seems to cover the deviant ones:
1841
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1842
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1843
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1844
+ // [undefined, "t", undefined, "e", ...]
1845
+ // ''.split(/.?/) should be [], not [""]
1846
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1847
+
1848
+ var string_split = StringPrototype.split;
1849
+ if (
1850
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1851
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1852
+ 'tesst'.split(/(s)*/)[1] === 't' ||
1853
+ 'test'.split(/(?:)/, -1).length !== 4 ||
1854
+ ''.split(/.?/).length ||
1855
+ '.'.split(/()()/).length > 1
1856
+ ) {
1857
+ (function () {
1858
+ var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
1859
+
1860
+ StringPrototype.split = function (separator, limit) {
1861
+ var string = this;
1862
+ if (typeof separator === 'undefined' && limit === 0) {
1863
+ return [];
1864
+ }
1865
+
1866
+ // If `separator` is not a regex, use native split
1867
+ if (!isRegex(separator)) {
1868
+ return string_split.call(this, separator, limit);
1869
+ }
1870
+
1871
+ var output = [];
1872
+ var flags = (separator.ignoreCase ? 'i' : '') +
1873
+ (separator.multiline ? 'm' : '') +
1874
+ (separator.extended ? 'x' : '') + // Proposed for ES6
1875
+ (separator.sticky ? 'y' : ''), // Firefox 3+
1876
+ lastLastIndex = 0,
1877
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1878
+ separator2, match, lastIndex, lastLength;
1879
+ var separatorCopy = new RegExp(separator.source, flags + 'g');
1880
+ string += ''; // Type-convert
1881
+ if (!compliantExecNpcg) {
1882
+ // Doesn't need flags gy, but they don't hurt
1883
+ separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
1884
+ }
1885
+ /* Values for `limit`, per the spec:
1886
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1887
+ * If 0, Infinity, or NaN: 0
1888
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1889
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1890
+ * If other: Type-convert, then use the above rules
1891
+ */
1892
+ var splitLimit = typeof limit === 'undefined' ?
1893
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1894
+ ES.ToUint32(limit);
1895
+ match = separatorCopy.exec(string);
1896
+ while (match) {
1897
+ // `separatorCopy.lastIndex` is not reliable cross-browser
1898
+ lastIndex = match.index + match[0].length;
1899
+ if (lastIndex > lastLastIndex) {
1900
+ output.push(string.slice(lastLastIndex, match.index));
1901
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1902
+ // nonparticipating capturing groups
1903
+ if (!compliantExecNpcg && match.length > 1) {
1904
+ /* eslint-disable no-loop-func */
1905
+ match[0].replace(separator2, function () {
1906
+ for (var i = 1; i < arguments.length - 2; i++) {
1907
+ if (typeof arguments[i] === 'undefined') {
1908
+ match[i] = void 0;
1909
+ }
1910
+ }
1911
+ });
1912
+ /* eslint-enable no-loop-func */
1913
+ }
1914
+ if (match.length > 1 && match.index < string.length) {
1915
+ array_push.apply(output, match.slice(1));
1916
+ }
1917
+ lastLength = match[0].length;
1918
+ lastLastIndex = lastIndex;
1919
+ if (output.length >= splitLimit) {
1920
+ break;
1921
+ }
1922
+ }
1923
+ if (separatorCopy.lastIndex === match.index) {
1924
+ separatorCopy.lastIndex++; // Avoid an infinite loop
1925
+ }
1926
+ match = separatorCopy.exec(string);
1927
+ }
1928
+ if (lastLastIndex === string.length) {
1929
+ if (lastLength || !separatorCopy.test('')) {
1930
+ output.push('');
1931
+ }
1932
+ } else {
1933
+ output.push(string.slice(lastLastIndex));
1934
+ }
1935
+ return output.length > splitLimit ? output.slice(0, splitLimit) : output;
1936
+ };
1937
+ }());
1938
+
1939
+ // [bugfix, chrome]
1940
+ // If separator is undefined, then the result array contains just one String,
1941
+ // which is the this value (converted to a String). If limit is not undefined,
1942
+ // then the output array is truncated so that it contains no more than limit
1943
+ // elements.
1944
+ // "0".split(undefined, 0) -> []
1945
+ } else if ('0'.split(void 0, 0).length) {
1946
+ StringPrototype.split = function split(separator, limit) {
1947
+ if (typeof separator === 'undefined' && limit === 0) { return []; }
1948
+ return string_split.call(this, separator, limit);
1949
+ };
1950
+ }
1951
+
1952
+ var str_replace = StringPrototype.replace;
1953
+ var replaceReportsGroupsCorrectly = (function () {
1954
+ var groups = [];
1955
+ 'x'.replace(/x(.)?/g, function (match, group) {
1956
+ groups.push(group);
1957
+ });
1958
+ return groups.length === 1 && typeof groups[0] === 'undefined';
1959
+ }());
1960
+
1961
+ if (!replaceReportsGroupsCorrectly) {
1962
+ StringPrototype.replace = function replace(searchValue, replaceValue) {
1963
+ var isFn = isCallable(replaceValue);
1964
+ var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
1965
+ if (!isFn || !hasCapturingGroups) {
1966
+ return str_replace.call(this, searchValue, replaceValue);
1967
+ } else {
1968
+ var wrappedReplaceValue = function (match) {
1969
+ var length = arguments.length;
1970
+ var originalLastIndex = searchValue.lastIndex;
1971
+ searchValue.lastIndex = 0;
1972
+ var args = searchValue.exec(match) || [];
1973
+ searchValue.lastIndex = originalLastIndex;
1974
+ args.push(arguments[length - 2], arguments[length - 1]);
1975
+ return replaceValue.apply(this, args);
1976
+ };
1977
+ return str_replace.call(this, searchValue, wrappedReplaceValue);
1978
+ }
1979
+ };
1980
+ }
1981
+
1982
+ // ECMA-262, 3rd B.2.3
1983
+ // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
1984
+ // non-normative section suggesting uniform semantics and it should be
1985
+ // normalized across all browsers
1986
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1987
+ var string_substr = StringPrototype.substr;
1988
+ var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
1989
+ defineProperties(StringPrototype, {
1990
+ substr: function substr(start, length) {
1991
+ var normalizedStart = start;
1992
+ if (start < 0) {
1993
+ normalizedStart = Math.max(this.length + start, 0);
1994
+ }
1995
+ return string_substr.call(this, normalizedStart, length);
1996
+ }
1997
+ }, hasNegativeSubstrBug);
1998
+
1999
+ // ES5 15.5.4.20
2000
+ // whitespace from: http://es5.github.io/#x15.5.4.20
2001
+ var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
2002
+ '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
2003
+ '\u2029\uFEFF';
2004
+ var zeroWidth = '\u200b';
2005
+ var wsRegexChars = '[' + ws + ']';
2006
+ var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
2007
+ var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
2008
+ var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
2009
+ defineProperties(StringPrototype, {
2010
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
2011
+ // http://perfectionkills.com/whitespace-deviations/
2012
+ trim: function trim() {
2013
+ if (typeof this === 'undefined' || this === null) {
2014
+ throw new TypeError("can't convert " + this + ' to object');
2015
+ }
2016
+ return String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
2017
+ }
2018
+ }, hasTrimWhitespaceBug);
2019
+
2020
+ // ES-5 15.1.2.2
2021
+ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
2022
+ /* global parseInt: true */
2023
+ parseInt = (function (origParseInt) {
2024
+ var hexRegex = /^0[xX]/;
2025
+ return function parseInt(str, radix) {
2026
+ var string = String(str).trim();
2027
+ var defaultedRadix = Number(radix) || (hexRegex.test(string) ? 16 : 10);
2028
+ return origParseInt(string, defaultedRadix);
2029
+ };
2030
+ }(parseInt));
2031
+ }
2032
+
2033
+ }));
2034
+
2035
+ !window.addEventListener && (function (WindowPrototype, DocumentPrototype, ElementPrototype, addEventListener, removeEventListener, dispatchEvent, registry) {
2036
+ WindowPrototype[addEventListener] = DocumentPrototype[addEventListener] = ElementPrototype[addEventListener] = function (type, listener) {
2037
+ var target = this;
2038
+
2039
+ registry.unshift([target, type, listener, function (event) {
2040
+ event.currentTarget = target;
2041
+ event.preventDefault = function () { event.returnValue = false };
2042
+ event.stopPropagation = function () { event.cancelBubble = true };
2043
+ event.target = event.srcElement || target;
2044
+
2045
+ listener.call(target, event);
2046
+ }]);
2047
+
2048
+ this.attachEvent("on" + type, registry[0][3]);
2049
+ };
2050
+
2051
+ WindowPrototype[removeEventListener] = DocumentPrototype[removeEventListener] = ElementPrototype[removeEventListener] = function (type, listener) {
2052
+ for (var index = 0, register; register = registry[index]; ++index) {
2053
+ if (register[0] == this && register[1] == type && register[2] == listener) {
2054
+ return this.detachEvent("on" + type, registry.splice(index, 1)[0][3]);
2055
+ }
2056
+ }
2057
+ };
2058
+
2059
+ WindowPrototype[dispatchEvent] = DocumentPrototype[dispatchEvent] = ElementPrototype[dispatchEvent] = function (eventObject) {
2060
+ return this.fireEvent("on" + eventObject.type, eventObject);
2061
+ };
2062
+ })(Window.prototype, HTMLDocument.prototype, Element.prototype, "addEventListener", "removeEventListener", "dispatchEvent", []);
2063
+
2064
+ /**
2065
+ * Module: rem - v1.3.4
2066
+ * Description: A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers
2067
+ * Date Built: 2014-07-02
2068
+ * Copyright (c) 2014 | Chuck Carpenter <chuck.carpenter@me.com>,Lucas Serven <lserven@gmail.com>;
2069
+ * @see https://github.com/chuckcarpenter/REM-unit-polyfill
2070
+ **/
2071
+
2072
+ (function (window, undefined) {
2073
+ "use strict";
2074
+ // test for REM unit support
2075
+ var cssremunit = function() {
2076
+ var div = document.createElement( 'div' );
2077
+ div.style.cssText = 'font-size: 1rem;';
2078
+
2079
+ return (/rem/).test(div.style.fontSize);
2080
+ },
2081
+
2082
+ // filter returned links for stylesheets
2083
+ isStyleSheet = function () {
2084
+ var styles = document.getElementsByTagName('link'),
2085
+ filteredLinks = [];
2086
+
2087
+ for ( var i = 0; i < styles.length; i++) {
2088
+ if ( styles[i].rel.toLowerCase() === 'stylesheet' && styles[i].getAttribute('data-norem') === null ) {
2089
+
2090
+ filteredLinks.push( styles[i].href );
2091
+ }
2092
+ }
2093
+
2094
+ return filteredLinks;
2095
+ },
2096
+
2097
+ processLinks = function () {
2098
+ //prepare to match each link
2099
+ for( var i = 0; i < links.length; i++ ){
2100
+ xhr( links[i], storeCSS );
2101
+ }
2102
+ },
2103
+
2104
+ storeCSS = function ( response, link ) {
2105
+
2106
+ preCSS.push(response.responseText);
2107
+ CSSLinks.push(link);
2108
+
2109
+ if( CSSLinks.length === links.length ){
2110
+ for( var j = 0; j < CSSLinks.length; j++ ){
2111
+ matchCSS( preCSS[j], CSSLinks[j] );
2112
+ }
2113
+
2114
+ if( ( links = importLinks.slice(0) ).length > 0 ){ //after finishing all current links, set links equal to the new imports found
2115
+ CSSLinks = [];
2116
+ preCSS = [];
2117
+ importLinks = [];
2118
+ processLinks();
2119
+ } else {
2120
+ buildCSS();
2121
+ }
2122
+ }
2123
+ },
2124
+
2125
+ matchCSS = function ( sheetCSS, link ) { // collect all of the rules from the xhr response texts and match them to a pattern
2126
+ var clean = removeMediaQueries( sheetCSS ).replace(/\/\*[\s\S]*?\*\//g, ''), // remove MediaQueries and comments
2127
+ pattern = /[\w\d\s\-\/\\\[\]:,.'"*()<>+~%#^$_=|@]+\{[\w\d\s\-\/\\%#:!;,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!;,.'"*()]*\}/g, //find selectors that use rem in one or more of their rules
2128
+ current = clean.match(pattern),
2129
+ remPattern =/\d*\.?\d+rem/g,
2130
+ remCurrent = clean.match(remPattern),
2131
+ sheetPathPattern = /(.*\/)/,
2132
+ sheetPath = sheetPathPattern.exec(link)[0], //relative path to css file specified in @import
2133
+ importPattern = /@import (?:url\()?['"]?([^'\)"]*)['"]?\)?[^;]*/gm, //matches all @import variations outlined at: https://developer.mozilla.org/en-US/docs/Web/CSS/@import
2134
+ importStatement;
2135
+
2136
+ while( (importStatement = importPattern.exec(sheetCSS)) !== null ){
2137
+ if( importStatement[1].indexOf("/") === 0 ) { // check if the value of importStatement[1] is a root relative path, in which case it shouldn't be concatenated with sheetPath
2138
+ importLinks.push( importStatement[1] );
2139
+ } else {
2140
+ importLinks.push( sheetPath + importStatement[1] );
2141
+ }
2142
+ }
2143
+
2144
+ if( current !== null && current.length !== 0 ){
2145
+ found = found.concat( current ); // save all of the blocks of rules with rem in a property
2146
+ foundProps = foundProps.concat( remCurrent ); // save all of the properties with rem
2147
+ }
2148
+ },
2149
+
2150
+ buildCSS = function () { // first build each individual rule from elements in the found array and then add it to the string of rules.
2151
+ var pattern = /[\w\d\s\-\/\\%#:,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!,.'"*()]*[;}]/g; // find properties with rem values in them
2152
+ for( var i = 0; i < found.length; i++ ){
2153
+ rules = rules + found[i].substr(0,found[i].indexOf("{")+1); // save the selector portion of each rule with a rem value
2154
+ var current = found[i].match( pattern );
2155
+ for( var j = 0; j<current.length; j++ ){ // build a new set of with only the selector and properties that have rem in the value
2156
+ rules = rules + current[j];
2157
+ if( j === current.length-1 && rules[rules.length-1] !== "}" ){
2158
+ rules = rules + "\n}";
2159
+ }
2160
+ }
2161
+ }
2162
+
2163
+ parseCSS();
2164
+ },
2165
+
2166
+ parseCSS = function () { // replace each set of parentheses with evaluated content
2167
+ for( var i = 0; i < foundProps.length; i++ ){
2168
+ css[i] = Math.round( parseFloat(foundProps[i].substr(0,foundProps[i].length-3)*fontSize) ) + 'px';
2169
+ }
2170
+
2171
+ loadCSS();
2172
+ },
2173
+
2174
+ loadCSS = function () { // replace and load the new rules
2175
+ for( var i = 0; i < css.length; i++ ){ // only run this loop as many times as css has entries
2176
+ if( css[i] ){
2177
+ rules = rules.replace( foundProps[i],css[i] ); // replace old rules with our processed rules
2178
+ }
2179
+ }
2180
+ var remcss = document.createElement( 'style' );
2181
+ remcss.setAttribute( 'type', 'text/css' );
2182
+ remcss.id = 'remReplace';
2183
+ document.getElementsByTagName( 'head' )[0].appendChild( remcss ); // create the new element
2184
+ if( remcss.styleSheet ) {
2185
+ remcss.styleSheet.cssText = rules; // IE8 will not support innerHTML on read-only elements, such as STYLE
2186
+ } else {
2187
+ remcss.appendChild( document.createTextNode( rules ) );
2188
+ }
2189
+ },
2190
+
2191
+ xhr = function ( url, callback ) { // create new XMLHttpRequest object and run it
2192
+ try {
2193
+ //try to create a request object
2194
+ //arranging the two conditions this way is for IE7/8's benefit
2195
+ //so that it works with any combination of ActiveX or Native XHR settings,
2196
+ //as long as one or the other is enabled; but if both are enabled
2197
+ //it prefers ActiveX, which means it still works with local files
2198
+ //(Native XHR in IE7/8 is blocked and throws "access is denied",
2199
+ // but ActiveX is permitted if the user allows it [default is to prompt])
2200
+ var xhr = window.ActiveXObject ? ( new ActiveXObject('Microsoft.XMLHTTP') || new ActiveXObject('Msxml2.XMLHTTP') ) : new XMLHttpRequest();
2201
+
2202
+ xhr.open( 'GET', url, true );
2203
+ xhr.onreadystatechange = function() {
2204
+ if ( xhr.readyState === 4 ){
2205
+ callback(xhr, url);
2206
+ } // else { callback function on AJAX error }
2207
+ };
2208
+
2209
+ xhr.send( null );
2210
+ } catch (e){
2211
+ if ( window.XDomainRequest ) {
2212
+ var xdr = new XDomainRequest();
2213
+ xdr.open('get', url);
2214
+ xdr.onload = function() {
2215
+ callback(xdr, url);
2216
+ };
2217
+ xdr.onerror = function() {
2218
+ return false; // xdr load fail
2219
+ };
2220
+ xdr.send();
2221
+ }
2222
+ }
2223
+ },
2224
+
2225
+ // Remove queries.
2226
+ removeMediaQueries = function(css) {
2227
+ // Test for Media Query support
2228
+ if ( !window.matchMedia && !window.msMatchMedia ) {
2229
+ // If the browser doesn't support media queries, we find all @media declarations in the CSS and remove them.
2230
+ // Note: Since @rules can't be nested in the CSS spec, we're safe to just check for the closest following "}}" to the "@media".
2231
+ css = css.replace(/@media[\s\S]*?\}\s*\}/g, "");
2232
+ }
2233
+
2234
+ return css;
2235
+ };
2236
+
2237
+ if( !cssremunit() ){ // this checks if the rem value is supported
2238
+ var rules = '', // initialize the rules variable in this scope so it can be used later
2239
+ links = isStyleSheet(), // initialize the array holding the sheets urls for use later
2240
+ importLinks = [], //initialize the array holding the import sheet urls for use later
2241
+ found = [], // initialize the array holding the found rules for use later
2242
+ foundProps = [], // initialize the array holding the found properties for use later
2243
+ preCSS = [], // initialize array that holds css before being parsed
2244
+ CSSLinks = [], //initialize array holding css links returned from xhr
2245
+ css = [], // initialize the array holding the parsed rules for use later
2246
+ fontSize = '';
2247
+
2248
+ // Notice: rem is a "root em" that means that in case when html element size was changed by css
2249
+ // or style we should not change document.documentElement.fontSize to 1em - only body size should be changed
2250
+ // to 1em for calculation
2251
+
2252
+ fontSize = (function () {
2253
+ var doc = document,
2254
+ docElement = doc.documentElement,
2255
+ body = doc.body || doc.createElement('body'),
2256
+ isFakeBody = !doc.body,
2257
+ div = doc.createElement('div'),
2258
+ currentSize = body.style.fontSize,
2259
+ size;
2260
+
2261
+ if ( isFakeBody ) {
2262
+ docElement.appendChild( body );
2263
+ }
2264
+
2265
+ div.style.cssText = 'width:1em; position:absolute; visibility:hidden; padding: 0;';
2266
+
2267
+ body.style.fontSize = '1em';
2268
+
2269
+ body.appendChild( div );
2270
+ size = div.offsetWidth;
2271
+
2272
+ if ( isFakeBody ) {
2273
+ docElement.removeChild( body );
2274
+ }
2275
+ else {
2276
+ body.removeChild( div );
2277
+ body.style.fontSize = currentSize;
2278
+ }
2279
+
2280
+ return size;
2281
+ }());
2282
+
2283
+ processLinks();
2284
+ } // else { do nothing, you are awesome and have REM support }
2285
+
2286
+ })(window);
2287
+
2288
+ /*! Respond.js v1.4.2: min/max-width media query polyfill
2289
+ * Copyright 2014 Scott Jehl
2290
+ * Licensed under MIT
2291
+ * http://j.mp/respondjs */
2292
+
2293
+ !function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='&shy;<style media="'+a+'"> #mq-test-1 { width: 42px; }</style>',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){v(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))},g=function(a){return a.replace(c.regex.minmaxwh,"").match(c.regex.other)};if(c.ajax=f,c.queue=d,c.unsupportedmq=g,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,comments:/\/\*[^*]*\*+([^/][^*]*\*+)*\//gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,maxw:/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,minmaxwh:/\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi,other:/\([^\)]*\)/g},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var h,i,j,k=a.document,l=k.documentElement,m=[],n=[],o=[],p={},q=30,r=k.getElementsByTagName("head")[0]||l,s=k.getElementsByTagName("base")[0],t=r.getElementsByTagName("link"),u=function(){var a,b=k.createElement("div"),c=k.body,d=l.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=k.createElement("body"),c.style.background="none"),l.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&l.insertBefore(c,l.firstChild),a=b.offsetWidth,f?l.removeChild(c):c.removeChild(b),l.style.fontSize=d,e&&(c.style.fontSize=e),a=j=parseFloat(a)},v=function(b){var c="clientWidth",d=l[c],e="CSS1Compat"===k.compatMode&&d||k.body[c]||d,f={},g=t[t.length-1],p=(new Date).getTime();if(b&&h&&q>p-h)return a.clearTimeout(i),i=a.setTimeout(v,q),void 0;h=p;for(var s in m)if(m.hasOwnProperty(s)){var w=m[s],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?j||u():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?j||u():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(n[w.rules]))}for(var C in o)o.hasOwnProperty(C)&&o[C]&&o[C].parentNode===r&&r.removeChild(o[C]);o.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=k.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,r.insertBefore(E,g.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(k.createTextNode(F)),o.push(E)}},w=function(a,b,d){var e=a.replace(c.regex.comments,"").replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var h=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},i=!f&&d;b.length&&(b+="/"),i&&(f=1);for(var j=0;f>j;j++){var k,l,o,p;i?(k=d,n.push(h(a))):(k=e[j].match(c.regex.findStyles)&&RegExp.$1,n.push(RegExp.$2&&h(RegExp.$2))),o=k.split(","),p=o.length;for(var q=0;p>q;q++)l=o[q],g(l)||m.push({media:l.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:n.length-1,hasquery:l.indexOf("(")>-1,minw:l.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:l.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}v()},x=function(){if(d.length){var b=d.shift();f(b.href,function(c){w(c,b.href,b.media),p[b.href]=!0,a.setTimeout(function(){x()},0)})}},y=function(){for(var b=0;b<t.length;b++){var c=t[b],e=c.href,f=c.media,g=c.rel&&"stylesheet"===c.rel.toLowerCase();e&&g&&!p[e]&&(c.styleSheet&&c.styleSheet.rawCssText?(w(c.styleSheet.rawCssText,e,f),p[e]=!0):(!/^([a-zA-Z:]*\/\/)/.test(e)&&!s||e.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&("//"===e.substring(0,2)&&(e=a.location.protocol+e),d.push({href:e,media:f})))}x()};y(),c.update=y,c.getEmValue=u,a.addEventListener?a.addEventListener("resize",b,!1):a.attachEvent&&a.attachEvent("onresize",b)}}(this);