webshims-rails 1.14.1 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +0 -0
  4. data/vendor/assets/javascripts/webshims/polyfiller.js +3 -8
  5. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/canvas2png.js +0 -0
  6. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.js +0 -0
  7. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.swf +0 -0
  8. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/proxy.php +0 -0
  9. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/save.php +0 -0
  10. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/canvas2png.js +0 -0
  11. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  12. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  13. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flashcanvas.js +0 -0
  14. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/proxy.php +0 -0
  15. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/save.php +0 -0
  16. data/vendor/assets/javascripts/webshims/shims/color-picker.js +2 -2
  17. data/vendor/assets/javascripts/webshims/shims/combos/1.js +66 -43
  18. data/vendor/assets/javascripts/webshims/shims/combos/10.js +66 -31
  19. data/vendor/assets/javascripts/webshims/shims/combos/11.js +66 -31
  20. data/vendor/assets/javascripts/webshims/shims/combos/12.js +96 -59
  21. data/vendor/assets/javascripts/webshims/shims/combos/13.js +96 -59
  22. data/vendor/assets/javascripts/webshims/shims/combos/14.js +0 -0
  23. data/vendor/assets/javascripts/webshims/shims/combos/15.js +4 -1
  24. data/vendor/assets/javascripts/webshims/shims/combos/16.js +70 -44
  25. data/vendor/assets/javascripts/webshims/shims/combos/17.js +66 -31
  26. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1241 -1126
  27. data/vendor/assets/javascripts/webshims/shims/combos/19.js +1272 -1214
  28. data/vendor/assets/javascripts/webshims/shims/combos/2.js +66 -43
  29. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1272 -1214
  30. data/vendor/assets/javascripts/webshims/shims/combos/21.js +61 -92
  31. data/vendor/assets/javascripts/webshims/shims/combos/22.js +30 -16
  32. data/vendor/assets/javascripts/webshims/shims/combos/23.js +66 -43
  33. data/vendor/assets/javascripts/webshims/shims/combos/25.js +41 -85
  34. data/vendor/assets/javascripts/webshims/shims/combos/26.js +1556 -2316
  35. data/vendor/assets/javascripts/webshims/shims/combos/27.js +12 -10
  36. data/vendor/assets/javascripts/webshims/shims/combos/28.js +4 -1
  37. data/vendor/assets/javascripts/webshims/shims/combos/29.js +0 -0
  38. data/vendor/assets/javascripts/webshims/shims/combos/3.js +0 -0
  39. data/vendor/assets/javascripts/webshims/shims/combos/30.js +0 -0
  40. data/vendor/assets/javascripts/webshims/shims/combos/31.js +0 -0
  41. data/vendor/assets/javascripts/webshims/shims/combos/32.js +1175 -1095
  42. data/vendor/assets/javascripts/webshims/shims/combos/33.js +0 -0
  43. data/vendor/assets/javascripts/webshims/shims/combos/34.js +30 -16
  44. data/vendor/assets/javascripts/webshims/shims/combos/4.js +0 -0
  45. data/vendor/assets/javascripts/webshims/shims/combos/5.js +66 -31
  46. data/vendor/assets/javascripts/webshims/shims/combos/6.js +66 -31
  47. data/vendor/assets/javascripts/webshims/shims/combos/7.js +66 -43
  48. data/vendor/assets/javascripts/webshims/shims/combos/8.js +66 -43
  49. data/vendor/assets/javascripts/webshims/shims/combos/9.js +66 -31
  50. data/vendor/assets/javascripts/webshims/shims/combos/97.js +63 -28
  51. data/vendor/assets/javascripts/webshims/shims/combos/98.js +149 -74
  52. data/vendor/assets/javascripts/webshims/shims/combos/99.js +149 -74
  53. data/vendor/assets/javascripts/webshims/shims/combos/comboinfo.json +1 -1
  54. data/vendor/assets/javascripts/webshims/shims/details.js +0 -0
  55. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +0 -0
  56. data/vendor/assets/javascripts/webshims/shims/es5.js +1175 -1095
  57. data/vendor/assets/javascripts/webshims/shims/excanvas.js +0 -0
  58. data/vendor/assets/javascripts/webshims/shims/filereader.js +10 -9
  59. data/vendor/assets/javascripts/webshims/shims/form-combat.js +0 -0
  60. data/vendor/assets/javascripts/webshims/shims/form-core.js +0 -0
  61. data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +0 -0
  62. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +0 -0
  63. data/vendor/assets/javascripts/webshims/shims/form-fixrangechange.js +0 -0
  64. data/vendor/assets/javascripts/webshims/shims/form-message.js +0 -0
  65. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +0 -0
  66. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +0 -0
  67. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +40 -11
  68. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +4 -1
  69. data/vendor/assets/javascripts/webshims/shims/form-shim-extend2.js +2 -1
  70. data/vendor/assets/javascripts/webshims/shims/form-validation.js +80 -47
  71. data/vendor/assets/javascripts/webshims/shims/form-validators.js +19 -8
  72. data/vendor/assets/javascripts/webshims/shims/forms-picker.js +21 -1
  73. data/vendor/assets/javascripts/webshims/shims/geolocation.js +0 -0
  74. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ar.js +0 -0
  75. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ch-CN.js +0 -0
  76. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-cs.js +0 -0
  77. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-de.js +0 -0
  78. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-el.js +0 -0
  79. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-en.js +0 -0
  80. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-es.js +0 -0
  81. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-fa.js +130 -0
  82. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-fr.js +0 -0
  83. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-he.js +0 -0
  84. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-hi.js +0 -0
  85. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-hu.js +0 -0
  86. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-it.js +0 -0
  87. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ja.js +0 -0
  88. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-lt.js +0 -0
  89. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-nl.js +0 -0
  90. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pl.js +0 -0
  91. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt-BR.js +0 -0
  92. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt-PT.js +0 -0
  93. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt.js +0 -0
  94. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ru.js +0 -0
  95. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-sv.js +0 -0
  96. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-zh-CN.js +0 -0
  97. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-zh-TW.js +130 -0
  98. data/vendor/assets/javascripts/webshims/shims/jajax.js +0 -0
  99. data/vendor/assets/javascripts/webshims/shims/jme/_icons.scss +186 -0
  100. data/vendor/assets/javascripts/webshims/shims/jme/b.js +63 -28
  101. data/vendor/assets/javascripts/webshims/shims/jme/c.js +86 -46
  102. data/vendor/assets/javascripts/webshims/shims/jme/controls.css +317 -211
  103. data/vendor/assets/javascripts/webshims/shims/jme/controls.scss +59 -223
  104. data/vendor/assets/javascripts/webshims/shims/jme/jme.eot +0 -0
  105. data/vendor/assets/javascripts/webshims/shims/jme/jme.svg +0 -0
  106. data/vendor/assets/javascripts/webshims/shims/jme/jme.ttf +0 -0
  107. data/vendor/assets/javascripts/webshims/shims/jme/jme.woff +0 -0
  108. data/vendor/assets/javascripts/webshims/shims/jme/mediacontrols-lazy.js +66 -14
  109. data/vendor/assets/javascripts/webshims/shims/jme/p.js +0 -0
  110. data/vendor/assets/javascripts/webshims/shims/jpicker/ChangeLog.txt +0 -0
  111. data/vendor/assets/javascripts/webshims/shims/jpicker/ReadMe.txt +0 -0
  112. data/vendor/assets/javascripts/webshims/shims/jpicker/images/AlphaBar.png +0 -0
  113. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Bars.png +0 -0
  114. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Maps.png +0 -0
  115. data/vendor/assets/javascripts/webshims/shims/jpicker/images/NoColor.png +0 -0
  116. data/vendor/assets/javascripts/webshims/shims/jpicker/images/bar-opacity.png +0 -0
  117. data/vendor/assets/javascripts/webshims/shims/jpicker/images/map-opacity.png +0 -0
  118. data/vendor/assets/javascripts/webshims/shims/jpicker/images/mappoint.gif +0 -0
  119. data/vendor/assets/javascripts/webshims/shims/jpicker/images/picker.gif +0 -0
  120. data/vendor/assets/javascripts/webshims/shims/jpicker/images/preview-opacity.png +0 -0
  121. data/vendor/assets/javascripts/webshims/shims/jpicker/images/rangearrows.gif +0 -0
  122. data/vendor/assets/javascripts/webshims/shims/jpicker/jpicker.css +55 -48
  123. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +66 -43
  124. data/vendor/assets/javascripts/webshims/shims/mediaelement-debug.js +833 -0
  125. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +31 -76
  126. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +0 -0
  127. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +0 -0
  128. data/vendor/assets/javascripts/webshims/shims/moxie/flash/Moxie.cdn.swf +0 -0
  129. data/vendor/assets/javascripts/webshims/shims/moxie/flash/Moxie.min.swf +0 -0
  130. data/vendor/assets/javascripts/webshims/shims/moxie/js/moxie.js +1542 -2303
  131. data/vendor/assets/javascripts/webshims/shims/moxie/silverlight/Moxie.cdn.xap +0 -0
  132. data/vendor/assets/javascripts/webshims/shims/moxie/silverlight/Moxie.min.xap +0 -0
  133. data/vendor/assets/javascripts/webshims/shims/picture.js +160 -79
  134. data/vendor/assets/javascripts/webshims/shims/plugins/jquery.ui.position.js +0 -0
  135. data/vendor/assets/javascripts/webshims/shims/promise.js +0 -0
  136. data/vendor/assets/javascripts/webshims/shims/range-ui.js +26 -20
  137. data/vendor/assets/javascripts/webshims/shims/sizzle.js +0 -0
  138. data/vendor/assets/javascripts/webshims/shims/styles/color-picker.png +0 -0
  139. data/vendor/assets/javascripts/webshims/shims/styles/forms-ext.css +444 -326
  140. data/vendor/assets/javascripts/webshims/shims/styles/forms-picker.css +379 -300
  141. data/vendor/assets/javascripts/webshims/shims/styles/progress.gif +0 -0
  142. data/vendor/assets/javascripts/webshims/shims/styles/progress.png +0 -0
  143. data/vendor/assets/javascripts/webshims/shims/styles/scss/_api-forms-ext.scss +8 -8
  144. data/vendor/assets/javascripts/webshims/shims/styles/scss/_api-shim.scss +0 -0
  145. data/vendor/assets/javascripts/webshims/shims/styles/scss/_extends.scss +0 -14
  146. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-ext.scss +104 -85
  147. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-picker.scss +20 -32
  148. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim-ext.scss +0 -0
  149. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +14 -34
  150. data/vendor/assets/javascripts/webshims/shims/styles/shim-ext.css +920 -728
  151. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +471 -391
  152. data/vendor/assets/javascripts/webshims/shims/styles/widget.eot +0 -0
  153. data/vendor/assets/javascripts/webshims/shims/styles/widget.svg +0 -0
  154. data/vendor/assets/javascripts/webshims/shims/styles/widget.ttf +0 -0
  155. data/vendor/assets/javascripts/webshims/shims/styles/widget.woff +0 -0
  156. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  157. data/vendor/assets/javascripts/webshims/shims/swfmini-embed.js +0 -0
  158. data/vendor/assets/javascripts/webshims/shims/swfmini.js +0 -0
  159. data/vendor/assets/javascripts/webshims/shims/track-ui.js +0 -0
  160. data/vendor/assets/javascripts/webshims/shims/track.js +30 -16
  161. metadata +8 -4
  162. data/vendor/assets/javascripts/webshims/shims/styles/config.rb +0 -12
  163. data/vendor/assets/javascripts/webshims/shims/swf/filereader.swf +0 -0
@@ -228,14 +228,50 @@ webshims.isReady('swfmini', true);
228
228
  setTimeout(function(){
229
229
  webshims.isReady('es5', true);
230
230
  });
231
- /**
232
- * Brings an environment as close to ECMAScript 5 compliance
233
- * as is possible with the facilities of erstwhile engines.
234
- *
235
- * Annotated ES5: http://es5.github.com/ (specific links below)
236
- * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
237
- * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
238
- */
231
+ /**
232
+ * Brings an environment as close to ECMAScript 5 compliance
233
+ * as is possible with the facilities of erstwhile engines.
234
+ *
235
+ * Annotated ES5: http://es5.github.com/ (specific links below)
236
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
237
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
238
+ */
239
+
240
+ // Shortcut to an often accessed properties, in order to avoid multiple
241
+ // dereference that costs universally.
242
+ var call = Function.prototype.call;
243
+ var prototypeOfArray = Array.prototype;
244
+ var prototypeOfObject = Object.prototype;
245
+ var _Array_slice_ = prototypeOfArray.slice;
246
+ var array_splice = Array.prototype.splice;
247
+ var array_push = Array.prototype.push;
248
+ var array_unshift = Array.prototype.unshift;
249
+
250
+ // Having a toString local variable name breaks in Opera so use _toString.
251
+ var _toString = prototypeOfObject.toString;
252
+
253
+ var isFunction = function (val) {
254
+ return prototypeOfObject.toString.call(val) === '[object Function]';
255
+ };
256
+ var isRegex = function (val) {
257
+ return prototypeOfObject.toString.call(val) === '[object RegExp]';
258
+ };
259
+ var isArray = function isArray(obj) {
260
+ return _toString.call(obj) === "[object Array]";
261
+ };
262
+ var isArguments = function isArguments(value) {
263
+ var str = _toString.call(value);
264
+ var isArgs = str === '[object Arguments]';
265
+ if (!isArgs) {
266
+ isArgs = !isArray(str)
267
+ && value !== null
268
+ && typeof value === 'object'
269
+ && typeof value.length === 'number'
270
+ && value.length >= 0
271
+ && isFunction(value.callee);
272
+ }
273
+ return isArgs;
274
+ };
239
275
 
240
276
  //
241
277
  // Function
