sudojs-rails 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module Sudojs
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sudojs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -58,9 +58,7 @@ files:
58
58
  - lib/sudojs/engine.rb
59
59
  - lib/sudojs/version.rb
60
60
  - sudojs-rails.gemspec
61
- - vendor/assets/javascripts/es5-sham
62
61
  - vendor/assets/javascripts/es5-sham.js
63
- - vendor/assets/javascripts/es5-shim
64
62
  - vendor/assets/javascripts/es5-shim.js
65
63
  - vendor/assets/javascripts/sudo-x.js
66
64
  - vendor/assets/javascripts/sudo.js
@@ -78,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
76
  version: '0'
79
77
  segments:
80
78
  - 0
81
- hash: 1971257747311608677
79
+ hash: 2786470183056535713
82
80
  required_rubygems_version: !ruby/object:Gem::Requirement
83
81
  none: false
84
82
  requirements:
@@ -87,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
85
  version: '0'
88
86
  segments:
89
87
  - 0
90
- hash: 1971257747311608677
88
+ hash: 2786470183056535713
91
89
  requirements: []
92
90
  rubyforge_project:
93
91
  rubygems_version: 1.8.24
@@ -1,25 +0,0 @@
1
- // Polyfills for non-std browsers that, while not attaining ES5 spec
2
- // (hence `sham`), function correctly on a limited scope.
3
- (function() {
4
- if(!Object.create) {
5
- Object.create = function(obj) {
6
- var ret;
7
- if (arguments.length > 1 ) {
8
- // cannot support the multiple argument scenario for legacy browsers
9
- throw new Error('This Object.create implementation only accepts a single argument');
10
- }
11
- function F(){}
12
- F.prototype = obj;
13
- ret = new F();
14
- // Allows Object.getPrototypeOf to work in non-std browsers
15
- ret.__proto__ = obj;
16
- return ret;
17
- };
18
- }
19
- // Will return the expected Object for all Objects created using the above `create` method
20
- if(!Object.getPrototypeOf) {
21
- Object.getPrototypeOf = function(object) {
22
- return object.__proto__;
23
- };
24
- }
25
- }());
@@ -1,948 +0,0 @@
1
- // Copyright 2009-2012 by contributors, MIT License
2
- (function() {
3
- /**
4
- * Brings an environment as close to ECMAScript 5 compliance
5
- * as is possible with the facilities of erstwhile engines.
6
- *
7
- * Annotated ES5: http://es5.github.com/ (specific links below)
8
- * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
9
- * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
10
- */
11
-
12
- //
13
- // Function
14
- // ========
15
- //
16
-
17
- // ES-5 15.3.4.5
18
- // http://es5.github.com/#x15.3.4.5
19
-
20
- if (!Function.prototype.bind) {
21
- Function.prototype.bind = function bind(that) { // .length is 1
22
- // 1. Let Target be the this value.
23
- var target = this;
24
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
25
- if (typeof target != "function") {
26
- throw new TypeError("Function.prototype.bind called on incompatible " + target);
27
- }
28
- // 3. Let A be a new (possibly empty) internal list of all of the
29
- // argument values provided after thisArg (arg1, arg2 etc), in order.
30
- // XXX slicedArgs will stand in for "A" if used
31
- var args = slice.call(arguments, 1); // for normal call
32
- // 4. Let F be a new native ECMAScript object.
33
- // 11. Set the [[Prototype]] internal property of F to the standard
34
- // built-in Function prototype object as specified in 15.3.3.1.
35
- // 12. Set the [[Call]] internal property of F as described in
36
- // 15.3.4.5.1.
37
- // 13. Set the [[Construct]] internal property of F as described in
38
- // 15.3.4.5.2.
39
- // 14. Set the [[HasInstance]] internal property of F as described in
40
- // 15.3.4.5.3.
41
- var bound = function () {
42
-
43
- if (this instanceof bound) {
44
- // 15.3.4.5.2 [[Construct]]
45
- // When the [[Construct]] internal method of a function object,
46
- // F that was created using the bind function is called with a
47
- // list of arguments ExtraArgs, the following steps are taken:
48
- // 1. Let target be the value of F's [[TargetFunction]]
49
- // internal property.
50
- // 2. If target has no [[Construct]] internal method, a
51
- // TypeError exception is thrown.
52
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
53
- // property.
54
- // 4. Let args be a new list containing the same values as the
55
- // list boundArgs in the same order followed by the same
56
- // values as the list ExtraArgs in the same order.
57
- // 5. Return the result of calling the [[Construct]] internal
58
- // method of target providing args as the arguments.
59
-
60
- var result = target.apply(
61
- this,
62
- args.concat(slice.call(arguments))
63
- );
64
- if (Object(result) === result) {
65
- return result;
66
- }
67
- return this;
68
-
69
- } else {
70
- // 15.3.4.5.1 [[Call]]
71
- // When the [[Call]] internal method of a function object, F,
72
- // which was created using the bind function is called with a
73
- // this value and a list of arguments ExtraArgs, the following
74
- // steps are taken:
75
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
76
- // property.
77
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
78
- // property.
79
- // 3. Let target be the value of F's [[TargetFunction]] internal
80
- // property.
81
- // 4. Let args be a new list containing the same values as the
82
- // list boundArgs in the same order followed by the same
83
- // values as the list ExtraArgs in the same order.
84
- // 5. Return the result of calling the [[Call]] internal method
85
- // of target providing boundThis as the this value and
86
- // providing args as the arguments.
87
-
88
- // equiv: target.call(this, ...boundArgs, ...args)
89
- return target.apply(
90
- that,
91
- args.concat(slice.call(arguments))
92
- );
93
-
94
- }
95
-
96
- };
97
- if(target.prototype) {
98
- bound.prototype = Object.create(target.prototype);
99
- }
100
- // XXX bound.length is never writable, so don't even try
101
- //
102
- // 15. If the [[Class]] internal property of Target is "Function", then
103
- // a. Let L be the length property of Target minus the length of A.
104
- // b. Set the length own property of F to either 0 or L, whichever is
105
- // larger.
106
- // 16. Else set the length own property of F to 0.
107
- // 17. Set the attributes of the length own property of F to the values
108
- // specified in 15.3.5.1.
109
-
110
- // TODO
111
- // 18. Set the [[Extensible]] internal property of F to true.
112
-
113
- // TODO
114
- // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
115
- // 20. Call the [[DefineOwnProperty]] internal method of F with
116
- // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
117
- // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
118
- // false.
119
- // 21. Call the [[DefineOwnProperty]] internal method of F with
120
- // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
121
- // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
122
- // and false.
123
-
124
- // TODO
125
- // NOTE Function objects created using Function.prototype.bind do not
126
- // have a prototype property or the [[Code]], [[FormalParameters]], and
127
- // [[Scope]] internal properties.
128
- // XXX can't delete prototype in pure-js.
129
-
130
- // 22. Return F.
131
- return bound;
132
- };
133
- }
134
-
135
- // Shortcut to an often accessed properties, in order to avoid multiple
136
- // dereference that costs universally.
137
- // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
138
- // us it in defining shortcuts.
139
- var call = Function.prototype.call;
140
- var prototypeOfArray = Array.prototype;
141
- var prototypeOfObject = Object.prototype;
142
- var slice = prototypeOfArray.slice;
143
- // Having a toString local variable name breaks in Opera so use _toString.
144
- var _toString = call.bind(prototypeOfObject.toString);
145
- var owns = call.bind(prototypeOfObject.hasOwnProperty);
146
-
147
- // If JS engine supports accessors creating shortcuts.
148
- var defineGetter;
149
- var defineSetter;
150
- var lookupGetter;
151
- var lookupSetter;
152
- var supportsAccessors;
153
- if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
154
- defineGetter = call.bind(prototypeOfObject.__defineGetter__);
155
- defineSetter = call.bind(prototypeOfObject.__defineSetter__);
156
- lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
157
- lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
158
- }
159
-
160
- //
161
- // Array
162
- // =====
163
- //
164
-
165
- // ES5 15.4.4.12
166
- // http://es5.github.com/#x15.4.4.12
167
- // Default value for second param
168
- // [bugfix, ielt9, old browsers]
169
- // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
170
- if ([1,2].splice(0).length != 2) {
171
- var array_splice = Array.prototype.splice;
172
- Array.prototype.splice = function(start, deleteCount) {
173
- if (!arguments.length) {
174
- return [];
175
- } else {
176
- return array_splice.apply(this, [
177
- start === void 0 ? 0 : start,
178
- deleteCount === void 0 ? (this.length - start) : deleteCount
179
- ].concat(slice.call(arguments, 2)))
180
- }
181
- };
182
- }
183
-
184
- // ES5 15.4.3.2
185
- // http://es5.github.com/#x15.4.3.2
186
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
187
- if (!Array.isArray) {
188
- Array.isArray = function isArray(obj) {
189
- return _toString(obj) == "[object Array]";
190
- };
191
- }
192
-
193
- // The IsCallable() check in the Array functions
194
- // has been replaced with a strict check on the
195
- // internal class of the object to trap cases where
196
- // the provided function was actually a regular
197
- // expression literal, which in V8 and
198
- // JavaScriptCore is a typeof "function". Only in
199
- // V8 are regular expression literals permitted as
200
- // reduce parameters, so it is desirable in the
201
- // general case for the shim to match the more
202
- // strict and common behavior of rejecting regular
203
- // expressions.
204
-
205
- // ES5 15.4.4.18
206
- // http://es5.github.com/#x15.4.4.18
207
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
208
-
209
- // Check failure of by-index access of string characters (IE < 9)
210
- // and failure of `0 in boxedString` (Rhino)
211
- var boxedString = Object("a"),
212
- splitString = boxedString[0] != "a" || !(0 in boxedString);
213
-
214
- if (!Array.prototype.forEach) {
215
- Array.prototype.forEach = function forEach(fun /*, thisp*/) {
216
- var object = toObject(this),
217
- self = splitString && _toString(this) == "[object String]" ?
218
- this.split("") :
219
- object,
220
- thisp = arguments[1],
221
- i = -1,
222
- length = self.length >>> 0;
223
-
224
- // If no callback function or if callback is not a callable function
225
- if (_toString(fun) != "[object Function]") {
226
- throw new TypeError(); // TODO message
227
- }
228
-
229
- while (++i < length) {
230
- if (i in self) {
231
- // Invoke the callback function with call, passing arguments:
232
- // context, property value, property key, thisArg object
233
- // context
234
- fun.call(thisp, self[i], i, object);
235
- }
236
- }
237
- };
238
- }
239
-
240
- // ES5 15.4.4.19
241
- // http://es5.github.com/#x15.4.4.19
242
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
243
- if (!Array.prototype.map) {
244
- Array.prototype.map = function map(fun /*, thisp*/) {
245
- var object = toObject(this),
246
- self = splitString && _toString(this) == "[object String]" ?
247
- this.split("") :
248
- object,
249
- length = self.length >>> 0,
250
- result = Array(length),
251
- thisp = arguments[1];
252
-
253
- // If no callback function or if callback is not a callable function
254
- if (_toString(fun) != "[object Function]") {
255
- throw new TypeError(fun + " is not a function");
256
- }
257
-
258
- for (var i = 0; i < length; i++) {
259
- if (i in self)
260
- result[i] = fun.call(thisp, self[i], i, object);
261
- }
262
- return result;
263
- };
264
- }
265
-
266
- // ES5 15.4.4.20
267
- // http://es5.github.com/#x15.4.4.20
268
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
269
- if (!Array.prototype.filter) {
270
- Array.prototype.filter = function filter(fun /*, thisp */) {
271
- var object = toObject(this),
272
- self = splitString && _toString(this) == "[object String]" ?
273
- this.split("") :
274
- object,
275
- length = self.length >>> 0,
276
- result = [],
277
- value,
278
- thisp = arguments[1];
279
-
280
- // If no callback function or if callback is not a callable function
281
- if (_toString(fun) != "[object Function]") {
282
- throw new TypeError(fun + " is not a function");
283
- }
284
-
285
- for (var i = 0; i < length; i++) {
286
- if (i in self) {
287
- value = self[i];
288
- if (fun.call(thisp, value, i, object)) {
289
- result.push(value);
290
- }
291
- }
292
- }
293
- return result;
294
- };
295
- }
296
-
297
- // ES5 15.4.4.16
298
- // http://es5.github.com/#x15.4.4.16
299
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
300
- if (!Array.prototype.every) {
301
- Array.prototype.every = function every(fun /*, thisp */) {
302
- var object = toObject(this),
303
- self = splitString && _toString(this) == "[object String]" ?
304
- this.split("") :
305
- object,
306
- length = self.length >>> 0,
307
- thisp = arguments[1];
308
-
309
- // If no callback function or if callback is not a callable function
310
- if (_toString(fun) != "[object Function]") {
311
- throw new TypeError(fun + " is not a function");
312
- }
313
-
314
- for (var i = 0; i < length; i++) {
315
- if (i in self && !fun.call(thisp, self[i], i, object)) {
316
- return false;
317
- }
318
- }
319
- return true;
320
- };
321
- }
322
-
323
- // ES5 15.4.4.17
324
- // http://es5.github.com/#x15.4.4.17
325
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
326
- if (!Array.prototype.some) {
327
- Array.prototype.some = function some(fun /*, thisp */) {
328
- var object = toObject(this),
329
- self = splitString && _toString(this) == "[object String]" ?
330
- this.split("") :
331
- object,
332
- length = self.length >>> 0,
333
- thisp = arguments[1];
334
-
335
- // If no callback function or if callback is not a callable function
336
- if (_toString(fun) != "[object Function]") {
337
- throw new TypeError(fun + " is not a function");
338
- }
339
-
340
- for (var i = 0; i < length; i++) {
341
- if (i in self && fun.call(thisp, self[i], i, object)) {
342
- return true;
343
- }
344
- }
345
- return false;
346
- };
347
- }
348
-
349
- // ES5 15.4.4.21
350
- // http://es5.github.com/#x15.4.4.21
351
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
352
- if (!Array.prototype.reduce) {
353
- Array.prototype.reduce = function reduce(fun /*, initial*/) {
354
- var object = toObject(this),
355
- self = splitString && _toString(this) == "[object String]" ?
356
- this.split("") :
357
- object,
358
- length = self.length >>> 0;
359
-
360
- // If no callback function or if callback is not a callable function
361
- if (_toString(fun) != "[object Function]") {
362
- throw new TypeError(fun + " is not a function");
363
- }
364
-
365
- // no value to return if no initial value and an empty array
366
- if (!length && arguments.length == 1) {
367
- throw new TypeError("reduce of empty array with no initial value");
368
- }
369
-
370
- var i = 0;
371
- var result;
372
- if (arguments.length >= 2) {
373
- result = arguments[1];
374
- } else {
375
- do {
376
- if (i in self) {
377
- result = self[i++];
378
- break;
379
- }
380
-
381
- // if array contains no values, no initial value to return
382
- if (++i >= length) {
383
- throw new TypeError("reduce of empty array with no initial value");
384
- }
385
- } while (true);
386
- }
387
-
388
- for (; i < length; i++) {
389
- if (i in self) {
390
- result = fun.call(void 0, result, self[i], i, object);
391
- }
392
- }
393
-
394
- return result;
395
- };
396
- }
397
-
398
- // ES5 15.4.4.22
399
- // http://es5.github.com/#x15.4.4.22
400
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
401
- if (!Array.prototype.reduceRight) {
402
- Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
403
- var object = toObject(this),
404
- self = splitString && _toString(this) == "[object String]" ?
405
- this.split("") :
406
- object,
407
- length = self.length >>> 0;
408
-
409
- // If no callback function or if callback is not a callable function
410
- if (_toString(fun) != "[object Function]") {
411
- throw new TypeError(fun + " is not a function");
412
- }
413
-
414
- // no value to return if no initial value, empty array
415
- if (!length && arguments.length == 1) {
416
- throw new TypeError("reduceRight of empty array with no initial value");
417
- }
418
-
419
- var result, i = length - 1;
420
- if (arguments.length >= 2) {
421
- result = arguments[1];
422
- } else {
423
- do {
424
- if (i in self) {
425
- result = self[i--];
426
- break;
427
- }
428
-
429
- // if array contains no values, no initial value to return
430
- if (--i < 0) {
431
- throw new TypeError("reduceRight of empty array with no initial value");
432
- }
433
- } while (true);
434
- }
435
-
436
- do {
437
- if (i in this) {
438
- result = fun.call(void 0, result, self[i], i, object);
439
- }
440
- } while (i--);
441
-
442
- return result;
443
- };
444
- }
445
-
446
- // ES5 15.4.4.14
447
- // http://es5.github.com/#x15.4.4.14
448
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
449
- if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
450
- Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
451
- var self = splitString && _toString(this) == "[object String]" ?
452
- this.split("") :
453
- toObject(this),
454
- length = self.length >>> 0;
455
-
456
- if (!length) {
457
- return -1;
458
- }
459
-
460
- var i = 0;
461
- if (arguments.length > 1) {
462
- i = toInteger(arguments[1]);
463
- }
464
-
465
- // handle negative indices
466
- i = i >= 0 ? i : Math.max(0, length + i);
467
- for (; i < length; i++) {
468
- if (i in self && self[i] === sought) {
469
- return i;
470
- }
471
- }
472
- return -1;
473
- };
474
- }
475
-
476
- // ES5 15.4.4.15
477
- // http://es5.github.com/#x15.4.4.15
478
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
479
- if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
480
- Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
481
- var self = splitString && _toString(this) == "[object String]" ?
482
- this.split("") :
483
- toObject(this),
484
- length = self.length >>> 0;
485
-
486
- if (!length) {
487
- return -1;
488
- }
489
- var i = length - 1;
490
- if (arguments.length > 1) {
491
- i = Math.min(i, toInteger(arguments[1]));
492
- }
493
- // handle negative indices
494
- i = i >= 0 ? i : length - Math.abs(i);
495
- for (; i >= 0; i--) {
496
- if (i in self && sought === self[i]) {
497
- return i;
498
- }
499
- }
500
- return -1;
501
- };
502
- }
503
-
504
- //
505
- // Object
506
- // ======
507
- //
508
-
509
- // ES5 15.2.3.14
510
- // http://es5.github.com/#x15.2.3.14
511
- if (!Object.keys) {
512
- // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
513
- var hasDontEnumBug = true,
514
- dontEnums = [
515
- "toString",
516
- "toLocaleString",
517
- "valueOf",
518
- "hasOwnProperty",
519
- "isPrototypeOf",
520
- "propertyIsEnumerable",
521
- "constructor"
522
- ],
523
- dontEnumsLength = dontEnums.length;
524
-
525
- for (var key in {"toString": null}) {
526
- hasDontEnumBug = false;
527
- }
528
-
529
- Object.keys = function keys(object) {
530
-
531
- if (
532
- (typeof object != "object" && typeof object != "function") ||
533
- object === null
534
- ) {
535
- throw new TypeError("Object.keys called on a non-object");
536
- }
537
-
538
- var keys = [];
539
- for (var name in object) {
540
- if (owns(object, name)) {
541
- keys.push(name);
542
- }
543
- }
544
-
545
- if (hasDontEnumBug) {
546
- for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
547
- var dontEnum = dontEnums[i];
548
- if (owns(object, dontEnum)) {
549
- keys.push(dontEnum);
550
- }
551
- }
552
- }
553
- return keys;
554
- };
555
-
556
- }
557
-
558
- //
559
- // Date
560
- // ====
561
- //
562
-
563
- // ES5 15.9.5.43
564
- // http://es5.github.com/#x15.9.5.43
565
- // This function returns a String value represent the instance in time
566
- // represented by this Date object. The format of the String is the Date Time
567
- // string format defined in 15.9.1.15. All fields are present in the String.
568
- // The time zone is always UTC, denoted by the suffix Z. If the time value of
569
- // this object is not a finite Number a RangeError exception is thrown.
570
- var negativeDate = -62198755200000,
571
- negativeYearString = "-000001";
572
- if (
573
- !Date.prototype.toISOString ||
574
- (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
575
- ) {
576
- Date.prototype.toISOString = function toISOString() {
577
- var result, length, value, year, month;
578
- if (!isFinite(this)) {
579
- throw new RangeError("Date.prototype.toISOString called on non-finite value.");
580
- }
581
-
582
- year = this.getUTCFullYear();
583
-
584
- month = this.getUTCMonth();
585
- // see https://github.com/kriskowal/es5-shim/issues/111
586
- year += Math.floor(month / 12);
587
- month = (month % 12 + 12) % 12;
588
-
589
- // the date time string format is specified in 15.9.1.15.
590
- result = [month + 1, this.getUTCDate(),
591
- this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
592
- year = (
593
- (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
594
- ("00000" + Math.abs(year))
595
- .slice(0 <= year && year <= 9999 ? -4 : -6)
596
- );
597
-
598
- length = result.length;
599
- while (length--) {
600
- value = result[length];
601
- // pad months, days, hours, minutes, and seconds to have two
602
- // digits.
603
- if (value < 10) {
604
- result[length] = "0" + value;
605
- }
606
- }
607
- // pad milliseconds to have three digits.
608
- return (
609
- year + "-" + result.slice(0, 2).join("-") +
610
- "T" + result.slice(2).join(":") + "." +
611
- ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
612
- );
613
- };
614
- }
615
-
616
-
617
- // ES5 15.9.5.44
618
- // http://es5.github.com/#x15.9.5.44
619
- // This function provides a String representation of a Date object for use by
620
- // JSON.stringify (15.12.3).
621
- var dateToJSONIsSupported = false;
622
- try {
623
- dateToJSONIsSupported = (
624
- Date.prototype.toJSON &&
625
- new Date(NaN).toJSON() === null &&
626
- new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
627
- Date.prototype.toJSON.call({ // generic
628
- toISOString: function () {
629
- return true;
630
- }
631
- })
632
- );
633
- } catch (e) {
634
- }
635
- if (!dateToJSONIsSupported) {
636
- Date.prototype.toJSON = function toJSON(key) {
637
- // When the toJSON method is called with argument key, the following
638
- // steps are taken:
639
-
640
- // 1. Let O be the result of calling ToObject, giving it the this
641
- // value as its argument.
642
- // 2. Let tv be toPrimitive(O, hint Number).
643
- var o = Object(this),
644
- tv = toPrimitive(o),
645
- toISO;
646
- // 3. If tv is a Number and is not finite, return null.
647
- if (typeof tv === "number" && !isFinite(tv)) {
648
- return null;
649
- }
650
- // 4. Let toISO be the result of calling the [[Get]] internal method of
651
- // O with argument "toISOString".
652
- toISO = o.toISOString;
653
- // 5. If IsCallable(toISO) is false, throw a TypeError exception.
654
- if (typeof toISO != "function") {
655
- throw new TypeError("toISOString property is not callable");
656
- }
657
- // 6. Return the result of calling the [[Call]] internal method of
658
- // toISO with O as the this value and an empty argument list.
659
- return toISO.call(o);
660
-
661
- // NOTE 1 The argument is ignored.
662
-
663
- // NOTE 2 The toJSON function is intentionally generic; it does not
664
- // require that its this value be a Date object. Therefore, it can be
665
- // transferred to other kinds of objects for use as a method. However,
666
- // it does require that any such object have a toISOString method. An
667
- // object is free to use the argument key to filter its
668
- // stringification.
669
- };
670
- }
671
-
672
- // ES5 15.9.4.2
673
- // http://es5.github.com/#x15.9.4.2
674
- // based on work shared by Daniel Friesen (dantman)
675
- // http://gist.github.com/303249
676
- if (!Date.parse || "Date.parse is buggy") {
677
- // XXX global assignment won't work in embeddings that use
678
- // an alternate object for the context.
679
- Date = (function(NativeDate) {
680
-
681
- // Date.length === 7
682
- function Date(Y, M, D, h, m, s, ms) {
683
- var length = arguments.length;
684
- if (this instanceof NativeDate) {
685
- var date = length == 1 && String(Y) === Y ? // isString(Y)
686
- // We explicitly pass it through parse:
687
- new NativeDate(Date.parse(Y)) :
688
- // We have to manually make calls depending on argument
689
- // length here
690
- length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
691
- length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
692
- length >= 5 ? new NativeDate(Y, M, D, h, m) :
693
- length >= 4 ? new NativeDate(Y, M, D, h) :
694
- length >= 3 ? new NativeDate(Y, M, D) :
695
- length >= 2 ? new NativeDate(Y, M) :
696
- length >= 1 ? new NativeDate(Y) :
697
- new NativeDate();
698
- // Prevent mixups with unfixed Date object
699
- date.constructor = Date;
700
- return date;
701
- }
702
- return NativeDate.apply(this, arguments);
703
- };
704
-
705
- // 15.9.1.15 Date Time String Format.
706
- var isoDateExpression = new RegExp("^" +
707
- "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
708
- // 6-digit extended year
709
- "(?:-(\\d{2})" + // optional month capture
710
- "(?:-(\\d{2})" + // optional day capture
711
- "(?:" + // capture hours:minutes:seconds.milliseconds
712
- "T(\\d{2})" + // hours capture
713
- ":(\\d{2})" + // minutes capture
714
- "(?:" + // optional :seconds.milliseconds
715
- ":(\\d{2})" + // seconds capture
716
- "(?:\\.(\\d{3}))?" + // milliseconds capture
717
- ")?" +
718
- "(" + // capture UTC offset component
719
- "Z|" + // UTC capture
720
- "(?:" + // offset specifier +/-hours:minutes
721
- "([-+])" + // sign capture
722
- "(\\d{2})" + // hours offset capture
723
- ":(\\d{2})" + // minutes offset capture
724
- ")" +
725
- ")?)?)?)?" +
726
- "$");
727
-
728
- var months = [
729
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
730
- ];
731
-
732
- function dayFromMonth(year, month) {
733
- var t = month > 1 ? 1 : 0;
734
- return (
735
- months[month] +
736
- Math.floor((year - 1969 + t) / 4) -
737
- Math.floor((year - 1901 + t) / 100) +
738
- Math.floor((year - 1601 + t) / 400) +
739
- 365 * (year - 1970)
740
- );
741
- }
742
-
743
- // Copy any custom methods a 3rd party library may have added
744
- for (var key in NativeDate) {
745
- Date[key] = NativeDate[key];
746
- }
747
-
748
- // Copy "native" methods explicitly; they may be non-enumerable
749
- Date.now = NativeDate.now;
750
- Date.UTC = NativeDate.UTC;
751
- Date.prototype = NativeDate.prototype;
752
- Date.prototype.constructor = Date;
753
-
754
- // Upgrade Date.parse to handle simplified ISO 8601 strings
755
- Date.parse = function parse(string) {
756
- var match = isoDateExpression.exec(string);
757
- if (match) {
758
- // parse months, days, hours, minutes, seconds, and milliseconds
759
- // provide default values if necessary
760
- // parse the UTC offset component
761
- var year = Number(match[1]),
762
- month = Number(match[2] || 1) - 1,
763
- day = Number(match[3] || 1) - 1,
764
- hour = Number(match[4] || 0),
765
- minute = Number(match[5] || 0),
766
- second = Number(match[6] || 0),
767
- millisecond = Number(match[7] || 0),
768
- // When time zone is missed, local offset should be used
769
- // (ES 5.1 bug)
770
- // see https://bugs.ecmascript.org/show_bug.cgi?id=112
771
- offset = !match[4] || match[8] ?
772
- 0 : Number(new NativeDate(1970, 0)),
773
- signOffset = match[9] === "-" ? 1 : -1,
774
- hourOffset = Number(match[10] || 0),
775
- minuteOffset = Number(match[11] || 0),
776
- result;
777
- if (
778
- hour < (
779
- minute > 0 || second > 0 || millisecond > 0 ?
780
- 24 : 25
781
- ) &&
782
- minute < 60 && second < 60 && millisecond < 1000 &&
783
- month > -1 && month < 12 && hourOffset < 24 &&
784
- minuteOffset < 60 && // detect invalid offsets
785
- day > -1 &&
786
- day < (
787
- dayFromMonth(year, month + 1) -
788
- dayFromMonth(year, month)
789
- )
790
- ) {
791
- result = (
792
- (dayFromMonth(year, month) + day) * 24 +
793
- hour +
794
- hourOffset * signOffset
795
- ) * 60;
796
- result = (
797
- (result + minute + minuteOffset * signOffset) * 60 +
798
- second
799
- ) * 1000 + millisecond + offset;
800
- if (-8.64e15 <= result && result <= 8.64e15) {
801
- return result;
802
- }
803
- }
804
- return NaN;
805
- }
806
- return NativeDate.parse.apply(this, arguments);
807
- };
808
-
809
- return Date;
810
- })(Date);
811
- }
812
-
813
- // ES5 15.9.4.4
814
- // http://es5.github.com/#x15.9.4.4
815
- if (!Date.now) {
816
- Date.now = function now() {
817
- return new Date().getTime();
818
- };
819
- }
820
-
821
-
822
- //
823
- // String
824
- // ======
825
- //
826
-
827
-
828
- // ES5 15.5.4.14
829
- // http://es5.github.com/#x15.5.4.14
830
- // [bugfix, chrome]
831
- // If separator is undefined, then the result array contains just one String,
832
- // which is the this value (converted to a String). If limit is not undefined,
833
- // then the output array is truncated so that it contains no more than limit
834
- // elements.
835
- // "0".split(undefined, 0) -> []
836
- if("0".split(void 0, 0).length) {
837
- var string_split = String.prototype.split;
838
- String.prototype.split = function(separator, limit) {
839
- if(separator === void 0 && limit === 0)return [];
840
- return string_split.apply(this, arguments);
841
- }
842
- }
843
-
844
- // ECMA-262, 3rd B.2.3
845
- // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
846
- // non-normative section suggesting uniform semantics and it should be
847
- // normalized across all browsers
848
- // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
849
- if("".substr && "0b".substr(-1) !== "b") {
850
- var string_substr = String.prototype.substr;
851
- /**
852
- * Get the substring of a string
853
- * @param {integer} start where to start the substring
854
- * @param {integer} length how many characters to return
855
- * @return {string}
856
- */
857
- String.prototype.substr = function(start, length) {
858
- return string_substr.call(
859
- this,
860
- start < 0 ? (start = this.length + start) < 0 ? 0 : start : start,
861
- length
862
- );
863
- }
864
- }
865
-
866
- // ES5 15.5.4.20
867
- // http://es5.github.com/#x15.5.4.20
868
- var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
869
- "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
870
- "\u2029\uFEFF";
871
- if (!String.prototype.trim || ws.trim()) {
872
- // http://blog.stevenlevithan.com/archives/faster-trim-javascript
873
- // http://perfectionkills.com/whitespace-deviations/
874
- ws = "[" + ws + "]";
875
- var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
876
- trimEndRegexp = new RegExp(ws + ws + "*$");
877
- String.prototype.trim = function trim() {
878
- if (this === undefined || this === null) {
879
- throw new TypeError("can't convert "+this+" to object");
880
- }
881
- return String(this)
882
- .replace(trimBeginRegexp, "")
883
- .replace(trimEndRegexp, "");
884
- };
885
- }
886
-
887
- //
888
- // Util
889
- // ======
890
- //
891
-
892
- // ES5 9.4
893
- // http://es5.github.com/#x9.4
894
- // http://jsperf.com/to-integer
895
-
896
- function toInteger(n) {
897
- n = +n;
898
- if (n !== n) { // isNaN
899
- n = 0;
900
- } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
901
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
902
- }
903
- return n;
904
- }
905
-
906
- function isPrimitive(input) {
907
- var type = typeof input;
908
- return (
909
- input === null ||
910
- type === "undefined" ||
911
- type === "boolean" ||
912
- type === "number" ||
913
- type === "string"
914
- );
915
- }
916
-
917
- function toPrimitive(input) {
918
- var val, valueOf, toString;
919
- if (isPrimitive(input)) {
920
- return input;
921
- }
922
- valueOf = input.valueOf;
923
- if (typeof valueOf === "function") {
924
- val = valueOf.call(input);
925
- if (isPrimitive(val)) {
926
- return val;
927
- }
928
- }
929
- toString = input.toString;
930
- if (typeof toString === "function") {
931
- val = toString.call(input);
932
- if (isPrimitive(val)) {
933
- return val;
934
- }
935
- }
936
- throw new TypeError();
937
- }
938
-
939
- // ES5 9.9
940
- // http://es5.github.com/#x9.9
941
- var toObject = function (o) {
942
- if (o == null) { // this matches both null and undefined
943
- throw new TypeError("can't convert "+o+" to object");
944
- }
945
- return Object(o);
946
- };
947
-
948
- }());