joosy 1.2.0.alpha.73 → 1.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gruntfile.coffee +56 -18
  3. data/bower.json +1 -1
  4. data/build/joosy/form.js +1 -0
  5. data/build/joosy/resources.js +1 -0
  6. data/build/joosy.js +2 -2774
  7. data/package.json +5 -4
  8. data/source/joosy/application.coffee +9 -7
  9. data/source/joosy/{extensions/resources-form/form.coffee → form.coffee} +58 -51
  10. data/source/joosy/helpers/form.coffee +241 -0
  11. data/source/joosy/helpers/index.coffee +3 -0
  12. data/source/joosy/helpers/routes.coffee +3 -1
  13. data/source/joosy/helpers/view.coffee +9 -9
  14. data/source/joosy/joosy.coffee +3 -5
  15. data/source/joosy/module.coffee +9 -4
  16. data/source/joosy/modules/dom.coffee +33 -31
  17. data/source/joosy/modules/events.coffee +24 -20
  18. data/source/joosy/modules/filters.coffee +38 -35
  19. data/source/joosy/modules/page/title.coffee +3 -3
  20. data/source/joosy/modules/renderer.coffee +23 -18
  21. data/source/joosy/modules/resources/identity_map.coffee +45 -0
  22. data/source/joosy/modules/resources/model.coffee +146 -0
  23. data/source/joosy/modules/widgets_manager.coffee +8 -8
  24. data/source/joosy/resources/array.coffee +0 -5
  25. data/source/joosy/resources/hash.coffee +8 -13
  26. data/source/joosy/resources/index.coffee +2 -0
  27. data/source/joosy/{extensions/resources → resources}/rest.coffee +48 -19
  28. data/source/joosy/resources/scalar.coffee +8 -10
  29. data/source/joosy/router.coffee +13 -12
  30. data/source/joosy/templaters/jst.coffee +3 -2
  31. data/source/joosy/widget.coffee +17 -15
  32. data/source/joosy.coffee +2 -0
  33. data/source/vendor/es5-shim.js +1316 -0
  34. data/source/vendor/inflections.js +598 -0
  35. data/source/vendor/metamorph.js +457 -0
  36. data/spec/helpers/matchers.coffee +4 -4
  37. data/spec/joosy/core/application_spec.coffee +1 -1
  38. data/spec/joosy/core/helpers/view_spec.coffee +2 -2
  39. data/spec/joosy/core/joosy_spec.coffee +8 -4
  40. data/spec/joosy/core/modules/dom_spec.coffee +7 -7
  41. data/spec/joosy/core/modules/events_spec.coffee +2 -2
  42. data/spec/joosy/core/modules/filters_spec.coffee +7 -8
  43. data/spec/joosy/core/modules/module_spec.coffee +5 -5
  44. data/spec/joosy/core/router_spec.coffee +3 -3
  45. data/spec/joosy/core/widget_spec.coffee +6 -6
  46. data/spec/joosy/environments/amd_spec.coffee +4 -2
  47. data/spec/joosy/environments/global_spec.coffee +1 -1
  48. data/spec/joosy/{extensions/form → form}/form_spec.coffee +9 -16
  49. data/spec/joosy/{extensions/form → form}/helpers/forms_spec.coffee +5 -5
  50. data/spec/joosy/{core/resources → resources}/array_spec.coffee +2 -2
  51. data/spec/joosy/{core/resources → resources}/hash_spec.coffee +0 -8
  52. data/spec/joosy/{core/modules/resources → resources/modules}/cacher_spec.coffee +0 -0
  53. data/spec/joosy/resources/modules/identity_map_spec.coffee +47 -0
  54. data/spec/joosy/{extensions/resources/base_spec.coffee → resources/modules/model_spec.coffee} +28 -48
  55. data/spec/joosy/{extensions/resources → resources}/rest_spec.coffee +29 -22
  56. data/spec/joosy/{core/resources → resources}/scalar_spec.coffee +8 -8
  57. data/templates/application/application.coffee.tt +0 -2
  58. data/templates/environment/app/haml/index.haml +2 -2
  59. data/templates/environment/package.json +1 -1
  60. metadata +23 -19
  61. data/build/joosy/extensions/resources-form.js +0 -590
  62. data/build/joosy/extensions/resources.js +0 -561
  63. data/source/joosy/extensions/resources/base.coffee +0 -282
  64. data/source/joosy/extensions/resources/index.coffee +0 -1
  65. data/source/joosy/extensions/resources-form/helpers/form.coffee +0 -104
  66. data/source/joosy/extensions/resources-form/index.coffee +0 -1
  67. data/source/metamorph.coffee +0 -410