@@ -245,150 +281,157 @@ setTimeout(function(){
245
281
  // ES-5 15.3.4.5
246
282
  // http://es5.github.com/#x15.3.4.5
247
283
 
248
- function Empty() {}
284
+ function Empty() {}
249
285
 
250
- if (!Function.prototype.bind) {
251
- Function.prototype.bind = function bind(that) { // .length is 1
252
- // 1. Let Target be the this value.
253
- var target = this;
254
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
255
- if (typeof target != "function") {
256
- throw new TypeError("Function.prototype.bind called on incompatible " + target);
257
- }
258
- // 3. Let A be a new (possibly empty) internal list of all of the
259
- // argument values provided after thisArg (arg1, arg2 etc), in order.
260
- // XXX slicedArgs will stand in for "A" if used
261
- var args = _Array_slice_.call(arguments, 1); // for normal call
262
- // 4. Let F be a new native ECMAScript object.
263
- // 11. Set the [[Prototype]] internal property of F to the standard
264
- // built-in Function prototype object as specified in 15.3.3.1.
265
- // 12. Set the [[Call]] internal property of F as described in
266
- // 15.3.4.5.1.
267
- // 13. Set the [[Construct]] internal property of F as described in
268
- // 15.3.4.5.2.
269
- // 14. Set the [[HasInstance]] internal property of F as described in
270
- // 15.3.4.5.3.
271
- var bound = function () {
272
-
273
- if (this instanceof bound) {
274
- // 15.3.4.5.2 [[Construct]]
275
- // When the [[Construct]] internal method of a function object,
276
- // F that was created using the bind function is called with a
277
- // list of arguments ExtraArgs, the following steps are taken:
278
- // 1. Let target be the value of F's [[TargetFunction]]
279
- // internal property.
280
- // 2. If target has no [[Construct]] internal method, a
281
- // TypeError exception is thrown.
282
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
283
- // property.
284
- // 4. Let args be a new list containing the same values as the
285
- // list boundArgs in the same order followed by the same
286
- // values as the list ExtraArgs in the same order.
287
- // 5. Return the result of calling the [[Construct]] internal
288
- // method of target providing args as the arguments.
289
-
290
- var result = target.apply(
291
- this,
292
- args.concat(_Array_slice_.call(arguments))
293
- );
294
- if (Object(result) === result) {
295
- return result;
296
- }
297
- return this;
298
-
299
- } else {
300
- // 15.3.4.5.1 [[Call]]
301
- // When the [[Call]] internal method of a function object, F,
302
- // which was created using the bind function is called with a
303
- // this value and a list of arguments ExtraArgs, the following
304
- // steps are taken:
305
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
306
- // property.
307
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
308
- // property.
309
- // 3. Let target be the value of F's [[TargetFunction]] internal
310
- // property.
311
- // 4. Let args be a new list containing the same values as the
312
- // list boundArgs in the same order followed by the same
313
- // values as the list ExtraArgs in the same order.
314
- // 5. Return the result of calling the [[Call]] internal method
315
- // of target providing boundThis as the this value and
316
- // providing args as the arguments.
317
-
318
- // equiv: target.call(this, ...boundArgs, ...args)
319
- return target.apply(
320
- that,
321
- args.concat(_Array_slice_.call(arguments))
322
- );
323
-
324
- }
286
+ if (!Function.prototype.bind) {
287
+ Function.prototype.bind = function bind(that) { // .length is 1
288
+ // 1. Let Target be the this value.
289
+ var target = this;
290
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
291
+ if (!isFunction(target)) {
292
+ throw new TypeError("Function.prototype.bind called on incompatible " + target);
293
+ }
294
+ // 3. Let A be a new (possibly empty) internal list of all of the
295
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
296
+ // XXX slicedArgs will stand in for "A" if used
297
+ var args = _Array_slice_.call(arguments, 1); // for normal call
298
+ // 4. Let F be a new native ECMAScript object.
299
+ // 11. Set the [[Prototype]] internal property of F to the standard
300
+ // built-in Function prototype object as specified in 15.3.3.1.
301
+ // 12. Set the [[Call]] internal property of F as described in
302
+ // 15.3.4.5.1.
303
+ // 13. Set the [[Construct]] internal property of F as described in
304
+ // 15.3.4.5.2.
305
+ // 14. Set the [[HasInstance]] internal property of F as described in
306
+ // 15.3.4.5.3.
307
+ var binder = function () {
308
+
309
+ if (this instanceof bound) {
310
+ // 15.3.4.5.2 [[Construct]]
311
+ // When the [[Construct]] internal method of a function object,
312
+ // F that was created using the bind function is called with a
313
+ // list of arguments ExtraArgs, the following steps are taken:
314
+ // 1. Let target be the value of F's [[TargetFunction]]
315
+ // internal property.
316
+ // 2. If target has no [[Construct]] internal method, a
317
+ // TypeError exception is thrown.
318
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
319
+ // property.
320
+ // 4. Let args be a new list containing the same values as the
321
+ // list boundArgs in the same order followed by the same
322
+ // values as the list ExtraArgs in the same order.
323
+ // 5. Return the result of calling the [[Construct]] internal
324
+ // method of target providing args as the arguments.
325
+
326
+ var result = target.apply(
327
+ this,
328
+ args.concat(_Array_slice_.call(arguments))
329
+ );
330
+ if (Object(result) === result) {
331
+ return result;
332
+ }
333
+ return this;
325
334
 
326
- };
327
- if(target.prototype) {
328
- Empty.prototype = target.prototype;
329
- bound.prototype = new Empty();
330
- // Clean up dangling references.
331
- Empty.prototype = null;
332
- }
333
- // XXX bound.length is never writable, so don't even try
334
- //
335
- // 15. If the [[Class]] internal property of Target is "Function", then
336
- // a. Let L be the length property of Target minus the length of A.
337
- // b. Set the length own property of F to either 0 or L, whichever is
338
- // larger.
339
- // 16. Else set the length own property of F to 0.
340
- // 17. Set the attributes of the length own property of F to the values
341
- // specified in 15.3.5.1.
342
-
343
- // TODO
344
- // 18. Set the [[Extensible]] internal property of F to true.
345
-
346
- // TODO
347
- // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
348
- // 20. Call the [[DefineOwnProperty]] internal method of F with
349
- // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
350
- // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
351
- // false.
352
- // 21. Call the [[DefineOwnProperty]] internal method of F with
353
- // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
354
- // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
355
- // and false.
356
-
357
- // TODO
358
- // NOTE Function objects created using Function.prototype.bind do not
359
- // have a prototype property or the [[Code]], [[FormalParameters]], and
360
- // [[Scope]] internal properties.
361
- // XXX can't delete prototype in pure-js.
362
-
363
- // 22. Return F.
364
- return bound;
365
- };
366
- }
335
+ } else {
336
+ // 15.3.4.5.1 [[Call]]
337
+ // When the [[Call]] internal method of a function object, F,
338
+ // which was created using the bind function is called with a
339
+ // this value and a list of arguments ExtraArgs, the following
340
+ // steps are taken:
341
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
342
+ // property.
343
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
344
+ // property.
345
+ // 3. Let target be the value of F's [[TargetFunction]] internal
346
+ // property.
347
+ // 4. Let args be a new list containing the same values as the
348
+ // list boundArgs in the same order followed by the same
349
+ // values as the list ExtraArgs in the same order.
350
+ // 5. Return the result of calling the [[Call]] internal method
351
+ // of target providing boundThis as the this value and
352
+ // providing args as the arguments.
353
+
354
+ // equiv: target.call(this, ...boundArgs, ...args)
355
+ return target.apply(
356
+ that,
357
+ args.concat(_Array_slice_.call(arguments))
358
+ );
359
+
360
+ }
361
+
362
+ };
363
+
364
+ // 15. If the [[Class]] internal property of Target is "Function", then
365
+ // a. Let L be the length property of Target minus the length of A.
366
+ // b. Set the length own property of F to either 0 or L, whichever is
367
+ // larger.
368
+ // 16. Else set the length own property of F to 0.
369
+
370
+ var boundLength = Math.max(0, target.length - args.length);
371
+
372
+ // 17. Set the attributes of the length own property of F to the values
373
+ // specified in 15.3.5.1.
374
+ var boundArgs = [];
375
+ for (var i = 0; i < boundLength; i++) {
376
+ boundArgs.push("$" + i);
377
+ }
378
+
379
+ // XXX Build a dynamic function with desired amount of arguments is the only
380
+ // way to set the length property of a function.
381
+ // In environments where Content Security Policies enabled (Chrome extensions,
382
+ // for ex.) all use of eval or Function costructor throws an exception.
383
+ // However in all of these environments Function.prototype.bind exists
384
+ // and so this code will never be executed.
385
+ var bound = Function("binder", "return function (" + boundArgs.join(",") + "){return binder.apply(this,arguments)}")(binder);
386
+
387
+ if (target.prototype) {
388
+ Empty.prototype = target.prototype;
389
+ bound.prototype = new Empty();
390
+ // Clean up dangling references.
391
+ Empty.prototype = null;
392
+ }
393
+
394
+ // TODO
395
+ // 18. Set the [[Extensible]] internal property of F to true.
396
+
397
+ // TODO
398
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
399
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
400
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
401
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
402
+ // false.
403
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
404
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
405
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
406
+ // and false.
407
+
408
+ // TODO
409
+ // NOTE Function objects created using Function.prototype.bind do not
410
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
411
+ // [[Scope]] internal properties.
412
+ // XXX can't delete prototype in pure-js.
413
+
414
+ // 22. Return F.
415
+ return bound;
416
+ };
417
+ }
367
418
 
368
- // Shortcut to an often accessed properties, in order to avoid multiple
369
- // dereference that costs universally.
370
419
  // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
371
420
  // us it in defining shortcuts.
372
- var call = Function.prototype.call;
373
- var prototypeOfArray = Array.prototype;
374
- var prototypeOfObject = Object.prototype;
375
- var _Array_slice_ = prototypeOfArray.slice;
376
- // Having a toString local variable name breaks in Opera so use _toString.
377
- var _toString = call.bind(prototypeOfObject.toString);
378
- var owns = call.bind(prototypeOfObject.hasOwnProperty);
421
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
379
422
 
380
423
  // If JS engine supports accessors creating shortcuts.
381
- var defineGetter;
382
- var defineSetter;
383
- var lookupGetter;
384
- var lookupSetter;
385
- var supportsAccessors;
386
- if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
387
- defineGetter = call.bind(prototypeOfObject.__defineGetter__);
388
- defineSetter = call.bind(prototypeOfObject.__defineSetter__);
389
- lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
390
- lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
391
- }
424
+ var defineGetter;
425
+ var defineSetter;
426
+ var lookupGetter;
427
+ var lookupSetter;
428
+ var supportsAccessors;
429
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
430
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
431
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
432
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
433
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
434
+ }
392
435
 
393
436
  //
394
437
  // Array
@@ -397,127 +440,63 @@ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
397
440
 
398
441
  // ES5 15.4.4.12
399
442
  // http://es5.github.com/#x15.4.4.12
400
- // Default value for second param
401
- // [bugfix, ielt9, old browsers]
402
- // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
403
- if ([1,2].splice(0).length != 2) {
404
- var array_splice = Array.prototype.splice;
405
-
406
- if(function() { // test IE < 9 to splice bug - see issue #138
407
- function makeArray(l) {
408
- var a = [];
409
- while (l--) {
410
- a.unshift(l)
411
- }
412
- return a
413
- }
414
-
415
- var array = []
416
- , lengthBefore
417
- ;
418
-
419
- array.splice.bind(array, 0, 0).apply(null, makeArray(20));
420
- array.splice.bind(array, 0, 0).apply(null, makeArray(26));
421
-
422
- lengthBefore = array.length; //20
423
- array.splice(5, 0, "XXX"); // add one element
424
-
425
- if(lengthBefore + 1 == array.length) {
426
- return true;// has right splice implementation without bugs
427
- }
428
- // else {
429
- // IE8 bug
430
- // }
431
- }()) {//IE 6/7
432
- Array.prototype.splice = function(start, deleteCount) {
433
- if (!arguments.length) {
434
- return [];
435
- } else {
436
- return array_splice.apply(this, [
437
- start === void 0 ? 0 : start,
438
- deleteCount === void 0 ? (this.length - start) : deleteCount
439
- ].concat(_Array_slice_.call(arguments, 2)))
440
- }
441
- };
442
- }
443
- else {//IE8
444
- Array.prototype.splice = function(start, deleteCount) {
445
- var result
446
- , args = _Array_slice_.call(arguments, 2)
447
- , addElementsCount = args.length
448
- ;
449
-
450
- if(!arguments.length) {
451
- return [];
452
- }
453
-
454
- if(start === void 0) { // default
455
- start = 0;
456
- }
457
- if(deleteCount === void 0) { // default
458
- deleteCount = this.length - start;
459
- }
460
-
461
- if(addElementsCount > 0) {
462
- if(deleteCount <= 0) {
463
- if(start == this.length) { // tiny optimisation #1
464
- this.push.apply(this, args);
465
- return [];
466
- }
467
-
468
- if(start == 0) { // tiny optimisation #2
469
- this.unshift.apply(this, args);
470
- return [];
471
- }
472
- }
473
-
474
- // Array.prototype.splice implementation
475
- result = _Array_slice_.call(this, start, start + deleteCount);// delete part
476
- args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part
477
- args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part
478
-
479
- // delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part'
480
- args.unshift(0, this.length);
481
-
482
- array_splice.apply(this, args);
483
-
484
- return result;
485
- }
486
-
487
- return array_splice.call(this, start, deleteCount);
488
- }
489
-
490
- }
491
- }
443
+ var spliceWorksWithEmptyObject = (function () {
444
+ var obj = {};
445
+ Array.prototype.splice.call(obj, 0, 0, 1);
446
+ return obj.length === 1;
447
+ }());
448
+ var omittingSecondSpliceArgIsNoop = [1].splice(0).length === 0;
449
+ var spliceNoopReturnsEmptyArray = (function () {
450
+ var a = [1, 2];
451
+ var result = a.splice();
452
+ return a.length === 2 && isArray(result) && result.length === 0;
453
+ }());
454
+ if (spliceNoopReturnsEmptyArray) {
455
+ // Safari 5.0 bug where .split() returns undefined
456
+ Array.prototype.splice = function splice(start, deleteCount) {
457
+ if (arguments.length === 0) { return []; }
458
+ else { return array_splice.apply(this, arguments); }
459
+ };
460
+ }
461
+ if (!omittingSecondSpliceArgIsNoop || !spliceWorksWithEmptyObject) {
462
+ Array.prototype.splice = function splice(start, deleteCount) {
463
+ if (arguments.length === 0) { return []; }
464
+ var args = arguments;
465
+ this.length = Math.max(toInteger(this.length), 0);
466
+ if (arguments.length > 0 && typeof deleteCount !== 'number') {
467
+ args = _Array_slice_.call(arguments);
468
+ if (args.length < 2) { args.push(toInteger(deleteCount)); }
469
+ else { args[1] = toInteger(deleteCount); }
470
+ }
471
+ return array_splice.apply(this, args);
472
+ };
473
+ }
492
474
 
493
475
  // ES5 15.4.4.12
494
476
  // http://es5.github.com/#x15.4.4.13
495
477
  // Return len+argCount.
496
478
  // [bugfix, ielt8]
497
- // IE < 8 bug: [].unshift(0) == undefined but should be "1"
498
- if ([].unshift(0) != 1) {
499
- var array_unshift = Array.prototype.unshift;
500
- Array.prototype.unshift = function() {
501
- array_unshift.apply(this, arguments);
502
- return this.length;
503
- };
504
- }
479
+ // IE < 8 bug: [].unshift(0) === undefined but should be "1"
480
+ if ([].unshift(0) !== 1) {
481
+ Array.prototype.unshift = function () {
482
+ array_unshift.apply(this, arguments);
483
+ return this.length;
484
+ };
485
+ }
505
486
 
506
487
  // ES5 15.4.3.2
507
488
  // http://es5.github.com/#x15.4.3.2
508
489
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
509
- if (!Array.isArray) {
510
- Array.isArray = function isArray(obj) {
511
- return _toString(obj) == "[object Array]";
512
- };
513
- }
490
+ if (!Array.isArray) {
491
+ Array.isArray = isArray;
492
+ }
514
493
 
515
494
  // The IsCallable() check in the Array functions
516
495
  // has been replaced with a strict check on the
517
496
  // internal class of the object to trap cases where
518
497
  // the provided function was actually a regular
519
498
  // expression literal, which in V8 and
520
- // JavaScriptCore is a typeof "function". Only in
499
+ // JavaScriptCore is a typeof "function". Only in
521
500
  // V8 are regular expression literals permitted as
522
501
  // reduce parameters, so it is desirable in the
523
502
  // general case for the shim to match the more
@@ -530,302 +509,328 @@ if (!Array.isArray) {
530
509
 
531
510
  // Check failure of by-index access of string characters (IE < 9)
532
511
  // and failure of `0 in boxedString` (Rhino)
533
- var boxedString = Object("a"),
534
- splitString = boxedString[0] != "a" || !(0 in boxedString);
535
-
536
- if (!Array.prototype.forEach) {
537
- Array.prototype.forEach = function forEach(fun /*, thisp*/) {
538
- var object = toObject(this),
539
- self = splitString && _toString(this) == "[object String]" ?
540
- this.split("") :
541
- object,
542
- thisp = arguments[1],
543
- i = -1,
544
- length = self.length >>> 0;
545
-
546
- // If no callback function or if callback is not a callable function
547
- if (_toString(fun) != "[object Function]") {
548
- throw new TypeError(); // TODO message
549
- }
512
+ var boxedString = Object("a");
513
+ var splitString = boxedString[0] !== "a" || !(0 in boxedString);
514
+
515
+ var properlyBoxesContext = function properlyBoxed(method) {
516
+ // Check node 0.6.21 bug where third parameter is not boxed
517
+ var properlyBoxesNonStrict = true;
518
+ var properlyBoxesStrict = true;
519
+ if (method) {
520
+ method.call('foo', function (_, __, context) {
521
+ if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
522
+ });
550
523
 
551
- while (++i < length) {
552
- if (i in self) {
553
- // Invoke the callback function with call, passing arguments:
554
- // context, property value, property key, thisArg object
555
- // context
556
- fun.call(thisp, self[i], i, object);
557
- }
558
- }
559
- };
560
- }
524
+ method.call([1], function () {
525
+ 'use strict';
526
+ properlyBoxesStrict = typeof this === 'string';
527
+ }, 'x');
528
+ }
529
+ return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
530
+ };
531
+
532
+ if (!Array.prototype.forEach || !properlyBoxesContext(Array.prototype.forEach)) {
533
+ Array.prototype.forEach = function forEach(fun /*, thisp*/) {
534
+ var object = toObject(this),
535
+ self = splitString && _toString.call(this) === "[object String]" ?
536
+ this.split("") :
537
+ object,
538
+ thisp = arguments[1],
539
+ i = -1,
540
+ length = self.length >>> 0;
541
+
542
+ // If no callback function or if callback is not a callable function
543
+ if (!isFunction(fun)) {
544
+ throw new TypeError(); // TODO message
545
+ }
546
+
547
+ while (++i < length) {
548
+ if (i in self) {
549
+ // Invoke the callback function with call, passing arguments:
550
+ // context, property value, property key, thisArg object
551
+ // context
552
+ fun.call(thisp, self[i], i, object);
553
+ }
554
+ }
555
+ };
556
+ }
561
557
 
562
558
  // ES5 15.4.4.19
563
559
  // http://es5.github.com/#x15.4.4.19
564
560
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
565
- if (!Array.prototype.map) {
566
- Array.prototype.map = function map(fun /*, thisp*/) {
567
- var object = toObject(this),
568
- self = splitString && _toString(this) == "[object String]" ?
569
- this.split("") :
570
- object,
571
- length = self.length >>> 0,
572
- result = Array(length),
573
- thisp = arguments[1];
574
-
575
- // If no callback function or if callback is not a callable function
576
- if (_toString(fun) != "[object Function]") {
577
- throw new TypeError(fun + " is not a function");
578
- }
561
+ if (!Array.prototype.map || !properlyBoxesContext(Array.prototype.map)) {
562
+ Array.prototype.map = function map(fun /*, thisp*/) {
563
+ var object = toObject(this),
564
+ self = splitString && _toString.call(this) === "[object String]" ?
565
+ this.split("") :
566
+ object,
567
+ length = self.length >>> 0,
568
+ result = Array(length),
569
+ thisp = arguments[1];
570
+
571
+ // If no callback function or if callback is not a callable function
572
+ if (!isFunction(fun)) {
573
+ throw new TypeError(fun + " is not a function");
574
+ }
579
575
 
580
- for (var i = 0; i < length; i++) {
581
- if (i in self)
582
- result[i] = fun.call(thisp, self[i], i, object);
583
- }
584
- return result;
585
- };
586
- }
576
+ for (var i = 0; i < length; i++) {
577
+ if (i in self) {
578
+ result[i] = fun.call(thisp, self[i], i, object);
579
+ }
580
+ }
581
+ return result;
582
+ };
583
+ }
587
584
 
588
585
  // ES5 15.4.4.20
589
586
  // http://es5.github.com/#x15.4.4.20
590
587
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
591
- if (!Array.prototype.filter) {
592
- Array.prototype.filter = function filter(fun /*, thisp */) {
593
- var object = toObject(this),
594
- self = splitString && _toString(this) == "[object String]" ?
595
- this.split("") :
596
- object,
597
- length = self.length >>> 0,
598
- result = [],
599
- value,
600
- thisp = arguments[1];
601
-
602
- // If no callback function or if callback is not a callable function
603
- if (_toString(fun) != "[object Function]") {
604
- throw new TypeError(fun + " is not a function");
605
- }
588
+ if (!Array.prototype.filter || !properlyBoxesContext(Array.prototype.filter)) {
589
+ Array.prototype.filter = function filter(fun /*, thisp */) {
590
+ var object = toObject(this),
591
+ self = splitString && _toString.call(this) === "[object String]" ?
592
+ this.split("") :
593
+ object,
594
+ length = self.length >>> 0,
595
+ result = [],
596
+ value,
597
+ thisp = arguments[1];
598
+
599
+ // If no callback function or if callback is not a callable function
600
+ if (!isFunction(fun)) {
601
+ throw new TypeError(fun + " is not a function");
602
+ }
606
603
 
607
- for (var i = 0; i < length; i++) {
608
- if (i in self) {
609
- value = self[i];
610
- if (fun.call(thisp, value, i, object)) {
611
- result.push(value);
612
- }
613
- }
614
- }
615
- return result;
616
- };
617
- }
604
+ for (var i = 0; i < length; i++) {
605
+ if (i in self) {
606
+ value = self[i];
607
+ if (fun.call(thisp, value, i, object)) {
608
+ result.push(value);
609
+ }
610
+ }
611
+ }
612
+ return result;
613
+ };
614
+ }
618
615
 
619
616
  // ES5 15.4.4.16
620
617
  // http://es5.github.com/#x15.4.4.16
621
618
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
622
- if (!Array.prototype.every) {
623
- Array.prototype.every = function every(fun /*, thisp */) {
624
- var object = toObject(this),
625
- self = splitString && _toString(this) == "[object String]" ?
626
- this.split("") :
627
- object,
628
- length = self.length >>> 0,
629
- thisp = arguments[1];
630
-
631
- // If no callback function or if callback is not a callable function
632
- if (_toString(fun) != "[object Function]") {
633
- throw new TypeError(fun + " is not a function");
634
- }
619
+ if (!Array.prototype.every || !properlyBoxesContext(Array.prototype.every)) {
620
+ Array.prototype.every = function every(fun /*, thisp */) {
621
+ var object = toObject(this),
622
+ self = splitString && _toString.call(this) === "[object String]" ?
623
+ this.split("") :
624
+ object,
625
+ length = self.length >>> 0,
626
+ thisp = arguments[1];
627
+
628
+ // If no callback function or if callback is not a callable function
629
+ if (!isFunction(fun)) {
630
+ throw new TypeError(fun + " is not a function");
631
+ }
635
632
 
636
- for (var i = 0; i < length; i++) {
637
- if (i in self && !fun.call(thisp, self[i], i, object)) {
638
- return false;
639
- }
640
- }
641
- return true;
642
- };
643
- }
633
+ for (var i = 0; i < length; i++) {
634
+ if (i in self && !fun.call(thisp, self[i], i, object)) {
635
+ return false;
636
+ }
637
+ }
638
+ return true;
639
+ };
640
+ }
644
641
 
645
642
  // ES5 15.4.4.17
646
643
  // http://es5.github.com/#x15.4.4.17
647
644
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
648
- if (!Array.prototype.some) {
649
- Array.prototype.some = function some(fun /*, thisp */) {
650
- var object = toObject(this),
651
- self = splitString && _toString(this) == "[object String]" ?
652
- this.split("") :
653
- object,
654
- length = self.length >>> 0,
655
- thisp = arguments[1];
656
-
657
- // If no callback function or if callback is not a callable function
658
- if (_toString(fun) != "[object Function]") {
659
- throw new TypeError(fun + " is not a function");
660
- }
645
+ if (!Array.prototype.some || !properlyBoxesContext(Array.prototype.some)) {
646
+ Array.prototype.some = function some(fun /*, thisp */) {
647
+ var object = toObject(this),
648
+ self = splitString && _toString.call(this) === "[object String]" ?
649
+ this.split("") :
650
+ object,
651
+ length = self.length >>> 0,
652
+ thisp = arguments[1];
653
+
654
+ // If no callback function or if callback is not a callable function
655
+ if (!isFunction(fun)) {
656
+ throw new TypeError(fun + " is not a function");
657
+ }
661
658
 
662
- for (var i = 0; i < length; i++) {
663
- if (i in self && fun.call(thisp, self[i], i, object)) {
664
- return true;
665
- }
666
- }
667
- return false;
668
- };
669
- }
659
+ for (var i = 0; i < length; i++) {
660
+ if (i in self && fun.call(thisp, self[i], i, object)) {
661
+ return true;
662
+ }
663
+ }
664
+ return false;
665
+ };
666
+ }
670
667
 
671
668
  // ES5 15.4.4.21
672
669
  // http://es5.github.com/#x15.4.4.21
673
670
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
674
- if (!Array.prototype.reduce) {
675
- Array.prototype.reduce = function reduce(fun /*, initial*/) {
676
- var object = toObject(this),
677
- self = splitString && _toString(this) == "[object String]" ?
678
- this.split("") :
679
- object,
680
- length = self.length >>> 0;
681
-
682
- // If no callback function or if callback is not a callable function
683
- if (_toString(fun) != "[object Function]") {
684
- throw new TypeError(fun + " is not a function");
685
- }
671
+ var reduceCoercesToObject = false;
672
+ if (Array.prototype.reduce) {
673
+ reduceCoercesToObject = typeof Array.prototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object';
674
+ }
675
+ if (!Array.prototype.reduce || !reduceCoercesToObject) {
676
+ Array.prototype.reduce = function reduce(fun /*, initial*/) {
677
+ var object = toObject(this),
678
+ self = splitString && _toString.call(this) === "[object String]" ?
679
+ this.split("") :
680
+ object,
681
+ length = self.length >>> 0;
682
+
683
+ // If no callback function or if callback is not a callable function
684
+ if (!isFunction(fun)) {
685
+ throw new TypeError(fun + " is not a function");
686
+ }
686
687
 
687
- // no value to return if no initial value and an empty array
688
- if (!length && arguments.length == 1) {
689
- throw new TypeError("reduce of empty array with no initial value");
690
- }
688
+ // no value to return if no initial value and an empty array
689
+ if (!length && arguments.length === 1) {
690
+ throw new TypeError("reduce of empty array with no initial value");
691
+ }
691
692
 
692
- var i = 0;
693
- var result;
694
- if (arguments.length >= 2) {
695
- result = arguments[1];
696
- } else {
697
- do {
698
- if (i in self) {
699
- result = self[i++];
700
- break;
701
- }
702
-
703
- // if array contains no values, no initial value to return
704
- if (++i >= length) {
705
- throw new TypeError("reduce of empty array with no initial value");
706
- }
707
- } while (true);
708
- }
693
+ var i = 0;
694
+ var result;
695
+ if (arguments.length >= 2) {
696
+ result = arguments[1];
697
+ } else {
698
+ do {
699
+ if (i in self) {
700
+ result = self[i++];
701
+ break;
702
+ }
709
703
 
710
- for (; i < length; i++) {
711
- if (i in self) {
712
- result = fun.call(void 0, result, self[i], i, object);
713
- }
714
- }
704
+ // if array contains no values, no initial value to return
705
+ if (++i >= length) {
706
+ throw new TypeError("reduce of empty array with no initial value");
707
+ }
708
+ } while (true);
709
+ }
715
710
 
716
- return result;
717
- };
718
- }
711
+ for (; i < length; i++) {
712
+ if (i in self) {
713
+ result = fun.call(void 0, result, self[i], i, object);
714
+ }
715
+ }
716
+
717
+ return result;
718
+ };
719
+ }
719
720
 
720
721
  // ES5 15.4.4.22
721
722
  // http://es5.github.com/#x15.4.4.22
722
723
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
723
- if (!Array.prototype.reduceRight) {
724
- Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
725
- var object = toObject(this),
726
- self = splitString && _toString(this) == "[object String]" ?
727
- this.split("") :
728
- object,
729
- length = self.length >>> 0;
730
-
731
- // If no callback function or if callback is not a callable function
732
- if (_toString(fun) != "[object Function]") {
733
- throw new TypeError(fun + " is not a function");
734
- }
724
+ var reduceRightCoercesToObject = false;
725
+ if (Array.prototype.reduceRight) {
726
+ reduceRightCoercesToObject = typeof Array.prototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object';
727
+ }
728
+ if (!Array.prototype.reduceRight || !reduceRightCoercesToObject) {
729
+ Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
730
+ var object = toObject(this),
731
+ self = splitString && _toString.call(this) === "[object String]" ?
732
+ this.split("") :
733
+ object,
734
+ length = self.length >>> 0;
735
+
736
+ // If no callback function or if callback is not a callable function
737
+ if (!isFunction(fun)) {
738
+ throw new TypeError(fun + " is not a function");
739
+ }
735
740
 
736
- // no value to return if no initial value, empty array
737
- if (!length && arguments.length == 1) {
738
- throw new TypeError("reduceRight of empty array with no initial value");
739
- }
741
+ // no value to return if no initial value, empty array
742
+ if (!length && arguments.length === 1) {
743
+ throw new TypeError("reduceRight of empty array with no initial value");
744
+ }
740
745
 
741
- var result, i = length - 1;
742
- if (arguments.length >= 2) {
743
- result = arguments[1];
744
- } else {
745
- do {
746
- if (i in self) {
747
- result = self[i--];
748
- break;
749
- }
750
-
751
- // if array contains no values, no initial value to return
752
- if (--i < 0) {
753
- throw new TypeError("reduceRight of empty array with no initial value");
754
- }
755
- } while (true);
756
- }
746
+ var result, i = length - 1;
747
+ if (arguments.length >= 2) {
748
+ result = arguments[1];
749
+ } else {
750
+ do {
751
+ if (i in self) {
752
+ result = self[i--];
753
+ break;
754
+ }
757
755
 
758
- if (i < 0) {
759
- return result;
760
- }
756
+ // if array contains no values, no initial value to return
757
+ if (--i < 0) {
758
+ throw new TypeError("reduceRight of empty array with no initial value");
759
+ }
760
+ } while (true);
761
+ }
761
762
 
762
- do {
763
- if (i in this) {
764
- result = fun.call(void 0, result, self[i], i, object);
765
- }
766
- } while (i--);
763
+ if (i < 0) {
764
+ return result;
765
+ }
767
766
 
768
- return result;
769
- };
770
- }
767
+ do {
768
+ if (i in self) {
769
+ result = fun.call(void 0, result, self[i], i, object);
770
+ }
771
+ } while (i--);
772
+
773
+ return result;
774
+ };
775
+ }
771
776
 