@@ -0,0 +1,1316 @@
1
+ // Copyright 2009-2012 by contributors, MIT License
2
+ // vim: ts=4 sts=4 sw=4 expandtab
3
+
4
+ // Module systems magic dance
5
+ (function (definition) {
6
+ if (typeof YUI == "function") {
7
+ YUI.add("es5", definition);
8
+ // CommonJS and <script>
9
+ } else {
10
+ definition();
11
+ }
12
+ })(function () {
13
+
14
+ /**
15
+ * Brings an environment as close to ECMAScript 5 compliance
16
+ * as is possible with the facilities of erstwhile engines.
17
+ *
18
+ * Annotated ES5: http://es5.github.com/ (specific links below)
19
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
20
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
21
+ */
22
+
23
+ //
24
+ // Function
25
+ // ========
26
+ //
27
+
28
+ // ES-5 15.3.4.5
29
+ // http://es5.github.com/#x15.3.4.5
30
+
31
+ function Empty() {}
32
+
33
+ if (!Function.prototype.bind) {
34
+ Function.prototype.bind = function bind(that) { // .length is 1
35
+ // 1. Let Target be the this value.
36
+ var target = this;
37
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
38
+ if (typeof target != "function") {
39
+ throw new TypeError("Function.prototype.bind called on incompatible " + target);
40
+ }
41
+ // 3. Let A be a new (possibly empty) internal list of all of the
42
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
43
+ // XXX slicedArgs will stand in for "A" if used
44
+ var args = _Array_slice_.call(arguments, 1); // for normal call
45
+ // 4. Let F be a new native ECMAScript object.
46
+ // 11. Set the [[Prototype]] internal property of F to the standard
47
+ // built-in Function prototype object as specified in 15.3.3.1.
48
+ // 12. Set the [[Call]] internal property of F as described in
49
+ // 15.3.4.5.1.
50
+ // 13. Set the [[Construct]] internal property of F as described in
51
+ // 15.3.4.5.2.
52
+ // 14. Set the [[HasInstance]] internal property of F as described in
53
+ // 15.3.4.5.3.
54
+ var bound = function () {
55
+
56
+ if (this instanceof bound) {
57
+ // 15.3.4.5.2 [[Construct]]
58
+ // When the [[Construct]] internal method of a function object,
59
+ // F that was created using the bind function is called with a
60
+ // list of arguments ExtraArgs, the following steps are taken:
61
+ // 1. Let target be the value of F's [[TargetFunction]]
62
+ // internal property.
63
+ // 2. If target has no [[Construct]] internal method, a
64
+ // TypeError exception is thrown.
65
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
66
+ // property.
67
+ // 4. Let args be a new list containing the same values as the
68
+ // list boundArgs in the same order followed by the same
69
+ // values as the list ExtraArgs in the same order.
70
+ // 5. Return the result of calling the [[Construct]] internal
71
+ // method of target providing args as the arguments.
72
+
73
+ var result = target.apply(
74
+ this,
75
+ args.concat(_Array_slice_.call(arguments))
76
+ );
77
+ if (Object(result) === result) {
78
+ return result;
79
+ }
80
+ return this;
81
+
82
+ } else {
83
+ // 15.3.4.5.1 [[Call]]
84
+ // When the [[Call]] internal method of a function object, F,
85
+ // which was created using the bind function is called with a
86
+ // this value and a list of arguments ExtraArgs, the following
87
+ // steps are taken:
88
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
89
+ // property.
90
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
91
+ // property.
92
+ // 3. Let target be the value of F's [[TargetFunction]] internal
93
+ // property.
94
+ // 4. Let args be a new list containing the same values as the
95
+ // list boundArgs in the same order followed by the same
96
+ // values as the list ExtraArgs in the same order.
97
+ // 5. Return the result of calling the [[Call]] internal method
98
+ // of target providing boundThis as the this value and
99
+ // providing args as the arguments.
100
+
101
+ // equiv: target.call(this, ...boundArgs, ...args)
102
+ return target.apply(
103
+ that,
104
+ args.concat(_Array_slice_.call(arguments))
105
+ );
106
+
107
+ }
108
+
109
+ };
110
+ if (target.prototype) {
111
+ Empty.prototype = target.prototype;
112
+ bound.prototype = new Empty();
113
+ // Clean up dangling references.
114
+ Empty.prototype = null;
115
+ }
116
+ // XXX bound.length is never writable, so don't even try
117
+ //
118
+ // 15. If the [[Class]] internal property of Target is "Function", then
119
+ // a. Let L be the length property of Target minus the length of A.
120
+ // b. Set the length own property of F to either 0 or L, whichever is
121
+ // larger.
122
+ // 16. Else set the length own property of F to 0.
123
+ // 17. Set the attributes of the length own property of F to the values
124
+ // specified in 15.3.5.1.
125
+
126
+ // TODO
127
+ // 18. Set the [[Extensible]] internal property of F to true.
128
+
129
+ // TODO
130
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
131
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
132
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
133
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
134
+ // false.
135
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
136
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
137
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
138
+ // and false.
139
+
140
+ // TODO
141
+ // NOTE Function objects created using Function.prototype.bind do not
142
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
143
+ // [[Scope]] internal properties.
144
+ // XXX can't delete prototype in pure-js.
145
+
146
+ // 22. Return F.
147
+ return bound;
148
+ };
149
+ }
150
+
151
+ // Shortcut to an often accessed properties, in order to avoid multiple
152
+ // dereference that costs universally.
153
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
154
+ // us it in defining shortcuts.
155
+ var call = Function.prototype.call;
156
+ var prototypeOfArray = Array.prototype;
157
+ var prototypeOfObject = Object.prototype;
158
+ var _Array_slice_ = prototypeOfArray.slice;
159
+ // Having a toString local variable name breaks in Opera so use _toString.
160
+ var _toString = call.bind(prototypeOfObject.toString);
161
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
162
+
163
+ // If JS engine supports accessors creating shortcuts.
164
+ var defineGetter;
165
+ var defineSetter;
166
+ var lookupGetter;
167
+ var lookupSetter;
168
+ var supportsAccessors;
169
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
170
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
171
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
172
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
173
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
174
+ }
175
+
176
+ //
177
+ // Array
178
+ // =====
179
+ //
180
+
181
+ // ES5 15.4.4.12
182
+ // http://es5.github.com/#x15.4.4.12
183
+ // Default value for second param
184
+ // [bugfix, ielt9, old browsers]
185
+ // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
186
+ if ([1,2].splice(0).length != 2) {
187
+ var array_splice = Array.prototype.splice;
188
+
189
+ if (function() { // test IE < 9 to splice bug - see issue #138
190
+ function makeArray(l) {
191
+ var a = [];
192
+ while (l--) {
193
+ a.unshift(l)
194
+ }
195
+ return a
196
+ }
197
+
198
+ var array = []
199
+ , lengthBefore
200
+ ;
201
+
202
+ array.splice.bind(array, 0, 0).apply(null, makeArray(20));
203
+ array.splice.bind(array, 0, 0).apply(null, makeArray(26));
204
+
205
+ lengthBefore = array.length; //20
206
+ array.splice(5, 0, "XXX"); // add one element
207
+
208
+ if (lengthBefore + 1 == array.length) {
209
+ return true;// has right splice implementation without bugs
210
+ }
211
+ // else {
212
+ // IE8 bug
213
+ // }
214
+ }()) {//IE 6/7
215
+ Array.prototype.splice = function(start, deleteCount) {
216
+ if (!arguments.length) {
217
+ return [];
218
+ } else {
219
+ return array_splice.apply(this, [
220
+ start === void 0 ? 0 : start,
221
+ deleteCount === void 0 ? (this.length - start) : deleteCount
222
+ ].concat(_Array_slice_.call(arguments, 2)))
223
+ }
224
+ };
225
+ }
226
+ else {//IE8
227
+ Array.prototype.splice = function(start, deleteCount) {
228
+ var result
229
+ , args = _Array_slice_.call(arguments, 2)
230
+ , addElementsCount = args.length
231
+ ;
232
+
233
+ if (!arguments.length) {
234
+ return [];
235
+ }
236
+
237
+ if (start === void 0) { // default
238
+ start = 0;
239
+ }
240
+ if (deleteCount === void 0) { // default
241
+ deleteCount = this.length - start;
242
+ }
243
+
244
+ if (addElementsCount > 0) {
245
+ if (deleteCount <= 0) {
246
+ if (start == this.length) { // tiny optimisation #1
247
+ this.push.apply(this, args);
248
+ return [];
249
+ }
250
+
251
+ if (start == 0) { // tiny optimisation #2
252
+ this.unshift.apply(this, args);
253
+ return [];
254
+ }
255
+ }
256
+
257
+ // Array.prototype.splice implementation
258
+ result = _Array_slice_.call(this, start, start + deleteCount);// delete part
259
+ args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part
260
+ args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part
261
+
262
+ // delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part'
263
+ args.unshift(0, this.length);
264
+
265
+ array_splice.apply(this, args);
266
+
267
+ return result;
268
+ }
269
+
270
+ return array_splice.call(this, start, deleteCount);
271
+ }
272
+
273
+ }
274
+ }
275
+
276
+ // ES5 15.4.4.12
277
+ // http://es5.github.com/#x15.4.4.13
278
+ // Return len+argCount.
279
+ // [bugfix, ielt8]
280
+ // IE < 8 bug: [].unshift(0) == undefined but should be "1"
281
+ if ([].unshift(0) != 1) {
282
+ var array_unshift = Array.prototype.unshift;
283
+ Array.prototype.unshift = function() {
284
+ array_unshift.apply(this, arguments);
285
+ return this.length;
286
+ };
287
+ }
288
+
289
+ // ES5 15.4.3.2
290
+ // http://es5.github.com/#x15.4.3.2
291
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
292
+ if (!Array.isArray) {
293
+ Array.isArray = function isArray(obj) {
294
+ return _toString(obj) == "[object Array]";
295
+ };
296
+ }
297
+
298
+ // The IsCallable() check in the Array functions
299
+ // has been replaced with a strict check on the
300
+ // internal class of the object to trap cases where
301
+ // the provided function was actually a regular
302
+ // expression literal, which in V8 and
303
+ // JavaScriptCore is a typeof "function". Only in
304
+ // V8 are regular expression literals permitted as
305
+ // reduce parameters, so it is desirable in the
306
+ // general case for the shim to match the more
307
+ // strict and common behavior of rejecting regular
308
+ // expressions.
309
+
310
+ // ES5 15.4.4.18
311
+ // http://es5.github.com/#x15.4.4.18
312
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
313
+
314
+ // Check failure of by-index access of string characters (IE < 9)
315
+ // and failure of `0 in boxedString` (Rhino)
316
+ var boxedString = Object("a"),
317
+ splitString = boxedString[0] != "a" || !(0 in boxedString);
318
+
319
+ if (!Array.prototype.forEach) {
320
+ Array.prototype.forEach = function forEach(fun /*, thisp*/) {
321
+ var object = toObject(this),
322
+ self = splitString && _toString(this) == "[object String]" ?
323
+ this.split("") :
324
+ object,
325
+ thisp = arguments[1],
326
+ i = -1,
327
+ length = self.length >>> 0;
328
+
329
+ // If no callback function or if callback is not a callable function
330
+ if (_toString(fun) != "[object Function]") {
331
+ throw new TypeError(); // TODO message
332
+ }
333
+
334
+ while (++i < length) {
335
+ if (i in self) {
336
+ // Invoke the callback function with call, passing arguments:
337
+ // context, property value, property key, thisArg object
338
+ // context
339
+ fun.call(thisp, self[i], i, object);
340
+ }
341
+ }
342
+ };
343
+ }
344
+
345
+ // ES5 15.4.4.19
346
+ // http://es5.github.com/#x15.4.4.19
347
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
348
+ if (!Array.prototype.map) {
349
+ Array.prototype.map = function map(fun /*, thisp*/) {
350
+ var object = toObject(this),
351
+ self = splitString && _toString(this) == "[object String]" ?
352
+ this.split("") :
353
+ object,
354
+ length = self.length >>> 0,
355
+ result = Array(length),
356
+ thisp = arguments[1];
357
+
358
+ // If no callback function or if callback is not a callable function
359
+ if (_toString(fun) != "[object Function]") {
360
+ throw new TypeError(fun + " is not a function");
361
+ }
362
+
363
+ for (var i = 0; i < length; i++) {
364
+ if (i in self)
365
+ result[i] = fun.call(thisp, self[i], i, object);
366
+ }
367
+ return result;
368
+ };
369
+ }
370
+
371
+ // ES5 15.4.4.20
372
+ // http://es5.github.com/#x15.4.4.20
373
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
374
+ if (!Array.prototype.filter) {
375
+ Array.prototype.filter = function filter(fun /*, thisp */) {
376
+ var object = toObject(this),
377
+ self = splitString && _toString(this) == "[object String]" ?
378
+ this.split("") :
379
+ object,
380
+ length = self.length >>> 0,
381
+ result = [],
382
+ value,
383
+ thisp = arguments[1];
384
+
385
+ // If no callback function or if callback is not a callable function
386
+ if (_toString(fun) != "[object Function]") {
387
+ throw new TypeError(fun + " is not a function");
388
+ }
389
+
390
+ for (var i = 0; i < length; i++) {
391
+ if (i in self) {
392
+ value = self[i];
393
+ if (fun.call(thisp, value, i, object)) {
394
+ result.push(value);
395
+ }
396
+ }
397
+ }
398
+ return result;
399
+ };
400
+ }
401
+
402
+ // ES5 15.4.4.16
403
+ // http://es5.github.com/#x15.4.4.16
404
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
405
+ if (!Array.prototype.every) {
406
+ Array.prototype.every = function every(fun /*, thisp */) {
407
+ var object = toObject(this),
408
+ self = splitString && _toString(this) == "[object String]" ?
409
+ this.split("") :
410
+ object,
411
+ length = self.length >>> 0,
412
+ thisp = arguments[1];
413
+
414
+ // If no callback function or if callback is not a callable function
415
+ if (_toString(fun) != "[object Function]") {
416
+ throw new TypeError(fun + " is not a function");
417
+ }
418
+
419
+ for (var i = 0; i < length; i++) {
420
+ if (i in self && !fun.call(thisp, self[i], i, object)) {
421
+ return false;
422
+ }
423
+ }
424
+ return true;
425
+ };
426
+ }
427
+
428
+ // ES5 15.4.4.17
429
+ // http://es5.github.com/#x15.4.4.17
430
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
431
+ if (!Array.prototype.some) {
432
+ Array.prototype.some = function some(fun /*, thisp */) {
433
+ var object = toObject(this),
434
+ self = splitString && _toString(this) == "[object String]" ?
435
+ this.split("") :
436
+ object,
437
+ length = self.length >>> 0,
438
+ thisp = arguments[1];
439
+
440
+ // If no callback function or if callback is not a callable function
441
+ if (_toString(fun) != "[object Function]") {
442
+ throw new TypeError(fun + " is not a function");
443
+ }
444
+
445
+ for (var i = 0; i < length; i++) {
446
+ if (i in self && fun.call(thisp, self[i], i, object)) {
447
+ return true;
448
+ }
449
+ }
450
+ return false;
451
+ };
452
+ }
453
+
454
+ // ES5 15.4.4.21
455
+ // http://es5.github.com/#x15.4.4.21
456
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
457
+ if (!Array.prototype.reduce) {
458
+ Array.prototype.reduce = function reduce(fun /*, initial*/) {
459
+ var object = toObject(this),
460
+ self = splitString && _toString(this) == "[object String]" ?
461
+ this.split("") :
462
+ object,
463
+ length = self.length >>> 0;
464
+
465
+ // If no callback function or if callback is not a callable function
466
+ if (_toString(fun) != "[object Function]") {
467
+ throw new TypeError(fun + " is not a function");
468
+ }
469
+
470
+ // no value to return if no initial value and an empty array
471
+ if (!length && arguments.length == 1) {
472
+ throw new TypeError("reduce of empty array with no initial value");
473
+ }
474
+
475
+ var i = 0;
476
+ var result;
477
+ if (arguments.length >= 2) {
478
+ result = arguments[1];
479
+ } else {
480
+ do {
481
+ if (i in self) {
482
+ result = self[i++];
483
+ break;
484
+ }
485
+
486
+ // if array contains no values, no initial value to return
487
+ if (++i >= length) {
488
+ throw new TypeError("reduce of empty array with no initial value");
489
+ }
490
+ } while (true);
491
+ }
492
+
493
+ for (; i < length; i++) {
494
+ if (i in self) {
495
+ result = fun.call(void 0, result, self[i], i, object);
496
+ }
497
+ }
498
+
499
+ return result;
500
+ };
501
+ }
502
+
503
+ // ES5 15.4.4.22
504
+ // http://es5.github.com/#x15.4.4.22
505
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
506
+ if (!Array.prototype.reduceRight) {
507
+ Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
508
+ var object = toObject(this),
509
+ self = splitString && _toString(this) == "[object String]" ?
510
+ this.split("") :
511
+ object,
512
+ length = self.length >>> 0;
513
+
514
+ // If no callback function or if callback is not a callable function
515
+ if (_toString(fun) != "[object Function]") {
516
+ throw new TypeError(fun + " is not a function");
517
+ }
518
+
519
+ // no value to return if no initial value, empty array
520
+ if (!length && arguments.length == 1) {
521
+ throw new TypeError("reduceRight of empty array with no initial value");
522
+ }
523
+
524
+ var result, i = length - 1;
525
+ if (arguments.length >= 2) {
526
+ result = arguments[1];
527
+ } else {
528
+ do {
529
+ if (i in self) {
530
+ result = self[i--];
531
+ break;
532
+ }
533
+
534
+ // if array contains no values, no initial value to return
535
+ if (--i < 0) {
536
+ throw new TypeError("reduceRight of empty array with no initial value");
537
+ }
538
+ } while (true);
539
+ }
540
+
541
+ if (i < 0) {
542
+ return result;
543
+ }
544
+
545
+ do {
546
+ if (i in this) {
547
+ result = fun.call(void 0, result, self[i], i, object);
548
+ }
549
+ } while (i--);
550
+
551
+ return result;
552
+ };
553
+ }
554
+
555
+ // ES5 15.4.4.14
556
+ // http://es5.github.com/#x15.4.4.14
557
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
558
+ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
559
+ Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
560
+ var self = splitString && _toString(this) == "[object String]" ?
561
+ this.split("") :
562
+ toObject(this),
563
+ length = self.length >>> 0;
564
+
565
+ if (!length) {
566
+ return -1;
567
+ }
568
+
569
+ var i = 0;
570
+ if (arguments.length > 1) {
571
+ i = toInteger(arguments[1]);
572
+ }
573
+
574
+ // handle negative indices
575
+ i = i >= 0 ? i : Math.max(0, length + i);
576
+ for (; i < length; i++) {
577
+ if (i in self && self[i] === sought) {
578
+ return i;
579
+ }
580
+ }
581
+ return -1;
582
+ };
583
+ }
584
+
585
+ // ES5 15.4.4.15
586
+ // http://es5.github.com/#x15.4.4.15
587
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
588
+ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
589
+ Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
590
+ var self = splitString && _toString(this) == "[object String]" ?
591
+ this.split("") :
592
+ toObject(this),
593
+ length = self.length >>> 0;
594
+
595
+ if (!length) {
596
+ return -1;
597
+ }
598
+ var i = length - 1;
599
+ if (arguments.length > 1) {
600
+ i = Math.min(i, toInteger(arguments[1]));
601
+ }
602
+ // handle negative indices
603
+ i = i >= 0 ? i : length - Math.abs(i);
604
+ for (; i >= 0; i--) {
605
+ if (i in self && sought === self[i]) {
606
+ return i;
607
+ }
608
+ }
609
+ return -1;
610
+ };
611
+ }
612
+
613
+ //
614
+ // Object
615
+ // ======
616
+ //
617
+
618
+ // ES5 15.2.3.14
619
+ // http://es5.github.com/#x15.2.3.14
620
+ if (!Object.keys) {
621
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
622
+ var hasDontEnumBug = true,
623
+ dontEnums = [
624
+ "toString",
625
+ "toLocaleString",
626
+ "valueOf",
627
+ "hasOwnProperty",
628
+ "isPrototypeOf",
629
+ "propertyIsEnumerable",
630
+ "constructor"
631
+ ],
632
+ dontEnumsLength = dontEnums.length;
633
+
634
+ for (var key in {"toString": null}) {
635
+ hasDontEnumBug = false;
636
+ }
637
+
638
+ Object.keys = function keys(object) {
639
+
640
+ if (
641
+ (typeof object != "object" && typeof object != "function") ||
642
+ object === null
643
+ ) {
644
+ throw new TypeError("Object.keys called on a non-object");
645
+ }
646
+
647
+ var keys = [];
648
+ for (var name in object) {
649
+ if (owns(object, name)) {
650
+ keys.push(name);
651
+ }
652
+ }
653
+
654
+ if (hasDontEnumBug) {
655
+ for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
656
+ var dontEnum = dontEnums[i];
657
+ if (owns(object, dontEnum)) {
658
+ keys.push(dontEnum);
659
+ }
660
+ }
661
+ }
662
+ return keys;
663
+ };
664
+
665
+ }
666
+
667
+ //
668
+ // Date
669
+ // ====
670
+ //
671
+
672
+ // ES5 15.9.5.43
673
+ // http://es5.github.com/#x15.9.5.43
674
+ // This function returns a String value represent the instance in time
675
+ // represented by this Date object. The format of the String is the Date Time
676
+ // string format defined in 15.9.1.15. All fields are present in the String.
677
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
678
+ // this object is not a finite Number a RangeError exception is thrown.
679
+ var negativeDate = -62198755200000,
680
+ negativeYearString = "-000001";
681
+ if (
682
+ !Date.prototype.toISOString ||
683
+ (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
684
+ ) {
685
+ Date.prototype.toISOString = function toISOString() {
686
+ var result, length, value, year, month;
687
+ if (!isFinite(this)) {
688
+ throw new RangeError("Date.prototype.toISOString called on non-finite value.");
689
+ }
690
+
691
+ year = this.getUTCFullYear();
692
+
693
+ month = this.getUTCMonth();
694
+ // see https://github.com/kriskowal/es5-shim/issues/111
695
+ year += Math.floor(month / 12);
696
+ month = (month % 12 + 12) % 12;
697
+
698
+ // the date time string format is specified in 15.9.1.15.
699
+ result = [month + 1, this.getUTCDate(),
700
+ this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
701
+ year = (
702
+ (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
703
+ ("00000" + Math.abs(year))
704
+ .slice(0 <= year && year <= 9999 ? -4 : -6)
705
+ );
706
+
707
+ length = result.length;
708
+ while (length--) {
709
+ value = result[length];
710
+ // pad months, days, hours, minutes, and seconds to have two
711
+ // digits.
712
+ if (value < 10) {
713
+ result[length] = "0" + value;
714
+ }
715
+ }
716
+ // pad milliseconds to have three digits.
717
+ return (
718
+ year + "-" + result.slice(0, 2).join("-") +
719
+ "T" + result.slice(2).join(":") + "." +
720
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
721
+ );
722
+ };
723
+ }
724
+
725
+
726
+ // ES5 15.9.5.44
727
+ // http://es5.github.com/#x15.9.5.44
728
+ // This function provides a String representation of a Date object for use by
729
+ // JSON.stringify (15.12.3).
730
+ var dateToJSONIsSupported = false;
731
+ try {
732
+ dateToJSONIsSupported = (
733
+ Date.prototype.toJSON &&
734
+ new Date(NaN).toJSON() === null &&
735
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
736
+ Date.prototype.toJSON.call({ // generic
737
+ toISOString: function () {
738
+ return true;
739
+ }
740
+ })
741
+ );
742
+ } catch (e) {
743
+ }
744
+ if (!dateToJSONIsSupported) {
745
+ Date.prototype.toJSON = function toJSON(key) {
746
+ // When the toJSON method is called with argument key, the following
747
+ // steps are taken:
748
+
749
+ // 1. Let O be the result of calling ToObject, giving it the this
750
+ // value as its argument.
751
+ // 2. Let tv be toPrimitive(O, hint Number).
752
+ var o = Object(this),
753
+ tv = toPrimitive(o),
754
+ toISO;
755
+ // 3. If tv is a Number and is not finite, return null.
756
+ if (typeof tv === "number" && !isFinite(tv)) {
757
+ return null;
758
+ }
759
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
760
+ // O with argument "toISOString".
761
+ toISO = o.toISOString;
762
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
763
+ if (typeof toISO != "function") {
764
+ throw new TypeError("toISOString property is not callable");
765
+ }
766
+ // 6. Return the result of calling the [[Call]] internal method of
767
+ // toISO with O as the this value and an empty argument list.
768
+ return toISO.call(o);
769
+
770
+ // NOTE 1 The argument is ignored.
771
+
772
+ // NOTE 2 The toJSON function is intentionally generic; it does not
773
+ // require that its this value be a Date object. Therefore, it can be
774
+ // transferred to other kinds of objects for use as a method. However,
775
+ // it does require that any such object have a toISOString method. An
776
+ // object is free to use the argument key to filter its
777
+ // stringification.
778
+ };
779
+ }
780
+
781
+ // ES5 15.9.4.2
782
+ // http://es5.github.com/#x15.9.4.2
783
+ // based on work shared by Daniel Friesen (dantman)
784
+ // http://gist.github.com/303249
785
+ if (!Date.parse || "Date.parse is buggy") {
786
+ // XXX global assignment won't work in embeddings that use
787
+ // an alternate object for the context.
788
+ Date = (function(NativeDate) {
789
+
790
+ // Date.length === 7
791
+ function Date(Y, M, D, h, m, s, ms) {
792
+ var length = arguments.length;
793
+ if (this instanceof NativeDate) {
794
+ var date = length == 1 && String(Y) === Y ? // isString(Y)
795
+ // We explicitly pass it through parse:
796
+ new NativeDate(Date.parse(Y)) :
797
+ // We have to manually make calls depending on argument
798
+ // length here
799
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
800
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
801
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
802
+ length >= 4 ? new NativeDate(Y, M, D, h) :
803
+ length >= 3 ? new NativeDate(Y, M, D) :
804
+ length >= 2 ? new NativeDate(Y, M) :
805
+ length >= 1 ? new NativeDate(Y) :
806
+ new NativeDate();
807
+ // Prevent mixups with unfixed Date object
808
+ date.constructor = Date;
809
+ return date;
810
+ }
811
+ return NativeDate.apply(this, arguments);
812
+ };
813
+
814
+ // 15.9.1.15 Date Time String Format.
815
+ var isoDateExpression = new RegExp("^" +
816
+ "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
817
+ // 6-digit extended year
818
+ "(?:-(\\d{2})" + // optional month capture
819
+ "(?:-(\\d{2})" + // optional day capture
820
+ "(?:" + // capture hours:minutes:seconds.milliseconds
821
+ "T(\\d{2})" + // hours capture
822
+ ":(\\d{2})" + // minutes capture
823
+ "(?:" + // optional :seconds.milliseconds
824
+ ":(\\d{2})" + // seconds capture
825
+ "(?:(\\.\\d{1,}))?" + // milliseconds capture
826
+ ")?" +
827
+ "(" + // capture UTC offset component
828
+ "Z|" + // UTC capture
829
+ "(?:" + // offset specifier +/-hours:minutes
830
+ "([-+])" + // sign capture
831
+ "(\\d{2})" + // hours offset capture
832
+ ":(\\d{2})" + // minutes offset capture
833
+ ")" +
834
+ ")?)?)?)?" +
835
+ "$");
836
+
837
+ var months = [
838
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
839
+ ];
840
+
841
+ function dayFromMonth(year, month) {
842
+ var t = month > 1 ? 1 : 0;
843
+ return (
844
+ months[month] +
845
+ Math.floor((year - 1969 + t) / 4) -
846
+ Math.floor((year - 1901 + t) / 100) +
847
+ Math.floor((year - 1601 + t) / 400) +
848
+ 365 * (year - 1970)
849
+ );
850
+ }
851
+
852
+ function toUTC(t) {
853
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
854
+ }
855
+
856
+ // Copy any custom methods a 3rd party library may have added
857
+ for (var key in NativeDate) {
858
+ Date[key] = NativeDate[key];
859
+ }
860
+
861
+ // Copy "native" methods explicitly; they may be non-enumerable
862
+ Date.now = NativeDate.now;
863
+ Date.UTC = NativeDate.UTC;
864
+ Date.prototype = NativeDate.prototype;
865
+ Date.prototype.constructor = Date;
866
+
867
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
868
+ Date.parse = function parse(string) {
869
+ var match = isoDateExpression.exec(string);
870
+ if (match) {
871
+ // parse months, days, hours, minutes, seconds, and milliseconds
872
+ // provide default values if necessary
873
+ // parse the UTC offset component
874
+ var year = Number(match[1]),
875
+ month = Number(match[2] || 1) - 1,
876
+ day = Number(match[3] || 1) - 1,
877
+ hour = Number(match[4] || 0),
878
+ minute = Number(match[5] || 0),
879
+ second = Number(match[6] || 0),
880
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
881
+ // When time zone is missed, local offset should be used
882
+ // (ES 5.1 bug)
883
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
884
+ isLocalTime = Boolean(match[4] && !match[8]),
885
+ signOffset = match[9] === "-" ? 1 : -1,
886
+ hourOffset = Number(match[10] || 0),
887
+ minuteOffset = Number(match[11] || 0),
888
+ result;
889
+ if (
890
+ hour < (
891
+ minute > 0 || second > 0 || millisecond > 0 ?
892
+ 24 : 25
893
+ ) &&
894
+ minute < 60 && second < 60 && millisecond < 1000 &&
895
+ month > -1 && month < 12 && hourOffset < 24 &&
896
+ minuteOffset < 60 && // detect invalid offsets
897
+ day > -1 &&
898
+ day < (
899
+ dayFromMonth(year, month + 1) -
900
+ dayFromMonth(year, month)
901
+ )
902
+ ) {
903
+ result = (
904
+ (dayFromMonth(year, month) + day) * 24 +
905
+ hour +
906
+ hourOffset * signOffset
907
+ ) * 60;
908
+ result = (
909
+ (result + minute + minuteOffset * signOffset) * 60 +
910
+ second
911
+ ) * 1000 + millisecond;
912
+ if (isLocalTime) {
913
+ result = toUTC(result);
914
+ }
915
+ if (-8.64e15 <= result && result <= 8.64e15) {
916
+ return result;
917
+ }
918
+ }
919
+ return NaN;
920
+ }
921
+ return NativeDate.parse.apply(this, arguments);
922
+ };
923
+
924
+ return Date;
925
+ })(Date);
926
+ }
927
+
928
+ // ES5 15.9.4.4
929
+ // http://es5.github.com/#x15.9.4.4
930
+ if (!Date.now) {
931
+ Date.now = function now() {
932
+ return new Date().getTime();
933
+ };
934
+ }
935
+
936
+
937
+ //
938
+ // Number
939
+ // ======
940
+ //
941
+
942
+ // ES5.1 15.7.4.5
943
+ // http://es5.github.com/#x15.7.4.5
944
+ 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") {
945
+ // Hide these variables and functions
946
+ (function () {
947
+ var base, size, data, i;
948
+
949
+ base = 1e7;
950
+ size = 6;
951
+ data = [0, 0, 0, 0, 0, 0];
952
+
953
+ function multiply(n, c) {
954
+ var i = -1;
955
+ while (++i < size) {
956
+ c += n * data[i];
957
+ data[i] = c % base;
958
+ c = Math.floor(c / base);
959
+ }
960
+ }
961
+
962
+ function divide(n) {
963
+ var i = size, c = 0;
964
+ while (--i >= 0) {
965
+ c += data[i];
966
+ data[i] = Math.floor(c / n);
967
+ c = (c % n) * base;
968
+ }
969
+ }
970
+
971
+ function toString() {
972
+ var i = size;
973
+ var s = '';
974
+ while (--i >= 0) {
975
+ if (s !== '' || i === 0 || data[i] !== 0) {
976
+ var t = String(data[i]);
977
+ if (s === '') {
978
+ s = t;
979
+ } else {
980
+ s += '0000000'.slice(0, 7 - t.length) + t;
981
+ }
982
+ }
983
+ }
984
+ return s;
985
+ }
986
+
987
+ function pow(x, n, acc) {
988
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
989
+ }
990
+
991
+ function log(x) {
992
+ var n = 0;
993
+ while (x >= 4096) {
994
+ n += 12;
995
+ x /= 4096;
996
+ }
997
+ while (x >= 2) {
998
+ n += 1;
999
+ x /= 2;
1000
+ }
1001
+ return n;
1002
+ }
1003
+
1004
+ Number.prototype.toFixed = function (fractionDigits) {
1005
+ var f, x, s, m, e, z, j, k;
1006
+
1007
+ // Test for NaN and round fractionDigits down
1008
+ f = Number(fractionDigits);
1009
+ f = f !== f ? 0 : Math.floor(f);
1010
+
1011
+ if (f < 0 || f > 20) {
1012
+ throw new RangeError("Number.toFixed called with invalid number of decimals");
1013
+ }
1014
+
1015
+ x = Number(this);
1016
+
1017
+ // Test for NaN
1018
+ if (x !== x) {
1019
+ return "NaN";
1020
+ }
1021
+
1022
+ // If it is too big or small, return the string value of the number
1023
+ if (x <= -1e21 || x >= 1e21) {
1024
+ return String(x);
1025
+ }
1026
+
1027
+ s = "";
1028
+
1029
+ if (x < 0) {
1030
+ s = "-";
1031
+ x = -x;
1032
+ }
1033
+
1034
+ m = "0";
1035
+
1036
+ if (x > 1e-21) {
1037
+ // 1e-21 < x < 1e21
1038
+ // -70 < log2(x) < 70
1039
+ e = log(x * pow(2, 69, 1)) - 69;
1040
+ z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
1041
+ z *= 0x10000000000000; // Math.pow(2, 52);
1042
+ e = 52 - e;
1043
+
1044
+ // -18 < e < 122
1045
+ // x = z / 2 ^ e
1046
+ if (e > 0) {
1047
+ multiply(0, z);
1048
+ j = f;
1049
+
1050
+ while (j >= 7) {
1051
+ multiply(1e7, 0);
1052
+ j -= 7;
1053
+ }
1054
+
1055
+ multiply(pow(10, j, 1), 0);
1056
+ j = e - 1;
1057
+
1058
+ while (j >= 23) {
1059
+ divide(1 << 23);
1060
+ j -= 23;
1061
+ }
1062
+
1063
+ divide(1 << j);
1064
+ multiply(1, 1);
1065
+ divide(2);
1066
+ m = toString();
1067
+ } else {
1068
+ multiply(0, z);
1069
+ multiply(1 << (-e), 0);
1070
+ m = toString() + '0.00000000000000000000'.slice(2, 2 + f);
1071
+ }
1072
+ }
1073
+
1074
+ if (f > 0) {
1075
+ k = m.length;
1076
+
1077
+ if (k <= f) {
1078
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1079
+ } else {
1080
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1081
+ }
1082
+ } else {
1083
+ m = s + m;
1084
+ }
1085
+
1086
+ return m;
1087
+ }
1088
+ }());
1089
+ }
1090
+
1091
+
1092
+ //
1093
+ // String
1094
+ // ======
1095
+ //
1096
+
1097
+
1098
+ // ES5 15.5.4.14
1099
+ // http://es5.github.com/#x15.5.4.14
1100
+
1101
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1102
+ // Many browsers do not split properly with regular expressions or they
1103
+ // do not perform the split correctly under obscure conditions.
1104
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1105
+ // I've tested in many browsers and this seems to cover the deviant ones:
1106
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1107
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1108
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1109
+ // [undefined, "t", undefined, "e", ...]
1110
+ // ''.split(/.?/) should be [], not [""]
1111
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1112
+
1113
+ var string_split = String.prototype.split;
1114
+ if (
1115
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1116
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1117
+ 'tesst'.split(/(s)*/)[1] === "t" ||
1118
+ ''.split(/.?/).length === 0 ||
1119
+ '.'.split(/()()/).length > 1
1120
+ ) {
1121
+ (function () {
1122
+ var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1123
+
1124
+ String.prototype.split = function (separator, limit) {
1125
+ var string = this;
1126
+ if (separator === void 0 && limit === 0)
1127
+ return [];
1128
+
1129
+ // If `separator` is not a regex, use native split
1130
+ if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
1131
+ return string_split.apply(this, arguments);
1132
+ }
1133
+
1134
+ var output = [],
1135
+ flags = (separator.ignoreCase ? "i" : "") +
1136
+ (separator.multiline ? "m" : "") +
1137
+ (separator.extended ? "x" : "") + // Proposed for ES6
1138
+ (separator.sticky ? "y" : ""), // Firefox 3+
1139
+ lastLastIndex = 0,
1140
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1141
+ separator = new RegExp(separator.source, flags + "g"),
1142
+ separator2, match, lastIndex, lastLength;
1143
+ string += ""; // Type-convert
1144
+ if (!compliantExecNpcg) {
1145
+ // Doesn't need flags gy, but they don't hurt
1146
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1147
+ }
1148
+ /* Values for `limit`, per the spec:
1149
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1150
+ * If 0, Infinity, or NaN: 0
1151
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1152
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1153
+ * If other: Type-convert, then use the above rules
1154
+ */
1155
+ limit = limit === void 0 ?
1156
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1157
+ limit >>> 0; // ToUint32(limit)
1158
+ while (match = separator.exec(string)) {
1159
+ // `separator.lastIndex` is not reliable cross-browser
1160
+ lastIndex = match.index + match[0].length;
1161
+ if (lastIndex > lastLastIndex) {
1162
+ output.push(string.slice(lastLastIndex, match.index));
1163
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1164
+ // nonparticipating capturing groups
1165
+ if (!compliantExecNpcg && match.length > 1) {
1166
+ match[0].replace(separator2, function () {
1167
+ for (var i = 1; i < arguments.length - 2; i++) {
1168
+ if (arguments[i] === void 0) {
1169
+ match[i] = void 0;
1170
+ }
1171
+ }
1172
+ });
1173
+ }
1174
+ if (match.length > 1 && match.index < string.length) {
1175
+ Array.prototype.push.apply(output, match.slice(1));
1176
+ }
1177
+ lastLength = match[0].length;
1178
+ lastLastIndex = lastIndex;
1179
+ if (output.length >= limit) {
1180
+ break;
1181
+ }
1182
+ }
1183
+ if (separator.lastIndex === match.index) {
1184
+ separator.lastIndex++; // Avoid an infinite loop
1185
+ }
1186
+ }
1187
+ if (lastLastIndex === string.length) {
1188
+ if (lastLength || !separator.test("")) {
1189
+ output.push("");
1190
+ }
1191
+ } else {
1192
+ output.push(string.slice(lastLastIndex));
1193
+ }
1194
+ return output.length > limit ? output.slice(0, limit) : output;
1195
+ };
1196
+ }());
1197
+
1198
+ // [bugfix, chrome]
1199
+ // If separator is undefined, then the result array contains just one String,
1200
+ // which is the this value (converted to a String). If limit is not undefined,
1201
+ // then the output array is truncated so that it contains no more than limit
1202
+ // elements.
1203
+ // "0".split(undefined, 0) -> []
1204
+ } else if ("0".split(void 0, 0).length) {
1205
+ String.prototype.split = function(separator, limit) {
1206
+ if (separator === void 0 && limit === 0) return [];
1207
+ return string_split.apply(this, arguments);
1208
+ }
1209
+ }
1210
+
1211
+
1212
+ // ECMA-262, 3rd B.2.3
1213
+ // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
1214
+ // non-normative section suggesting uniform semantics and it should be
1215
+ // normalized across all browsers
1216
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1217
+ if ("".substr && "0b".substr(-1) !== "b") {
1218
+ var string_substr = String.prototype.substr;
1219
+ /**
1220
+ * Get the substring of a string
1221
+ * @param {integer} start where to start the substring
1222
+ * @param {integer} length how many characters to return
1223
+ * @return {string}
1224
+ */
1225
+ String.prototype.substr = function(start, length) {
1226
+ return string_substr.call(
1227
+ this,
1228
+ start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
1229
+ length
1230
+ );
1231
+ }
1232
+ }
1233
+
1234
+ // ES5 15.5.4.20
1235
+ // http://es5.github.com/#x15.5.4.20
1236
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1237
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1238
+ "\u2029\uFEFF";
1239
+ if (!String.prototype.trim || ws.trim()) {
1240
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1241
+ // http://perfectionkills.com/whitespace-deviations/
1242
+ ws = "[" + ws + "]";
1243
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1244
+ trimEndRegexp = new RegExp(ws + ws + "*$");
1245
+ String.prototype.trim = function trim() {
1246
+ if (this === void 0 || this === null) {
1247
+ throw new TypeError("can't convert "+this+" to object");
1248
+ }
1249
+ return String(this)
1250
+ .replace(trimBeginRegexp, "")
1251
+ .replace(trimEndRegexp, "");
1252
+ };
1253
+ }
1254
+
1255
+ //
1256
+ // Util
1257
+ // ======
1258
+ //
1259
+
1260
+ // ES5 9.4
1261
+ // http://es5.github.com/#x9.4
1262
+ // http://jsperf.com/to-integer
1263
+
1264
+ function toInteger(n) {
1265
+ n = +n;
1266
+ if (n !== n) { // isNaN
1267
+ n = 0;
1268
+ } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
1269
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
1270
+ }
1271
+ return n;
1272
+ }
1273
+
1274
+ function isPrimitive(input) {
1275
+ var type = typeof input;
1276
+ return (
1277
+ input === null ||
1278
+ type === "undefined" ||
1279
+ type === "boolean" ||
1280
+ type === "number" ||
1281
+ type === "string"
1282
+ );
1283
+ }
1284
+
1285
+ function toPrimitive(input) {
1286
+ var val, valueOf, toString;
1287
+ if (isPrimitive(input)) {
1288
+ return input;
1289
+ }
1290
+ valueOf = input.valueOf;
1291
+ if (typeof valueOf === "function") {
1292
+ val = valueOf.call(input);
1293
+ if (isPrimitive(val)) {
1294
+ return val;
1295
+ }
1296
+ }
1297
+ toString = input.toString;
1298
+ if (typeof toString === "function") {
1299
+ val = toString.call(input);
1300
+ if (isPrimitive(val)) {
1301
+ return val;
1302
+ }
1303
+ }
1304
+ throw new TypeError();
1305
+ }
1306
+
1307
+ // ES5 9.9
1308
+ // http://es5.github.com/#x9.9
1309
+ var toObject = function (o) {
1310
+ if (o == null) { // this matches both null and undefined
1311
+ throw new TypeError("can't convert "+o+" to object");
1312
+ }
1313
+ return Object(o);
1314
+ };
1315
+
1316
+ });