772
777
  // ES5 15.4.4.14
773
778
  // http://es5.github.com/#x15.4.4.14
774
779
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
775
- if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
776
- Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
777
- var self = splitString && _toString(this) == "[object String]" ?
778
- this.split("") :
779
- toObject(this),
780
- length = self.length >>> 0;
781
-
782
- if (!length) {
783
- return -1;
784
- }
780
+ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) !== -1)) {
781
+ Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
782
+ var self = splitString && _toString.call(this) === "[object String]" ?
783
+ this.split("") :
784
+ toObject(this),
785
+ length = self.length >>> 0;
786
+
787
+ if (!length) {
788
+ return -1;
789
+ }
785
790
 
786
- var i = 0;
787
- if (arguments.length > 1) {
788
- i = toInteger(arguments[1]);
789
- }
791
+ var i = 0;
792
+ if (arguments.length > 1) {
793
+ i = toInteger(arguments[1]);
794
+ }
790
795
 
791
- // handle negative indices
792
- i = i >= 0 ? i : Math.max(0, length + i);
793
- for (; i < length; i++) {
794
- if (i in self && self[i] === sought) {
795
- return i;
796
- }
797
- }
798
- return -1;
799
- };
800
- }
796
+ // handle negative indices
797
+ i = i >= 0 ? i : Math.max(0, length + i);
798
+ for (; i < length; i++) {
799
+ if (i in self && self[i] === sought) {
800
+ return i;
801
+ }
802
+ }
803
+ return -1;
804
+ };
805
+ }
801
806
 
802
807
  // ES5 15.4.4.15
803
808
  // http://es5.github.com/#x15.4.4.15
804
809
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
805
- if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
806
- Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
807
- var self = splitString && _toString(this) == "[object String]" ?
808
- this.split("") :
809
- toObject(this),
810
- length = self.length >>> 0;
811
-
812
- if (!length) {
813
- return -1;
814
- }
815
- var i = length - 1;
816
- if (arguments.length > 1) {
817
- i = Math.min(i, toInteger(arguments[1]));
818
- }
819
- // handle negative indices
820
- i = i >= 0 ? i : length - Math.abs(i);
821
- for (; i >= 0; i--) {
822
- if (i in self && sought === self[i]) {
823
- return i;
824
- }
825
- }
826
- return -1;
827
- };
828
- }
810
+ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) !== -1)) {
811
+ Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
812
+ var self = splitString && _toString.call(this) === "[object String]" ?
813
+ this.split("") :
814
+ toObject(this),
815
+ length = self.length >>> 0;
816
+
817
+ if (!length) {
818
+ return -1;
819
+ }
820
+ var i = length - 1;
821
+ if (arguments.length > 1) {
822
+ i = Math.min(i, toInteger(arguments[1]));
823
+ }
824
+ // handle negative indices
825
+ i = i >= 0 ? i : length - Math.abs(i);
826
+ for (; i >= 0; i--) {
827
+ if (i in self && sought === self[i]) {
828
+ return i;
829
+ }
830
+ }
831
+ return -1;
832
+ };
833
+ }
829
834
 
830
835
  //
831
836
  // Object
@@ -834,52 +839,71 @@ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
834
839
 
835
840
  // ES5 15.2.3.14
836
841
  // http://es5.github.com/#x15.2.3.14
837
- if (!Object.keys) {
838
- // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
839
- var hasDontEnumBug = true,
840
- dontEnums = [
841
- "toString",
842
- "toLocaleString",
843
- "valueOf",
844
- "hasOwnProperty",
845
- "isPrototypeOf",
846
- "propertyIsEnumerable",
847
- "constructor"
848
- ],
849
- dontEnumsLength = dontEnums.length;
850
-
851
- for (var key in {"toString": null}) {
852
- hasDontEnumBug = false;
853
- }
854
-
855
- Object.keys = function keys(object) {
856
-
857
- if (
858
- (typeof object != "object" && typeof object != "function") ||
859
- object === null
860
- ) {
861
- throw new TypeError("Object.keys called on a non-object");
862
- }
863
-
864
- var keys = [];
865
- for (var name in object) {
866
- if (owns(object, name)) {
867
- keys.push(name);
868
- }
869
- }
842
+ var keysWorksWithArguments = Object.keys && (function () {
843
+ return Object.keys(arguments).length === 2;
844
+ }(1, 2));
845
+ if (!Object.keys) {
846
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
847
+ var hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'),
848
+ hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
849
+ dontEnums = [
850
+ "toString",
851
+ "toLocaleString",
852
+ "valueOf",
853
+ "hasOwnProperty",
854
+ "isPrototypeOf",
855
+ "propertyIsEnumerable",
856
+ "constructor"
857
+ ],
858
+ dontEnumsLength = dontEnums.length;
859
+
860
+ Object.keys = function keys(object) {
861
+ var isFn = isFunction(object),
862
+ isArgs = isArguments(object),
863
+ isObject = object !== null && typeof object === 'object',
864
+ isString = isObject && _toString.call(object) === '[object String]';
865
+
866
+ if (!isObject && !isFn && !isArgs) {
867
+ throw new TypeError("Object.keys called on a non-object");
868
+ }
870
869
 
871
- if (hasDontEnumBug) {
872
- for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
873
- var dontEnum = dontEnums[i];
874
- if (owns(object, dontEnum)) {
875
- keys.push(dontEnum);
876
- }
877
- }
878
- }
879
- return keys;
880
- };
870
+ var theKeys = [];
871
+ var skipProto = hasProtoEnumBug && isFn;
872
+ if (isString || isArgs) {
873
+ for (var i = 0; i < object.length; ++i) {
874
+ theKeys.push(String(i));
875
+ }
876
+ } else {
877
+ for (var name in object) {
878
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
879
+ theKeys.push(String(name));
880
+ }
881
+ }
882
+ }
881
883
 
882
- }
884
+ if (hasDontEnumBug) {
885
+ var ctor = object.constructor,
886
+ skipConstructor = ctor && ctor.prototype === object;
887
+ for (var j = 0; j < dontEnumsLength; j++) {
888
+ var dontEnum = dontEnums[j];
889
+ if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
890
+ theKeys.push(dontEnum);
891
+ }
892
+ }
893
+ }
894
+ return theKeys;
895
+ };
896
+ } else if (!keysWorksWithArguments) {
897
+ // Safari 5.0 bug
898
+ var originalKeys = Object.keys;
899
+ Object.keys = function keys(object) {
900
+ if (isArguments(object)) {
901
+ return originalKeys(Array.prototype.slice.call(object));
902
+ } else {
903
+ return originalKeys(object);
904
+ }
905
+ };
906
+ }
883
907
 
884
908
  //
885
909
  // Date
@@ -893,256 +917,263 @@ if (!Object.keys) {
893
917
  // string format defined in 15.9.1.15. All fields are present in the String.
894
918
  // The time zone is always UTC, denoted by the suffix Z. If the time value of
895
919
  // this object is not a finite Number a RangeError exception is thrown.
896
- var negativeDate = -62198755200000,
897
- negativeYearString = "-000001";
898
- if (
899
- !Date.prototype.toISOString ||
900
- (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
901
- ) {
902
- Date.prototype.toISOString = function toISOString() {
903
- var result, length, value, year, month;
904
- if (!isFinite(this)) {
905
- throw new RangeError("Date.prototype.toISOString called on non-finite value.");
906
- }
920
+ var negativeDate = -62198755200000,
921
+ negativeYearString = "-000001";
922
+ if (
923
+ !Date.prototype.toISOString ||
924
+ (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
925
+ ) {
926
+ Date.prototype.toISOString = function toISOString() {
927
+ var result, length, value, year, month;
928
+ if (!isFinite(this)) {
929
+ throw new RangeError("Date.prototype.toISOString called on non-finite value.");
930
+ }
907
931
 
908
- year = this.getUTCFullYear();
909
-
910
- month = this.getUTCMonth();
911
- // see https://github.com/kriskowal/es5-shim/issues/111
912
- year += Math.floor(month / 12);
913
- month = (month % 12 + 12) % 12;
914
-
915
- // the date time string format is specified in 15.9.1.15.
916
- result = [month + 1, this.getUTCDate(),
917
- this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
918
- year = (
919
- (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
920
- ("00000" + Math.abs(year))
921
- .slice(0 <= year && year <= 9999 ? -4 : -6)
922
- );
923
-
924
- length = result.length;
925
- while (length--) {
926
- value = result[length];
927
- // pad months, days, hours, minutes, and seconds to have two
928
- // digits.
929
- if (value < 10) {
930
- result[length] = "0" + value;
931
- }
932
- }
933
- // pad milliseconds to have three digits.
934
- return (
935
- year + "-" + result.slice(0, 2).join("-") +
936
- "T" + result.slice(2).join(":") + "." +
937
- ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
938
- );
939
- };
940
- }
932
+ year = this.getUTCFullYear();
933
+
934
+ month = this.getUTCMonth();
935
+ // see https://github.com/es-shims/es5-shim/issues/111
936
+ year += Math.floor(month / 12);
937
+ month = (month % 12 + 12) % 12;
938
+
939
+ // the date time string format is specified in 15.9.1.15.
940
+ result = [month + 1, this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
941
+ year = (
942
+ (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
943
+ ("00000" + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6)
944
+ );
945
+
946
+ length = result.length;
947
+ while (length--) {
948
+ value = result[length];
949
+ // pad months, days, hours, minutes, and seconds to have two
950
+ // digits.
951
+ if (value < 10) {
952
+ result[length] = "0" + value;
953
+ }
954
+ }
955
+ // pad milliseconds to have three digits.
956
+ return (
957
+ year + "-" + result.slice(0, 2).join("-") +
958
+ "T" + result.slice(2).join(":") + "." +
959
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
960
+ );
961
+ };
962
+ }
941
963
 
942
964
 
943
965
  // ES5 15.9.5.44
944
966
  // http://es5.github.com/#x15.9.5.44
945
967
  // This function provides a String representation of a Date object for use by
946
968
  // JSON.stringify (15.12.3).
947
- var dateToJSONIsSupported = false;
948
- try {
949
- dateToJSONIsSupported = (
950
- Date.prototype.toJSON &&
951
- new Date(NaN).toJSON() === null &&
952
- new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
953
- Date.prototype.toJSON.call({ // generic
954
- toISOString: function () {
955
- return true;
956
- }
957
- })
958
- );
959
- } catch (e) {
960
- }
961
- if (!dateToJSONIsSupported) {
962
- Date.prototype.toJSON = function toJSON(key) {
963
- // When the toJSON method is called with argument key, the following
964
- // steps are taken:
965
-
966
- // 1. Let O be the result of calling ToObject, giving it the this
967
- // value as its argument.
968
- // 2. Let tv be toPrimitive(O, hint Number).
969
- var o = Object(this),
970
- tv = toPrimitive(o),
971
- toISO;
972
- // 3. If tv is a Number and is not finite, return null.
973
- if (typeof tv === "number" && !isFinite(tv)) {
974
- return null;
975
- }
976
- // 4. Let toISO be the result of calling the [[Get]] internal method of
977
- // O with argument "toISOString".
978
- toISO = o.toISOString;
979
- // 5. If IsCallable(toISO) is false, throw a TypeError exception.
980
- if (typeof toISO != "function") {
981
- throw new TypeError("toISOString property is not callable");
982
- }
983
- // 6. Return the result of calling the [[Call]] internal method of
984
- // toISO with O as the this value and an empty argument list.
985
- return toISO.call(o);
986
-
987
- // NOTE 1 The argument is ignored.
988
-
989
- // NOTE 2 The toJSON function is intentionally generic; it does not
990
- // require that its this value be a Date object. Therefore, it can be
991
- // transferred to other kinds of objects for use as a method. However,
992
- // it does require that any such object have a toISOString method. An
993
- // object is free to use the argument key to filter its
994
- // stringification.
995
- };
996
- }
969
+ var dateToJSONIsSupported = false;
970
+ try {
971
+ dateToJSONIsSupported = (
972
+ Date.prototype.toJSON &&
973
+ new Date(NaN).toJSON() === null &&
974
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
975
+ Date.prototype.toJSON.call({ // generic
976
+ toISOString: function () {
977
+ return true;
978
+ }
979
+ })
980
+ );
981
+ } catch (e) {
982
+ }
983
+ if (!dateToJSONIsSupported) {
984
+ Date.prototype.toJSON = function toJSON(key) {
985
+ // When the toJSON method is called with argument key, the following
986
+ // steps are taken:
987
+
988
+ // 1. Let O be the result of calling ToObject, giving it the this
989
+ // value as its argument.
990
+ // 2. Let tv be toPrimitive(O, hint Number).
991
+ var o = Object(this),
992
+ tv = toPrimitive(o),
993
+ toISO;
994
+ // 3. If tv is a Number and is not finite, return null.
995
+ if (typeof tv === "number" && !isFinite(tv)) {
996
+ return null;
997
+ }
998
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
999
+ // O with argument "toISOString".
1000
+ toISO = o.toISOString;
1001
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1002
+ if (typeof toISO !== "function") {
1003
+ throw new TypeError("toISOString property is not callable");
1004
+ }
1005
+ // 6. Return the result of calling the [[Call]] internal method of
1006
+ // toISO with O as the this value and an empty argument list.
1007
+ return toISO.call(o);
1008
+
1009
+ // NOTE 1 The argument is ignored.
1010
+
1011
+ // NOTE 2 The toJSON function is intentionally generic; it does not
1012
+ // require that its this value be a Date object. Therefore, it can be
1013
+ // transferred to other kinds of objects for use as a method. However,
1014
+ // it does require that any such object have a toISOString method. An
1015
+ // object is free to use the argument key to filter its
1016
+ // stringification.
1017
+ };
1018
+ }
997
1019
 
998
1020
  // ES5 15.9.4.2
999
1021
  // http://es5.github.com/#x15.9.4.2
1000
1022
  // based on work shared by Daniel Friesen (dantman)
1001
1023
  // http://gist.github.com/303249
1002
- if (!Date.parse || "Date.parse is buggy") {
1003
- // XXX global assignment won't work in embeddings that use
1004
- // an alternate object for the context.
1005
- Date = (function(NativeDate) {
1006
-
1007
- // Date.length === 7
1008
- function Date(Y, M, D, h, m, s, ms) {
1009
- var length = arguments.length;
1010
- if (this instanceof NativeDate) {
1011
- var date = length == 1 && String(Y) === Y ? // isString(Y)
1012
- // We explicitly pass it through parse:
1013
- new NativeDate(Date.parse(Y)) :
1014
- // We have to manually make calls depending on argument
1015
- // length here
1016
- length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
1017
- length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
1018
- length >= 5 ? new NativeDate(Y, M, D, h, m) :
1019
- length >= 4 ? new NativeDate(Y, M, D, h) :
1020
- length >= 3 ? new NativeDate(Y, M, D) :
1021
- length >= 2 ? new NativeDate(Y, M) :
1022
- length >= 1 ? new NativeDate(Y) :
1023
- new NativeDate();
1024
- // Prevent mixups with unfixed Date object
1025
- date.constructor = Date;
1026
- return date;
1027
- }
1028
- return NativeDate.apply(this, arguments);
1029
- };
1024
+ var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
1025
+ var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z'));
1026
+ var doesNotParseY2KNewYear = isNaN(Date.parse("2000-01-01T00:00:00.000Z"));
1027
+ if (!Date.parse || doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
1028
+ // XXX global assignment won't work in embeddings that use
1029
+ // an alternate object for the context.
1030
+ Date = (function (NativeDate) {
1031
+
1032
+ // Date.length === 7
1033
+ function Date(Y, M, D, h, m, s, ms) {
1034
+ var length = arguments.length;
1035
+ if (this instanceof NativeDate) {
1036
+ var date = length === 1 && String(Y) === Y ? // isString(Y)
1037
+ // We explicitly pass it through parse:
1038
+ new NativeDate(Date.parse(Y)) :
1039
+ // We have to manually make calls depending on argument
1040
+ // length here
1041
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
1042
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
1043
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
1044
+ length >= 4 ? new NativeDate(Y, M, D, h) :
1045
+ length >= 3 ? new NativeDate(Y, M, D) :
1046
+ length >= 2 ? new NativeDate(Y, M) :
1047
+ length >= 1 ? new NativeDate(Y) :
1048
+ new NativeDate();
1049
+ // Prevent mixups with unfixed Date object
1050
+ date.constructor = Date;
1051
+ return date;
1052
+ }
1053
+ return NativeDate.apply(this, arguments);
1054
+ }
1030
1055
 
1031
- // 15.9.1.15 Date Time String Format.
1032
- var isoDateExpression = new RegExp("^" +
1033
- "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
1034
- // 6-digit extended year
1035
- "(?:-(\\d{2})" + // optional month capture
1036
- "(?:-(\\d{2})" + // optional day capture
1037
- "(?:" + // capture hours:minutes:seconds.milliseconds
1038
- "T(\\d{2})" + // hours capture
1039
- ":(\\d{2})" + // minutes capture
1040
- "(?:" + // optional :seconds.milliseconds
1041
- ":(\\d{2})" + // seconds capture
1042
- "(?:(\\.\\d{1,}))?" + // milliseconds capture
1043
- ")?" +
1044
- "(" + // capture UTC offset component
1045
- "Z|" + // UTC capture
1046
- "(?:" + // offset specifier +/-hours:minutes
1047
- "([-+])" + // sign capture
1048
- "(\\d{2})" + // hours offset capture
1049
- ":(\\d{2})" + // minutes offset capture
1050
- ")" +
1051
- ")?)?)?)?" +
1052
- "$");
1053
-
1054
- var months = [
1055
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
1056
- ];
1057
-
1058
- function dayFromMonth(year, month) {
1059
- var t = month > 1 ? 1 : 0;
1060
- return (
1061
- months[month] +
1062
- Math.floor((year - 1969 + t) / 4) -
1063
- Math.floor((year - 1901 + t) / 100) +
1064
- Math.floor((year - 1601 + t) / 400) +
1065
- 365 * (year - 1970)
1066
- );
1067
- }
1056
+ // 15.9.1.15 Date Time String Format.
1057
+ var isoDateExpression = new RegExp("^" +
1058
+ "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
1059
+ // 6-digit extended year
1060
+ "(?:-(\\d{2})" + // optional month capture
1061
+ "(?:-(\\d{2})" + // optional day capture
1062
+ "(?:" + // capture hours:minutes:seconds.milliseconds
1063
+ "T(\\d{2})" + // hours capture
1064
+ ":(\\d{2})" + // minutes capture
1065
+ "(?:" + // optional :seconds.milliseconds
1066
+ ":(\\d{2})" + // seconds capture
1067
+ "(?:(\\.\\d{1,}))?" + // milliseconds capture
1068
+ ")?" +
1069
+ "(" + // capture UTC offset component
1070
+ "Z|" + // UTC capture
1071
+ "(?:" + // offset specifier +/-hours:minutes
1072
+ "([-+])" + // sign capture
1073
+ "(\\d{2})" + // hours offset capture
1074
+ ":(\\d{2})" + // minutes offset capture
1075
+ ")" +
1076
+ ")?)?)?)?" +
1077
+ "$");
1078
+
1079
+ var months = [
1080
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
1081
+ ];
1082
+
1083
+ function dayFromMonth(year, month) {
1084
+ var t = month > 1 ? 1 : 0;
1085
+ return (
1086
+ months[month] +
1087
+ Math.floor((year - 1969 + t) / 4) -
1088
+ Math.floor((year - 1901 + t) / 100) +
1089
+ Math.floor((year - 1601 + t) / 400) +
1090
+ 365 * (year - 1970)
1091
+ );
1092
+ }
1068
1093
 
1069
- // Copy any custom methods a 3rd party library may have added
1070
- for (var key in NativeDate) {
1071
- Date[key] = NativeDate[key];
1072
- }
1094
+ function toUTC(t) {
1095
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
1096
+ }
1073
1097
 
1074
- // Copy "native" methods explicitly; they may be non-enumerable
1075
- Date.now = NativeDate.now;
1076
- Date.UTC = NativeDate.UTC;
1077
- Date.prototype = NativeDate.prototype;
1078
- Date.prototype.constructor = Date;
1079
-
1080
- // Upgrade Date.parse to handle simplified ISO 8601 strings
1081
- Date.parse = function parse(string) {
1082
- var match = isoDateExpression.exec(string);
1083
- if (match) {
1084
- // parse months, days, hours, minutes, seconds, and milliseconds
1085
- // provide default values if necessary
1086
- // parse the UTC offset component
1087
- var year = Number(match[1]),
1088
- month = Number(match[2] || 1) - 1,
1089
- day = Number(match[3] || 1) - 1,
1090
- hour = Number(match[4] || 0),
1091
- minute = Number(match[5] || 0),
1092
- second = Number(match[6] || 0),
1093
- millisecond = Math.floor(Number(match[7] || 0) * 1000),
1094
- // When time zone is missed, local offset should be used
1095
- // (ES 5.1 bug)
1096
- // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1097
- offset = !match[4] || match[8] ?
1098
- 0 : Number(new NativeDate(1970, 0)),
1099
- signOffset = match[9] === "-" ? 1 : -1,
1100
- hourOffset = Number(match[10] || 0),
1101
- minuteOffset = Number(match[11] || 0),
1102
- result;
1103
- if (
1104
- hour < (
1105
- minute > 0 || second > 0 || millisecond > 0 ?
1106
- 24 : 25
1107
- ) &&
1108
- minute < 60 && second < 60 && millisecond < 1000 &&
1109
- month > -1 && month < 12 && hourOffset < 24 &&
1110
- minuteOffset < 60 && // detect invalid offsets
1111
- day > -1 &&
1112
- day < (
1113
- dayFromMonth(year, month + 1) -
1114
- dayFromMonth(year, month)
1115
- )
1116
- ) {
1117
- result = (
1118
- (dayFromMonth(year, month) + day) * 24 +
1119
- hour +
1120
- hourOffset * signOffset
1121
- ) * 60;
1122
- result = (
1123
- (result + minute + minuteOffset * signOffset) * 60 +
1124
- second
1125
- ) * 1000 + millisecond + offset;
1126
- if (-8.64e15 <= result && result <= 8.64e15) {
1127
- return result;
1128
- }
1129
- }
1130
- return NaN;
1131
- }
1132
- return NativeDate.parse.apply(this, arguments);
1133
- };
1098
+ // Copy any custom methods a 3rd party library may have added
1099
+ for (var key in NativeDate) {
1100
+ Date[key] = NativeDate[key];
1101
+ }
1134
1102
 
1135
- return Date;
1136
- })(Date);
1137
- }
1103
+ // Copy "native" methods explicitly; they may be non-enumerable
1104
+ Date.now = NativeDate.now;
1105
+ Date.UTC = NativeDate.UTC;
1106
+ Date.prototype = NativeDate.prototype;
1107
+ Date.prototype.constructor = Date;
1108
+
1109
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
1110
+ Date.parse = function parse(string) {
1111
+ var match = isoDateExpression.exec(string);
1112
+ if (match) {
1113
+ // parse months, days, hours, minutes, seconds, and milliseconds
1114
+ // provide default values if necessary
1115
+ // parse the UTC offset component
1116
+ var year = Number(match[1]),
1117
+ month = Number(match[2] || 1) - 1,
1118
+ day = Number(match[3] || 1) - 1,
1119
+ hour = Number(match[4] || 0),
1120
+ minute = Number(match[5] || 0),
1121
+ second = Number(match[6] || 0),
1122
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
1123
+ // When time zone is missed, local offset should be used
1124
+ // (ES 5.1 bug)
1125
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1126
+ isLocalTime = Boolean(match[4] && !match[8]),
1127
+ signOffset = match[9] === "-" ? 1 : -1,
1128
+ hourOffset = Number(match[10] || 0),
1129
+ minuteOffset = Number(match[11] || 0),
1130
+ result;
1131
+ if (
1132
+ hour < (
1133
+ minute > 0 || second > 0 || millisecond > 0 ?
1134
+ 24 : 25
1135
+ ) &&
1136
+ minute < 60 && second < 60 && millisecond < 1000 &&
1137
+ month > -1 && month < 12 && hourOffset < 24 &&
1138
+ minuteOffset < 60 && // detect invalid offsets
1139
+ day > -1 &&
1140
+ day < (
1141
+ dayFromMonth(year, month + 1) -
1142
+ dayFromMonth(year, month)
1143
+ )
1144
+ ) {
1145
+ result = (
1146
+ (dayFromMonth(year, month) + day) * 24 +
1147
+ hour +
1148
+ hourOffset * signOffset
1149
+ ) * 60;
1150
+ result = (
1151
+ (result + minute + minuteOffset * signOffset) * 60 +
1152
+ second
1153
+ ) * 1000 + millisecond;
1154
+ if (isLocalTime) {
1155
+ result = toUTC(result);
1156
+ }
1157
+ if (-8.64e15 <= result && result <= 8.64e15) {
1158
+ return result;
1159
+ }
1160
+ }
1161
+ return NaN;
1162
+ }
1163
+ return NativeDate.parse.apply(this, arguments);
1164
+ };
1165
+
1166
+ return Date;
1167
+ })(Date);
1168
+ }
1138
1169
 
1139
1170
  // ES5 15.9.4.4
1140
1171
  // http://es5.github.com/#x15.9.4.4
1141
- if (!Date.now) {
1142
- Date.now = function now() {
1143
- return new Date().getTime();
1144
- };
1145
- }
1172
+ if (!Date.now) {
1173
+ Date.now = function now() {
1174
+ return new Date().getTime();
1175
+ };
1176
+ }
1146
1177
 
1147
1178
 
1148
1179
  //
@@ -1152,152 +1183,152 @@ if (!Date.now) {
1152
1183
 
1153
1184
  // ES5.1 15.7.4.5
1154
1185
  // http://es5.github.com/#x15.7.4.5
1155
- if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") {
1156
- // Hide these variables and functions
1157
- (function () {
1158
- var base, size, data, i;
1159
-
1160
- base = 1e7;
1161
- size = 6;
1162
- data = [0, 0, 0, 0, 0, 0];
1163
-
1164
- function multiply(n, c) {
1165
- var i = -1;
1166
- while (++i < size) {
1167
- c += n * data[i];
1168
- data[i] = c % base;
1169
- c = Math.floor(c / base);
1170
- }
1171
- }
1186
+ if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") {
1187
+ // Hide these variables and functions
1188
+ (function () {
1189
+ var base, size, data, i;
1190
+
1191
+ base = 1e7;
1192
+ size = 6;
1193
+ data = [0, 0, 0, 0, 0, 0];
1194
+
1195
+ function multiply(n, c) {
1196
+ var i = -1;
1197
+ while (++i < size) {
1198
+ c += n * data[i];
1199
+ data[i] = c % base;
1200
+ c = Math.floor(c / base);
1201
+ }
1202
+ }
1172
1203
 
1173
- function divide(n) {
1174
- var i = size, c = 0;
1175
- while (--i >= 0) {
1176
- c += data[i];
1177
- data[i] = Math.floor(c / n);
1178
- c = (c % n) * base;
1179
- }
1180
- }
1204
+ function divide(n) {
1205
+ var i = size, c = 0;
1206
+ while (--i >= 0) {
1207
+ c += data[i];
1208
+ data[i] = Math.floor(c / n);
1209
+ c = (c % n) * base;
1210
+ }
1211
+ }
1181
1212
 
1182
- function toString() {
1183
- var i = size;
1184
- var s = '';
1185
- while (--i >= 0) {
1186
- if (s !== '' || i === 0 || data[i] !== 0) {
1187
- var t = String(data[i]);
1188
- if (s === '') {
1189
- s = t;
1190
- } else {
1191
- s += '0000000'.slice(0, 7 - t.length) + t;
1192
- }
1193
- }
1194
- }
1195
- return s;
1196
- }
1213
+ function numToString() {
1214
+ var i = size;
1215
+ var s = '';
1216
+ while (--i >= 0) {
1217
+ if (s !== '' || i === 0 || data[i] !== 0) {
1218
+ var t = String(data[i]);
1219
+ if (s === '') {
1220
+ s = t;
1221
+ } else {
1222
+ s += '0000000'.slice(0, 7 - t.length) + t;
1223
+ }
1224
+ }
1225
+ }
1226
+ return s;
1227
+ }
1197
1228
 
1198
- function pow(x, n, acc) {
1199
- return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1200
- }
1229
+ function pow(x, n, acc) {
1230
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1231
+ }
1201
1232
 
1202
- function log(x) {
1203
- var n = 0;
1204
- while (x >= 4096) {
1205
- n += 12;
1206
- x /= 4096;
1207
- }
1208
- while (x >= 2) {
1209
- n += 1;
1210
- x /= 2;
1211
- }
1212
- return n;
1213
- }
1233
+ function log(x) {
1234
+ var n = 0;
1235
+ while (x >= 4096) {
1236
+ n += 12;
1237
+ x /= 4096;
1238
+ }
1239
+ while (x >= 2) {
1240
+ n += 1;
1241
+ x /= 2;
1242
+ }
1243
+ return n;
1244
+ }
1214
1245
 
1215
- Number.prototype.toFixed = function (fractionDigits) {
1216
- var f, x, s, m, e, z, j, k;
1217
-
1218
- // Test for NaN and round fractionDigits down
1219
- f = Number(fractionDigits);
1220
- f = f !== f ? 0 : Math.floor(f);
1221
-
1222
- if (f < 0 || f > 20) {
1223
- throw new RangeError("Number.toFixed called with invalid number of decimals");
1224
- }
1225
-
1226
- x = Number(this);
1227
-
1228
- // Test for NaN
1229
- if (x !== x) {
1230
- return "NaN";
1231
- }
1232
-
1233
- // If it is too big or small, return the string value of the number
1234
- if (x <= -1e21 || x >= 1e21) {
1235
- return String(x);
1236
- }
1237
-
1238
- s = "";
1239
-
1240
- if (x < 0) {
1241
- s = "-";
1242
- x = -x;
1243
- }
1244
-
1245
- m = "0";
1246
-
1247
- if (x > 1e-21) {
1248
- // 1e-21 < x < 1e21
1249
- // -70 < log2(x) < 70
1250
- e = log(x * pow(2, 69, 1)) - 69;
1251
- z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
1252
- z *= 0x10000000000000; // Math.pow(2, 52);
1253
- e = 52 - e;
1254
-
1255
- // -18 < e < 122
1256
- // x = z / 2 ^ e
1257
- if (e > 0) {
1258
- multiply(0, z);
1259
- j = f;
1260
-
1261
- while (j >= 7) {
1262
- multiply(1e7, 0);
1263
- j -= 7;
1264
- }
1265
-
1266
- multiply(pow(10, j, 1), 0);
1267
- j = e - 1;
1268
-
1269
- while (j >= 23) {
1270
- divide(1 << 23);
1271
- j -= 23;
1272
- }
1273
-
1274
- divide(1 << j);
1275
- multiply(1, 1);
1276
- divide(2);
1277
- m = toString();
1278
- } else {
1279
- multiply(0, z);
1280
- multiply(1 << (-e), 0);
1281
- m = toString() + '0.00000000000000000000'.slice(2, 2 + f);
1282
- }
1283
- }
1284
-
1285
- if (f > 0) {
1286
- k = m.length;
1287
-
1288
- if (k <= f) {
1289
- m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1290
- } else {
1291
- m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1292
- }
1293
- } else {
1294
- m = s + m;
1295
- }
1296
-
1297
- return m;
1298
- }
1299
- }());
1300
- }
1246
+ Number.prototype.toFixed = function toFixed(fractionDigits) {
1247
+ var f, x, s, m, e, z, j, k;
1248
+
1249
+ // Test for NaN and round fractionDigits down
1250
+ f = Number(fractionDigits);
1251
+ f = f !== f ? 0 : Math.floor(f);
1252
+
1253
+ if (f < 0 || f > 20) {
1254
+ throw new RangeError("Number.toFixed called with invalid number of decimals");
1255
+ }
1256
+
1257
+ x = Number(this);
1258
+
1259
+ // Test for NaN
1260
+ if (x !== x) {
1261
+ return "NaN";
1262
+ }
1263
+
1264
+ // If it is too big or small, return the string value of the number
1265
+ if (x <= -1e21 || x >= 1e21) {
1266
+ return String(x);
1267
+ }
1268
+
1269
+ s = "";
1270
+
1271
+ if (x < 0) {
1272
+ s = "-";
1273
+ x = -x;
1274
+ }
1275
+
1276
+ m = "0";
1277
+
1278
+ if (x > 1e-21) {
1279
+ // 1e-21 < x < 1e21
1280
+ // -70 < log2(x) < 70
1281
+ e = log(x * pow(2, 69, 1)) - 69;
1282
+ z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
1283
+ z *= 0x10000000000000; // Math.pow(2, 52);
1284
+ e = 52 - e;
1285
+
1286
+ // -18 < e < 122
1287
+ // x = z / 2 ^ e
1288
+ if (e > 0) {
1289
+ multiply(0, z);
1290
+ j = f;
1291
+
1292
+ while (j >= 7) {
1293
+ multiply(1e7, 0);
1294
+ j -= 7;
1295
+ }
1296
+
1297
+ multiply(pow(10, j, 1), 0);
1298
+ j = e - 1;
1299
+
1300
+ while (j >= 23) {
1301
+ divide(1 << 23);
1302
+ j -= 23;
1303
+ }
1304
+
1305
+ divide(1 << j);
1306
+ multiply(1, 1);
1307
+ divide(2);
1308
+ m = numToString();
1309
+ } else {
1310
+ multiply(0, z);
1311
+ multiply(1 << (-e), 0);
1312
+ m = numToString() + '0.00000000000000000000'.slice(2, 2 + f);
1313
+ }
1314
+ }
1315
+
1316
+ if (f > 0) {
1317
+ k = m.length;
1318
+
1319
+ if (k <= f) {
1320
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1321
+ } else {
1322
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1323
+ }
1324
+ } else {
1325
+ m = s + m;
1326
+ }
1327
+
1328
+ return m;
1329
+ };
1330
+ }());
1331
+ }
1301
1332
 
1302
1333
 
1303
1334
  //
@@ -1305,7 +1336,6 @@ if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFix
1305
1336
  // ======
1306
1337
  //
1307
1338
 
1308
-
1309
1339
  // ES5 15.5.4.14
1310
1340
  // http://es5.github.com/#x15.5.4.14
1311
1341
 
@@ -1314,97 +1344,99 @@ if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFix
1314
1344
  // do not perform the split correctly under obscure conditions.
1315
1345
  // See http://blog.stevenlevithan.com/archives/cross-browser-split
1316
1346
  // I've tested in many browsers and this seems to cover the deviant ones:
1317
- // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1318
- // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1319
- // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1320
- // [undefined, "t", undefined, "e", ...]
1321
- // ''.split(/.?/) should be [], not [""]
1322
- // '.'.split(/()()/) should be ["."], not ["", "", "."]
1323
-
1324
- var string_split = String.prototype.split;
1325
- if (
1326
- 'ab'.split(/(?:ab)*/).length !== 2 ||
1327
- '.'.split(/(.?)(.?)/).length !== 4 ||
1328
- 'tesst'.split(/(s)*/)[1] === "t" ||
1329
- ''.split(/.?/).length === 0 ||
1330
- '.'.split(/()()/).length > 1
1331
- ) {
1332
- (function () {
1333
- var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1334
-
1335
- String.prototype.split = function (separator, limit) {
1336
- var string = this;
1337
- if (separator === void 0 && limit === 0)
1338
- return [];
1339
-
1340
- // If `separator` is not a regex, use native split
1341
- if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
1342
- return string_split.apply(this, arguments);
1343
- }
1344
-
1345
- var output = [],
1346
- flags = (separator.ignoreCase ? "i" : "") +
1347
- (separator.multiline ? "m" : "") +
1348
- (separator.extended ? "x" : "") + // Proposed for ES6
1349
- (separator.sticky ? "y" : ""), // Firefox 3+
1350
- lastLastIndex = 0,
1351
- // Make `global` and avoid `lastIndex` issues by working with a copy
1352
- separator = new RegExp(separator.source, flags + "g"),
1353
- separator2, match, lastIndex, lastLength;
1354
- string += ""; // Type-convert
1355
- if (!compliantExecNpcg) {
1356
- // Doesn't need flags gy, but they don't hurt
1357
- separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1358
- }
1359
- /* Values for `limit`, per the spec:
1360
- * If undefined: 4294967295 // Math.pow(2, 32) - 1
1361
- * If 0, Infinity, or NaN: 0
1362
- * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1363
- * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1364
- * If other: Type-convert, then use the above rules
1365
- */
1366
- limit = limit === void 0 ?
1367
- -1 >>> 0 : // Math.pow(2, 32) - 1
1368
- limit >>> 0; // ToUint32(limit)
1369
- while (match = separator.exec(string)) {
1370
- // `separator.lastIndex` is not reliable cross-browser
1371
- lastIndex = match.index + match[0].length;
1372
- if (lastIndex > lastLastIndex) {
1373
- output.push(string.slice(lastLastIndex, match.index));
1374
- // Fix browsers whose `exec` methods don't consistently return `undefined` for
1375
- // nonparticipating capturing groups
1376
- if (!compliantExecNpcg && match.length > 1) {
1377
- match[0].replace(separator2, function () {
1378
- for (var i = 1; i < arguments.length - 2; i++) {
1379
- if (arguments[i] === void 0) {
1380
- match[i] = void 0;
1381
- }
1382
- }
1383
- });
1384
- }
1385
- if (match.length > 1 && match.index < string.length) {
1386
- Array.prototype.push.apply(output, match.slice(1));
1387
- }
1388
- lastLength = match[0].length;
1389
- lastLastIndex = lastIndex;
1390
- if (output.length >= limit) {
1391
- break;
1392
- }
1393
- }
1394
- if (separator.lastIndex === match.index) {
1395
- separator.lastIndex++; // Avoid an infinite loop
1396
- }
1397
- }
1398
- if (lastLastIndex === string.length) {
1399
- if (lastLength || !separator.test("")) {
1400
- output.push("");
1401
- }
1402
- } else {
1403
- output.push(string.slice(lastLastIndex));
1404
- }
1405
- return output.length > limit ? output.slice(0, limit) : output;
1406
- };
1407
- }());
1347
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1348
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1349
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1350
+ // [undefined, "t", undefined, "e", ...]
1351
+ // ''.split(/.?/) should be [], not [""]
1352
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1353
+
1354
+ var string_split = String.prototype.split;
1355
+ if (
1356
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1357
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1358
+ 'tesst'.split(/(s)*/)[1] === "t" ||
1359
+ 'test'.split(/(?:)/, -1).length !== 4 ||
1360
+ ''.split(/.?/).length ||
1361
+ '.'.split(/()()/).length > 1
1362
+ ) {
1363
+ (function () {
1364
+ var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1365
+
1366
+ String.prototype.split = function (separator, limit) {
1367
+ var string = this;
1368
+ if (separator === void 0 && limit === 0) {
1369
+ return [];
1370
+ }
1371
+
1372
+ // If `separator` is not a regex, use native split
1373
+ if (_toString.call(separator) !== "[object RegExp]") {
1374
+ return string_split.call(this, separator, limit);
1375
+ }
1376
+
1377
+ var output = [],
1378
+ flags = (separator.ignoreCase ? "i" : "") +
1379
+ (separator.multiline ? "m" : "") +
1380
+ (separator.extended ? "x" : "") + // Proposed for ES6
1381
+ (separator.sticky ? "y" : ""), // Firefox 3+
1382
+ lastLastIndex = 0,
1383
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1384
+ separator2, match, lastIndex, lastLength;
1385
+ separator = new RegExp(separator.source, flags + "g");
1386
+ string += ""; // Type-convert
1387
+ if (!compliantExecNpcg) {
1388
+ // Doesn't need flags gy, but they don't hurt
1389
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1390
+ }
1391
+ /* Values for `limit`, per the spec:
1392
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1393
+ * If 0, Infinity, or NaN: 0
1394
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1395
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1396
+ * If other: Type-convert, then use the above rules
1397
+ */
1398
+ limit = limit === void 0 ?
1399
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1400
+ ToUint32(limit);
1401
+ while (match = separator.exec(string)) {
1402
+ // `separator.lastIndex` is not reliable cross-browser
1403
+ lastIndex = match.index + match[0].length;
1404
+ if (lastIndex > lastLastIndex) {
1405
+ output.push(string.slice(lastLastIndex, match.index));
1406
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1407
+ // nonparticipating capturing groups
1408
+ if (!compliantExecNpcg && match.length > 1) {
1409
+ match[0].replace(separator2, function () {
1410
+ for (var i = 1; i < arguments.length - 2; i++) {
1411
+ if (arguments[i] === void 0) {
1412
+ match[i] = void 0;
1413
+ }
1414
+ }
1415
+ });
1416
+ }
1417
+ if (match.length > 1 && match.index < string.length) {
1418
+ Array.prototype.push.apply(output, match.slice(1));
1419
+ }
1420
+ lastLength = match[0].length;
1421
+ lastLastIndex = lastIndex;
1422
+ if (output.length >= limit) {
1423
+ break;
1424
+ }
1425
+ }
1426
+ if (separator.lastIndex === match.index) {
1427
+ separator.lastIndex++; // Avoid an infinite loop
1428
+ }
1429
+ }
1430
+ if (lastLastIndex === string.length) {
1431
+ if (lastLength || !separator.test("")) {
1432
+ output.push("");
1433
+ }
1434
+ } else {
1435
+ output.push(string.slice(lastLastIndex));
1436
+ }
1437
+ return output.length > limit ? output.slice(0, limit) : output;
1438
+ };
1439
+ }());
1408
1440
 
1409
1441
  // [bugfix, chrome]
1410
1442
  // If separator is undefined, then the result array contains just one String,
@@ -1412,56 +1444,100 @@ if (
1412
1444
  // then the output array is truncated so that it contains no more than limit
1413
1445
  // elements.
1414
1446
  // "0".split(undefined, 0) -> []
1415
- } else if ("0".split(void 0, 0).length) {
1416
- String.prototype.split = function(separator, limit) {
1417
- if (separator === void 0 && limit === 0) return [];
1418
- return string_split.apply(this, arguments);
1419
- }
1420
- }
1447
+ } else if ("0".split(void 0, 0).length) {
1448
+ String.prototype.split = function split(separator, limit) {
1449
+ if (separator === void 0 && limit === 0) { return []; }
1450
+ return string_split.call(this, separator, limit);
1451
+ };
1452
+ }
1421
1453
 
1454
+ var str_replace = String.prototype.replace;
1455
+ var replaceReportsGroupsCorrectly = (function () {
1456
+ var groups = [];
1457
+ 'x'.replace(/x(.)?/g, function (match, group) {
1458
+ groups.push(group);
1459
+ });
1460
+ return groups.length === 1 && typeof groups[0] === 'undefined';
1461
+ }());
1462
+
1463
+ if (!replaceReportsGroupsCorrectly) {
1464
+ String.prototype.replace = function replace(searchValue, replaceValue) {
1465
+ var isFn = isFunction(replaceValue);
1466
+ var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
1467
+ if (!isFn || !hasCapturingGroups) {
1468
+ return str_replace.call(this, searchValue, replaceValue);
1469
+ } else {
1470
+ var wrappedReplaceValue = function (match) {
1471
+ var length = arguments.length;
1472
+ var originalLastIndex = searchValue.lastIndex;
1473
+ searchValue.lastIndex = 0;
1474
+ var args = searchValue.exec(match);
1475
+ searchValue.lastIndex = originalLastIndex;
1476
+ args.push(arguments[length - 2], arguments[length - 1]);
1477
+ return replaceValue.apply(this, args);
1478
+ };
1479
+ return str_replace.call(this, searchValue, wrappedReplaceValue);
1480
+ }
1481
+ };
1482
+ }
1422
1483
 
1423
1484
  // ECMA-262, 3rd B.2.3
1424
- // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
1485
+ // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
1425
1486
  // non-normative section suggesting uniform semantics and it should be
1426
1487
  // normalized across all browsers
1427
1488
  // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1428
- if("".substr && "0b".substr(-1) !== "b") {
1429
- var string_substr = String.prototype.substr;
1430
- /**
1431
- * Get the substring of a string
1432
- * @param {integer} start where to start the substring
1433
- * @param {integer} length how many characters to return
1434
- * @return {string}
1435
- */
1436
- String.prototype.substr = function(start, length) {
1437
- return string_substr.call(
1438
- this,
1439
- start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
1440
- length
1441
- );
1442
- }
1443
- }
1489
+ if ("".substr && "0b".substr(-1) !== "b") {
1490
+ var string_substr = String.prototype.substr;
1491
+ /**
1492
+ * Get the substring of a string
1493
+ * @param {integer} start where to start the substring
1494
+ * @param {integer} length how many characters to return
1495
+ * @return {string}
1496
+ */
1497
+ String.prototype.substr = function substr(start, length) {
1498
+ return string_substr.call(
1499
+ this,
1500
+ start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
1501
+ length
1502
+ );
1503
+ };
1504
+ }
1444
1505
 
1445
1506
  // ES5 15.5.4.20
1446
- // http://es5.github.com/#x15.5.4.20
1447
- var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1448
- "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1449
- "\u2029\uFEFF";
1450
- if (!String.prototype.trim || ws.trim()) {
1451
- // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1452
- // http://perfectionkills.com/whitespace-deviations/
1453
- ws = "[" + ws + "]";
1454
- var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1455
- trimEndRegexp = new RegExp(ws + ws + "*$");
1456
- String.prototype.trim = function trim() {
1457
- if (this === void 0 || this === null) {
1458
- throw new TypeError("can't convert "+this+" to object");
1459
- }
1460
- return String(this)
1461
- .replace(trimBeginRegexp, "")
1462
- .replace(trimEndRegexp, "");
1463
- };
1464
- }
1507
+ // whitespace from: http://es5.github.io/#x15.5.4.20
1508
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1509
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1510
+ "\u2029\uFEFF";
1511
+ var zeroWidth = '\u200b';
1512
+ if (!String.prototype.trim || ws.trim() || !zeroWidth.trim()) {
1513
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1514
+ // http://perfectionkills.com/whitespace-deviations/
1515
+ ws = "[" + ws + "]";
1516
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1517
+ trimEndRegexp = new RegExp(ws + ws + "*$");
1518
+ String.prototype.trim = function trim() {
1519
+ if (this === void 0 || this === null) {
1520
+ throw new TypeError("can't convert " + this + " to object");
1521
+ }
1522
+ return String(this)
1523
+ .replace(trimBeginRegexp, "")
1524
+ .replace(trimEndRegexp, "");
1525
+ };
1526
+ }
1527
+
1528
+ // ES-5 15.1.2.2
1529
+ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
1530
+ parseInt = (function (origParseInt) {
1531
+ var hexRegex = /^0[xX]/;
1532
+ return function parseIntES5(str, radix) {
1533
+ str = String(str).trim();
1534
+ if (!Number(radix)) {
1535
+ radix = hexRegex.test(str) ? 16 : 10;
1536
+ }
1537
+ return origParseInt(str, radix);
1538
+ };
1539
+ }(parseInt));
1540
+ }
1465
1541
 
1466
1542
  //
1467
1543
  // Util
@@ -1472,57 +1548,61 @@ if (!String.prototype.trim || ws.trim()) {
1472
1548
  // http://es5.github.com/#x9.4
1473
1549
  // http://jsperf.com/to-integer
1474
1550
 
1475
- function toInteger(n) {
1476
- n = +n;
1477
- if (n !== n) { // isNaN
1478
- n = 0;
1479
- } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
1480
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
1481
- }
1482
- return n;
1483
- }
1551
+ function toInteger(n) {
1552
+ n = +n;
1553
+ if (n !== n) { // isNaN
1554
+ n = 0;
1555
+ } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
1556
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
1557
+ }
1558
+ return n;
1559
+ }
1484
1560
 
1485
- function isPrimitive(input) {
1486
- var type = typeof input;
1487
- return (
1488
- input === null ||
1489
- type === "undefined" ||
1490
- type === "boolean" ||
1491
- type === "number" ||
1492
- type === "string"
1493
- );
1494
- }
1561
+ function isPrimitive(input) {
1562
+ var type = typeof input;
1563
+ return (
1564
+ input === null ||
1565
+ type === "undefined" ||
1566
+ type === "boolean" ||
1567
+ type === "number" ||
1568
+ type === "string"
1569
+ );
1570
+ }
1495
1571
 
1496
- function toPrimitive(input) {
1497
- var val, valueOf, toString;
1498
- if (isPrimitive(input)) {
1499
- return input;
1500
- }
1501
- valueOf = input.valueOf;
1502
- if (typeof valueOf === "function") {
1503
- val = valueOf.call(input);
1504
- if (isPrimitive(val)) {
1505
- return val;
1506
- }
1507
- }
1508
- toString = input.toString;
1509
- if (typeof toString === "function") {
1510
- val = toString.call(input);
1511
- if (isPrimitive(val)) {
1512
- return val;
1513
- }
1514
- }
1515
- throw new TypeError();
1516
- }
1572
+ function toPrimitive(input) {
1573
+ var val, valueOf, toStr;
1574
+ if (isPrimitive(input)) {
1575
+ return input;
1576
+ }
1577
+ valueOf = input.valueOf;
1578
+ if (isFunction(valueOf)) {
1579
+ val = valueOf.call(input);
1580
+ if (isPrimitive(val)) {
1581
+ return val;
1582
+ }
1583
+ }
1584
+ toStr = input.toString;
1585
+ if (isFunction(toStr)) {
1586
+ val = toStr.call(input);
1587
+ if (isPrimitive(val)) {
1588
+ return val;
1589
+ }
1590
+ }
1591
+ throw new TypeError();
1592
+ }
1517
1593
 
1518
1594
  // ES5 9.9
1519
1595
  // http://es5.github.com/#x9.9
1520
- var toObject = function (o) {
1521
- if (o == null) { // this matches both null and undefined
1522
- throw new TypeError("can't convert "+o+" to object");
1523
- }
1524
- return Object(o);
1525
- };
1596
+ var toObject = function (o) {
1597
+ if (o == null) { // this matches both null and undefined
1598
+ throw new TypeError("can't convert " + o + " to object");
1599
+ }
1600
+ return Object(o);
1601
+ };
1602
+
1603
+ var ToUint32 = function ToUint32(x) {
1604
+ return x >>> 0;
1605
+ };
1526
1606
 
1527
1607
  })();
1528
1608
 
@@ -2908,7 +2988,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2908
2988
 
2909
2989
  var wsCfg = webshims.cfg;
2910
2990
  var options = wsCfg.mediaelement;
2911
- var hasSwf;
2991
+ var isIE = navigator.userAgent.indexOf('MSIE') != -1;
2912
2992
  if(!options){
2913
2993
  webshims.error("mediaelement wasn't implemented but loaded");
2914
2994
  return;
@@ -2923,7 +3003,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2923
3003
 
2924
3004
  webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']);
2925
3005
 
2926
- if( !Modernizr.videoBuffered || !supportsLoop || (!Modernizr.mediaDefaultMuted && navigator.userAgent.indexOf('MSIE') != -1 && 'ActiveXObject' in window) ){
3006
+ if( !Modernizr.videoBuffered || !supportsLoop || (!Modernizr.mediaDefaultMuted && isIE && 'ActiveXObject' in window) ){
2927
3007
  webshims.addPolyfill('mediaelement-native-fix', {
2928
3008
  d: ['dom-support']
2929
3009
  });
@@ -2951,7 +3031,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2951
3031
  }
2952
3032
 
2953
3033
  webshims.register('mediaelement-core', function($, webshims, window, document, undefined, options){
2954
- hasSwf = swfmini.hasFlashPlayerVersion('10.0.3');
3034
+ var hasSwf = swfmini.hasFlashPlayerVersion('10.0.3');
2955
3035
  var mediaelement = webshims.mediaelement;
2956
3036
 
2957
3037
  mediaelement.parseRtmp = function(data){
@@ -3013,11 +3093,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3013
3093
  }
3014
3094
  }
3015
3095
  }
3016
-
3017
- if(!src.container){
3018
- $(elem).attr('data-wsrecheckmimetype', '');
3019
- }
3020
-
3096
+
3021
3097
  tmp = elem.attr('media');
3022
3098
  if(tmp){
3023
3099
  src.media = tmp;
@@ -3147,11 +3223,6 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3147
3223
  }
3148
3224
  };
3149
3225
 
3150
-
3151
- $.fn.loadMediaSrc = function(){
3152
- webshims.error('loadMediaSrc was removed.');
3153
- };
3154
-
3155
3226
  mediaelement.swfMimeTypes = ['video/3gpp', 'video/x-msvideo', 'video/quicktime', 'video/x-m4v', 'video/mp4', 'video/m4p', 'video/x-flv', 'video/flv', 'audio/mpeg', 'audio/aac', 'audio/mp4', 'audio/x-m4a', 'audio/m4a', 'audio/mp3', 'audio/x-fla', 'audio/fla', 'youtube/flv', 'video/jarisplayer', 'jarisplayer/jarisplayer', 'video/youtube', 'video/rtmp', 'audio/rtmp'];
3156
3227
 
3157
3228
  mediaelement.canThirdPlaySrces = function(mediaElem, srces){
@@ -3209,7 +3280,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3209
3280
  message = "can't play sources";
3210
3281
  }
3211
3282
  $(elem).pause().data('mediaerror', message);
3212
- webshims.error('mediaelementError: '+ message);
3283
+ webshims.error('mediaelementError: '+ message +'. Run the following line in your console to get more info: webshim.mediaelement.loadDebugger();');
3213
3284
  setTimeout(function(){
3214
3285
  if($(elem).data('mediaerror')){
3215
3286
  $(elem).addClass('media-error').trigger('mediaerror');
@@ -3241,36 +3312,49 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3241
3312
  }
3242
3313
  };
3243
3314
  })();
3244
-
3245
- var stepSources = function(elem, data, useSwf, _srces, _noLoop){
3246
- var ret;
3247
- if(useSwf || (useSwf !== false && data && data.isActive == 'third')){
3248
- ret = mediaelement.canThirdPlaySrces(elem, _srces);
3249
- if(!ret){
3250
- if(_noLoop){
3251
- mediaelement.setError(elem, false);
3252
- } else {
3253
- stepSources(elem, data, false, _srces, true);
3254
- }
3255
- } else {
3256
- handleThird(elem, ret, data);
3315
+
3316
+ var activate = {
3317
+ native: function(elem, src, data){
3318
+ if(data && data.isActive == 'third') {
3319
+ mediaelement.setActive(elem, 'html5', data);
3257
3320
  }
3258
- } else {
3259
- ret = mediaelement.canNativePlaySrces(elem, _srces);
3260
- if(!ret){
3261
- if(_noLoop){
3262
- mediaelement.setError(elem, false);
3263
- if(data && data.isActive == 'third') {
3264
- mediaelement.setActive(elem, 'html5', data);
3265
- }
3266
- } else {
3267
- stepSources(elem, data, true, _srces, true);
3268
- }
3269
- } else if(data && data.isActive == 'third') {
3321
+ },
3322
+ third: handleThird
3323
+ };
3324
+
3325
+ var stepSources = function(elem, data, srces){
3326
+ var i, src;
3327
+ var testOrder = [{test: 'canNativePlaySrces', activate: 'native'}, {test: 'canThirdPlaySrces', activate: 'third'}];
3328
+ if(options.preferFlash || (data && data.isActive == 'third') ){
3329
+ testOrder.reverse();
3330
+ }
3331
+ for(i = 0; i < 2; i++){
3332
+ src = mediaelement[testOrder[i].test](elem, srces);
3333
+ if(src){
3334
+ activate[testOrder[i].activate](elem, src, data);
3335
+ break;
3336
+ }
3337
+ }
3338
+
3339
+ if(!src){
3340
+ mediaelement.setError(elem, false);
3341
+ if(data && data.isActive == 'third') {
3270
3342
  mediaelement.setActive(elem, 'html5', data);
3271
3343
  }
3272
3344
  }
3273
3345
  };
3346
+ var allowedPreload = {'metadata': 1, 'auto': 1, '': 1};
3347
+ var fixPreload = function(elem){
3348
+ var preload, img;
3349
+ if(elem.getAttribute('preload') == 'none'){
3350
+ if(allowedPreload[(preload = $.attr(elem, 'data-preload'))]){
3351
+ $.attr(elem, 'preload', preload);
3352
+ } else if(hasNative && (preload = elem.getAttribute('poster'))){
3353
+ img = document.createElement('img');
3354
+ img.src = preload;
3355
+ }
3356
+ }
3357
+ };
3274
3358
  var stopParent = /^(?:embed|object|datalist)$/i;
3275
3359
  var selectSource = function(elem, data){
3276
3360
  var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
@@ -3286,7 +3370,9 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3286
3370
  if(mediaelement.sortMedia){
3287
3371
  _srces.sort(mediaelement.sortMedia);
3288
3372
  }
3289
- stepSources(elem, data, options.preferFlash || undefined, _srces);
3373
+ fixPreload(elem);
3374
+ stepSources(elem, data, _srces);
3375
+
3290
3376
  };
3291
3377
  mediaelement.selectSource = selectSource;
3292
3378
 
@@ -3297,20 +3383,22 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3297
3383
  setTimeout(function(){
3298
3384
  if( $.prop(e.target, 'paused') || !$.prop(e.target, 'loop') ){return;}
3299
3385
  $(e.target).prop('currentTime', 0).play();
3300
- }, 1);
3386
+ });
3301
3387
 
3302
3388
  });
3303
3389
 
3304
3390
  var handleMedia = false;
3391
+
3305
3392
  var initMediaElements = function(){
3306
3393
  var testFixMedia = function(){
3394
+
3307
3395
  if(webshims.implement(this, 'mediaelement')){
3308
3396
  selectSource(this);
3309
3397
  if(!Modernizr.mediaDefaultMuted && $.attr(this, 'muted') != null){
3310
3398
  $.prop(this, 'muted', true);
3311
3399
  }
3400
+
3312
3401
  }
3313
-
3314
3402
  };
3315
3403
 
3316
3404
  webshims.ready('dom-support', function(){
@@ -3326,6 +3414,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3326
3414
  prop: {
3327
3415
  value: function(){
3328
3416
  var data = webshims.data(this, 'mediaelement');
3417
+
3329
3418
  selectSource(this, data);
3330
3419
  if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
3331
3420
  supLoad.prop._supvalue.apply(this, arguments);
@@ -3337,6 +3426,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3337
3426
  }
3338
3427
  }
3339
3428
  });
3429
+
3340
3430
  nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
3341
3431
  prop: {
3342
3432
  value: function(type){
@@ -3353,6 +3443,9 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3353
3443
  ret = 'maybe';
3354
3444
  }
3355
3445
  }
3446
+ if(!ret && hasYt && type == 'video/youtube'){
3447
+ ret = 'maybe';
3448
+ }
3356
3449
  return ret;
3357
3450
  }
3358
3451
  }
@@ -3402,8 +3495,18 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3402
3495
  });
3403
3496
  }
3404
3497
  };
3405
-
3406
3498
 
3499
+ mediaelement.loadDebugger = function(){
3500
+ webshims.ready('dom-support', function(){
3501
+ webshims.loader.loadScript('mediaelement-debug');
3502
+ });
3503
+ };
3504
+
3505
+ if(({noCombo: 1, media: 1})[webshims.cfg.debug]){
3506
+ $(document).on('mediaerror', function(e){
3507
+ mediaelement.loadDebugger();
3508
+ });
3509
+ }
3407
3510
  //set native implementation ready, before swf api is retested
3408
3511
  if(hasNative){
3409
3512
  webshims.isReady('mediaelement-core', true);
@@ -3574,8 +3677,8 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3574
3677
  data.seeking = false;
3575
3678
  }, 300);
3576
3679
  },
3577
- onConnectionFailed: function(){
3578
- webshims.error('media error');
3680
+ onConnectionFailed: function(jaris, data){
3681
+ mediaelement.setError(data._elem, 'flash connection error');
3579
3682
  },
3580
3683
  onNotBuffering: function(jaris, data){
3581
3684
  setReadyState(3, data);
@@ -4491,6 +4594,13 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4491
4594
 
4492
4595
  if(hasFlash && $.cleanData){
4493
4596
  var oldClean = $.cleanData;
4597
+ var objElem = document.createElement('object');
4598
+ var noRemove = {
4599
+ SetVariable: 1,
4600
+ GetVariable: 1,
4601
+ SetReturnValue: 1,
4602
+ GetReturnValue: 1
4603
+ };
4494
4604
  var flashNames = {
4495
4605
  object: 1,
4496
4606
  OBJECT: 1
@@ -4498,6 +4608,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4498
4608
 
4499
4609
  $.cleanData = function(elems){
4500
4610
  var i, len, prop;
4611
+ var ret = oldClean.apply(this, arguments);
4501
4612
  if(elems && (len = elems.length) && loadedSwf){
4502
4613
 
4503
4614
  for(i = 0; i < len; i++){
@@ -4507,7 +4618,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4507
4618
  elems[i].api_pause();
4508
4619
  if(elems[i].readyState == 4){
4509
4620
  for (prop in elems[i]) {
4510
- if (typeof elems[i][prop] == "function") {
4621
+ if (!noRemove[prop] && !objElem[prop] && typeof elems[i][prop] == "function") {
4511
4622
  elems[i][prop] = null;
4512
4623
  }
4513
4624
  }
@@ -4517,7 +4628,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4517
4628
  }
4518
4629
 
4519
4630
  }
4520
- return oldClean.apply(this, arguments);
4631
+ return ret;
4521
4632
  };
4522
4633
  }
4523
4634
 
@@ -4589,62 +4700,6 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4589
4700
  } else if(!('media' in document.createElement('source'))){
4590
4701
  webshims.reflectProperties('source', ['media']);
4591
4702
  }
4592
- if(options.experimentallyMimetypeCheck){
4593
- (function(){
4594
- var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
4595
- var getMimeType = function(){
4596
- var done;
4597
- var unknown = 'media/unknown please provide mime type';
4598
- var media = $(this);
4599
- var xhrs = [];
4600
- media
4601
- .not('.ws-after-check')
4602
- .find('source')
4603
- [ADDBACK]()
4604
- .filter('[data-wsrecheckmimetype]:not([type])')
4605
- .each(function(){
4606
- var source = $(this).removeAttr('data-wsrecheckmimetype');
4607
- var error = function(){
4608
- source.attr('data-type', unknown);
4609
- };
4610
- try {
4611
- xhrs.push(
4612
- $.ajax({
4613
- type: 'head',
4614
- url: $.attr(this, 'src'),
4615
- success: function(content, status, xhr){
4616
- var mime = xhr.getResponseHeader('Content-Type');
4617
- if(mime){
4618
- done = true;
4619
- }
4620
- source.attr('data-type', mime || unknown);
4621
- },
4622
- error: error
4623
- })
4624
- )
4625
- ;
4626
- } catch(er){
4627
- error();
4628
- }
4629
- })
4630
- ;
4631
- if(xhrs.length){
4632
- media.addClass('ws-after-check');
4633
- $.when.apply($, xhrs).always(function(){
4634
- media.mediaLoad();
4635
- setTimeout(function(){
4636
- media.removeClass('ws-after-check');
4637
- }, 9);
4638
- });
4639
- }
4640
- };
4641
- $('audio.media-error, video.media-error').each(getMimeType);
4642
- $(document).on('mediaerror', function(e){
4643
- getMimeType.call(e.target);
4644
- });
4645
- })();
4646
- }
4647
-
4648
4703
 
4649
4704
  if(hasNative && hasFlash && !options.preferFlash){
4650
4705
  var switchErrors = {
@@ -4653,35 +4708,38 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
4653
4708
  };
4654
4709
  var switchOptions = function(e){
4655
4710
  var media, error, parent;
4656
- if(!options.preferFlash &&
4711
+ if(
4657
4712
  ($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source', parent).last()[0] == e.target)) &&
4658
- (media = $(e.target).closest('audio, video')) && (error = media.prop('error')) && switchErrors[error.code]
4713
+ (media = $(e.target).closest('audio, video')) && !media.is('.nonnative-api-active')
4659
4714
  ){
4660
-
4661
- if(!options.preferFlash){
4715
+ error = media.prop('error');
4716
+ setTimeout(function(){
4662
4717
  if(!media.is('.nonnative-api-active')){
4663
- options.preferFlash = true;
4664
- document.removeEventListener('error', switchOptions, true);
4665
- $('audio, video').each(function(){
4666
- webshims.mediaelement.selectSource(this);
4667
- });
4668
- webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error')+ 'first error: '+ error);
4718
+ if(error && switchErrors[error.code]){
4719
+ options.preferFlash = true;
4720
+ document.removeEventListener('error', switchOptions, true);
4721
+ $('audio, video').each(function(){
4722
+ webshims.mediaelement.selectSource(this);
4723
+ });
4724
+ webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.currentSrc+" Mediaerror: "+ media.prop('error')+ ' error.code: '+ error.code);
4725
+ }
4726
+ webshims.warn('There was a mediaelement error. Run the following line in your console to get more info: webshim.mediaelement.loadDebugger();')
4669
4727
  }
4670
- } else{
4671
- document.removeEventListener('error', switchOptions, true);
4672
- }
4728
+ });
4729
+
4730
+
4673
4731
  }
4674
4732
  };
4733
+
4734
+ document.addEventListener('error', switchOptions, true);
4675
4735
  setTimeout(function(){
4676
- document.addEventListener('error', switchOptions, true);
4677
4736
  $('audio, video').each(function(){
4678
4737
  var error = $.prop(this, 'error');
4679
4738
  if(error && switchErrors[error]){
4680
4739
  switchOptions({target: this});
4681
- return false;
4682
4740
  }
4683
4741
  });
4684
- }, 9);
4742
+ });
4685
4743
  }
4686
4744
 
4687
4745
  });