-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththere.is.only.jsboot.js
1570 lines (1397 loc) · 52.3 KB
/
there.is.only.jsboot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file "Strict" tester.
*
* This file is a build-system helper and can be safely ignored.
*
* @author WebItUp
* @version 0.4.0
*
* @license <a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPL</a>.
* @copyright All rights reserved <a href="http://www.webitup.fr">copyright WebItUp</a>
* @name strict.js
* @location https://github.com/jsBoot/jsboot.js/blob/master/src/strict.js#74-70c39446998be95596b03bc170b23bba337ce8b4
*/
(function() {
// fool linter
/*global whateverthenameofthis:true, console:false*/
'use strict';
try {
whateverthenameofthis = 'will crash';
try {
console.error('Browser doesn\'t support strict mode!!!');
}catch (e) {
}
}catch (e) {
}
}).apply(this);
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
v2.0.3 (c) Kyle Simpson
MIT License
*/
(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(a){var c=false;for(var b=0;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function t(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function I(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type)a.type=f.type;if(f.charset)a.charset=f.charset;if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded")g()}}a.src=c}else if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished)return;if(!a[u])p[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;t(d,b,"finished",f);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!p[b.src])p[b.src]={items:[],finished:false};g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else if(!h[j].finished){if(O(h[j]))continue;break}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a))a=a();if(!a)continue;if(H(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=s(a,{ready:false,ready_cb:T,finished:false,finished_cb:U});k.finished=false;k.scripts.push(a);S(g,a,k,(Q&&w));w=true;if(g[z])e.wait()}})(arguments[f],arguments[f])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}k=h[h.length-1]}else k=false;x();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){s(a,g);return e}}}m={setGlobalDefaults:function(a){s(a,l);return m},setOptions:function(){return v().setOptions.apply(null,arguments)},script:function(){return v().script.apply(null,arguments)},wait:function(){return v().wait.apply(null,arguments)},queueScript:function(){n[n.length]={type:"script",args:[].slice.call(arguments)};return m},queueWait:function(){n[n.length]={type:"wait",args:[].slice.call(arguments)};return m},runQueue:function(){var a=m,c=n.length,b=c,d;for(;--b>=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this);/**
* @file "Any" script loader wrapper.
*
* The sole purpose of this file is to wrap any "loader" library
* behind a unified interface.
* See links for approaches to embeded loader.
* This must work without any shim support, in most browsers.
*
* @see https://gist.github.com/603980
* @see http://www.dustindiaz.com/scriptjs/
*
* @author WebItUp <[email protected]> (http://www.webitup.fr/lab)
* @version 1.2.0
*
* @license <a href="http://en.wikipedia.org/wiki/MIT_License">MIT</a>.
* @copyright All rights reserved <a href="http://www.webitup.fr">copyright WebItUp <[email protected]> (http://www.webitup.fr/lab)</a>
* @name loader.js
* @location https://github.com/jsBoot/spitfire.js/blob/master/src/loader.js#111-0f8cc49a5082f7c6a0ca6ae84a9d585ad117fcd2
*/
/**
* Provides a crude "script loader" abstraction on top of whatever
* loader library is detected.
* Currently supports labjs and requirejs (headjs and yahoo are provided as well,
* with fewer test and possibly degraded performance / functionality).
* The API itself ressembles a lot that of LABJS.
*
* @module Spitfire/loader
* @summary Wrapper script "loader" singleton.
* @todo implement http://yepnopejs.com/
* @todo implement http://code.google.com/p/jsload/
*/
(function() {
/*jshint browser:true, maxcomplexity:11*/
/*global head:false, YUI:false, yepnope:false, requirejs:false, $LAB:false,
define:false, exports:false*/
'use strict';
// Get a backend
var backend;
// http://headjs.com/#api
if (typeof head != 'undefined')
backend = function() {
// Head has no "fork" feature
return function(uris, callback) {
uris.push(callback);
return head.js.apply(head.js, uris);
// head.js(file1 … fileN, [callback])
};
};
// http://yuilibrary.com/yui/docs/get/index.html
if (typeof YUI != 'undefined')
backend = function() {
var Y;
YUI().use('get', function(o) {
Y = o;
});
Y.Get.options.async = true;
return function() {
Y.Get.js.apply(Y.Get, arguments);
};
};
if (typeof yepnope != 'undefined')
backend = function() {
return function(uris, callback) {
var stamp = uris[uris.length - 1];
yepnope({load: uris, callback: function(url) {
if (stamp == url)
callback();
}});
};
};
// http://requirejs.org/
if (typeof requirejs != 'undefined')
backend = function() {
return function(uris, callback) {
requirejs(uris, callback);
};
};
var PvLoader;
// http://labjs.com/documentation.php
// LAB override entirely the PvLoader itself - not a backend per-se
if (typeof $LAB != 'undefined')
PvLoader = function() {
var q = $LAB.sandbox();
this.script = function(uri) {
q = q.script(uri);
return this;
};
this.wait = function(cbk) {
// Lab has an irritable anus
if (cbk)
q = q.wait(cbk);
else
q = q.wait();
return this;
};
};
/* backend = function(){
var q = $LAB.sandbox();
q.mark = Math.random(1);
return function(uris, callback) {
var mark = q.mark;
for(var x = 0; x < uris.length; x++)
q = q.script(uris[x]);
// while (uris.length)
// q = q.script(uris.shift());
q = q.wait(callback);
q.mark = mark;
};
};*/
if (!PvLoader)
PvLoader = function() {
var linger = null;
var toLoad = [];
var currentLoading = false;
var bck = backend();
var lingerEnd = function() {
if (currentLoading)
return;
currentLoading = toLoad.shift();
if (!currentLoading)
return;
if (!currentLoading.uris.length) {
var cl = currentLoading.callback;
currentLoading = false;
if (cl)
cl();
lingerEnd();
return;
}
bck(currentLoading.uris, function(err) {
var cl = currentLoading.callback;
currentLoading = false;
if (cl)
cl(err);
lingerEnd();
});
};
/**
* Allows to request the loading of a given script specified by an uri.
* The loading is always parallelized (if the underlying library supports it)
* though the evaluation is parallelized between calls to wait.
* Only javascript files can be loaded this way.
*
* @function module:Spitfire/loader.script
* @summary Main loader function.
* @see module:Spitfire/loader.wait
* @example
* loader.script("someuri.js");
* loader.script("otheruri.js");
* @example
* loader.script("someuri.js").script("otheruri.js");
*
* @param {String} uri [description].
* @returns {module:Spitfire/loader} Returns the loader so that calls can be chained.
*/
this.script = function(uri) {
if (linger)
clearTimeout(linger);
if (!toLoad.length)
toLoad.push({uris: [], callback: false});
toLoad[toLoad.length - 1].uris.push(uri);
linger = setTimeout(lingerEnd, 1);
return this;
};
/**
* This method allows to specify "groups" of scripts that will be evaluated
* after each other.
* There is no guarantee of any sort on the evaluation order inside a group.
* Note that some backend libraries don't support this properly and instead
* this blocks *loading* to guarantee the execution order (which is bad).
*
* @function module:Spitfire/loader.wait
* @summary Wait for previous scripts to evaluate.
* @see module:Spitfire/loader.script
* @example
* loader.script("someuri.js");
* loader.script("otheruri.js");
* loader.wait(function(){
* // both scripts have been executed
* });
* @example
* loader.script("uri.js")
* .wait()
* .script("another.js")// when another executes, uri has been executed
* .wait(function(){
* // both have been executed
* });
* @param {Function} [callback] Function to be called when all previous scripts
* have evaluated.
* @returns {module:Spitfire/loader} Returns the loader so that calls can be chained.
*/
this.wait = function(callback) {
// Grab the last waiting stack, if any
var me = toLoad.length ? toLoad[toLoad.length - 1] : false;
// If currently loading, that's our client
if (currentLoading)
me = currentLoading;
// If we have no stack and still a calback, call it now
if (!me) {
if (callback)
callback();
return this;
}
// If the stack doesn't have a callback, that's us
if (!me.callback) {
me.callback = callback;
toLoad.push({uris: [], callback: false});
}else {
// Otherwise, it's just a chained callback - add it to a blank stack
toLoad.push({uris: [], callback: callback});
}
return this;
};
};
/**
* Allows to get a new, separate loader instance
*
* @example
* // Two different, unrelated loading queues.
* var ld2 = loader.fork();
* loader.script('some.js').wait();
* ld2.script('some2.js').wait();
* @function module:Spitfire/loader.fork
* @summary Provides a new loading stack
* @returns {module:Spitfire/loader} Returns a new loader instance
*/
PvLoader.prototype.fork = function() {
return new PvLoader();
};
/**
* This is meant as a helper to resolve an uri against that of another script, and does return
* the "base" uri of a (previously loaded) script matching a name pattern.
*
* @todo Note this is NOT guaranteed to work - the document may NOT be ready at the time
* this is used...
* Correct approach would be to timeout and repeat this in case it returns false.
*
* @function module:Spitfire/loader.base
* @summary Get the base uri of the first script matching a name pattern
* @param {String} pattern Pattern to match the script from which to extract a base uri.
* @returns {String} Base uri of the matched script.
*/
PvLoader.prototype.base = function(pattern) {
var c = document.getElementsByTagName('script');
var m;
var re = new RegExp(pattern);
// for(var x = 0, it; (x < c.length) && (it = c[x].src); x++){
for (var x = 0, it; x < c.length; (it = c[x].getAttribute('src')), x++) {
if (it && re.test(it)) {
m = it.split('/');
m.pop();
m = m.join('/') || './';
break;
}
}
return m || null;
};
var idx = 1;
var hook = null;
/**
* This allows to load stylesheets.
* It works by embedding additional link rel into the document head.
* Note that the order will be respected, and that they will be appended
* AFTER anything already present in the head.
*
* @function module:Spitfire/loader.style
* @todo See gulliver - this may fail in subtle ways
* @summary A simple stylesheet loader.
* @param {String} url Url of the stylesheet.
* @param {String} [media] Optional media that the stylesheet applies for.
* @returns {undefined}
*/
PvLoader.prototype.style = function(url, media) {
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('link');
s.setAttribute('type', 'text/css');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('data-spitfire-index', idx);
if (media)
s.setAttribute('media', media);
s.setAttribute('href', url);
if (!hook)
hook = h.lastChild;
// && h.firstChild.nextSibling;
if (!hook || !hook.nextSibling)
h.appendChild(s);
else
h.insertBefore(s, hook.nextSibling);
hook = s;
idx++;
};
/*
* =========================
* AMD / noAMD dummy pattern
* Asynchronous module loaders, CommonJS environments, web
* browsers, and JavaScript engines. Credits: Oyvind Sean Kinsey.
* =========================
*/
// Pattern from JSON3
// Export for asynchronous module loaders, CommonJS environments, web browsers, and JavaScript
// engines.
var isLoader = typeof define === 'function' && define.amd;
var root = typeof exports == 'object' && exports;
if (isLoader || root) {
if (isLoader) {
// Export for asynchronous module loaders. The namespace is
// redefined because module loaders do not provide the "exports" object.
define('Spitfire/loader', new PvLoader());
}
} else {
if (!('Spitfire' in this))
this.Spitfire = {};
this.Spitfire.loader = new PvLoader();
}
/**
* =========================
* End of dummy pattern
* =========================
*/
}).apply(this);
/**
* @file
* @summary Set of browser features tests, shims, and minimalistic testing API.
*
* @see http://afarkas.github.com/webshim/demos/demos/json-storage.html
* @see http://code.google.com/p/html5-shims/wiki/LinksandResources
* @see https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills
* @see https://github.com/bestiejs/
* @see http://es5.github.com/#x15.4.4.13
*
* @author WebItUp <[email protected]> (http://www.webitup.fr/lab)
* @version 1.2.0
*
* @license <a href="http://en.wikipedia.org/wiki/MIT_License">MIT</a>.
* @copyright All rights reserved <a href="http://www.webitup.fr">copyright WebItUp <[email protected]> (http://www.webitup.fr/lab)</a>
* @name shimer.js
* @location https://github.com/jsBoot/spitfire.js/blob/master/src/shimer.js#111-0f8cc49a5082f7c6a0ca6ae84a9d585ad117fcd2
*/
(function() {
/*jshint evil:true, browser:true, maxstatements:50,maxcomplexity:60*/
/*global define:false, exports:false*/
'use strict';
/**
* The idea here is to provide tests to detect browsers missing features
* and bugs, and propose "shims" uris to be loaded.
* To some extent, this ressembles modernizr - except it focuses on core
* features (eg: ES5 language features), and does provide accompanying shims.
* Currently provided are large parts of ES5, JSON, XHR, geolocation, console
* and localStorage.
*
* @module Spitfire
* @summary Provides shiming test/patching environment.
*/
/*
* =========================
* AMD / noAMD dummy pattern
* Asynchronous module loaders, CommonJS environments, web
* browsers, and JavaScript engines. Credits: Oyvind Sean Kinsey.
* =========================
*/
var isLoader = typeof define === 'function' && define.amd;
var root = typeof exports == 'object' && exports;
// Pattern from JSON3
// Export for asynchronous module loaders, CommonJS environments, web browsers, and JavaScript
// engines.
if (isLoader || root) {
if (isLoader) {
// Export for asynchronous module loaders. The namespace is
// redefined because module loaders do not provide the "exports" object.
define('Spitfire', (root = {}));
}
} else {
// Export for browsers and JavaScript engines.
root = this.Spitfire || (this.Spitfire = {});
}
/*
* =========================
* End of dummy pattern
* =========================
*/
var shimsTest = {};
var toBeLoaded = [];
/**
* This describes what a test object should look like.
* This is NOT an actual, instanciable class.
* @todo Tests should be functions instead of booleans
* @class module:Spitfire.Test
* @abstract
* @extends {Object}
*/
/**
* Whether or not the environment needs to shim that functionality.
* @member module:Spitfire.Test.test
* @type {Boolean}
*/
/**
* Optional uri to the file providing the actual shim.
* This can be left undefined if a functional patch is provided.
* @see module:Spitfire.Test.patch
* @member module:Spitfire.Test.uri
* @type {String}
*/
/**
* An optional function providing the actual shim.
* If specified, will be favored over the uri.
* @member module:Spitfire.Test.patch
* @type {Function}
*/
/**
* Adds a newly created test to a shim category.
* Said category can then be "use"-d to request this to be shimed.
* Predefined categories are specified by this.SAFE (always loaded) and this.UNSAFE.
*
* @function module:Spitfire.add
* @summary Adds a test.
* @see module:Spitfire.use
* @see module:Spitfire.Test
* @see module:Spitfire.SAFE
* @see module:Spitfire.UNSAFE
* @example
* // Provide a conditional shim to be loaded as part of the SAFE batch
* Spitfire.add({
* test: !Function.prototype.bind,
* uri: 'relative_shim_uri_to_bind.js'
* }, Spitfire.SAFE);
* @example
* // Provide an always-loaded shim, in its own category
* Spitfire.add({
* test: true,
* uri: 'json3.js'
* }, Spitfire.JSON);
* @summary Allows to add a test in a category
* @param {module:Spitfire.Test} testObject The test object.
* @param {String} category The category to which this shim belong.
* @returns {undefined}
*/
root.add = function(testObject, category) {
if (!(category in shimsTest))
shimsTest[category] = [];
shimsTest[category].push(testObject);
};
/**
* For a given category, request that patchable shims are executed
* and that loadable shims uris be returned once "boot" is called.
* Note that the SAFE category is ALWAYS requested.
* Predefined categories consist of UNSAFE, XHR, and JSON
*
* @function module:Spitfire.use
* @example
* Spitfire.use(Spitfire.UNSAFE);
* var uris = Spitfire.boot();
* @see module:Spitfire.boot
* @see module:Spitfire.UNSAFE
* @see module:Spitfire.XHR
* @see module:Spitfire.JSON
* @summary Requests a category of shims
* @throws INVALID_CATEGORY if the requested category does not have any associated
* tests.
* @param {String} cat Category to load.
* @returns {undefined}
*/
root.use = function(cat) {
if (!cat || !(cat in shimsTest))
throw 'INVALID_CATEGORY';
for (var x = 0; x < shimsTest[cat].length; x++)
toBeLoaded.push(shimsTest[cat][x]);
};
/**
* Once categories have been requested via the "use" method, calling boot
* evaluate every test and returns the list of uris to load.
* Shims directly providing functionality via "patch" are executed before this
* returns.
* Note that the SAFE category is ALWAYS loaded.
*
* @function module:Spitfire.boot
* @example
* Spitfire.use(Spitfire.UNSAFE);
* // Just do it...
* var uris = Spitfire.boot();
* @summary Give uris to shims.
* @see module:Spitfire.use
* @param {Boolean} [useFull=false] If true, request non-minified versions of the shims.
* Useful for debugging only.
* @returns Array<String> An array of uris to load in order to obtain the shims.
*/
root.boot = function(useFull) {
var uris = [];
for (var x = 0, shim; (x < toBeLoaded.length) && (shim = toBeLoaded[x]); x++) {
if (shim.test) {
if (shim.patch)
shim.patch();
else
uris.push('burnscars/' + shim.uri + (useFull ? '.js' : '-min.js'));
}
}
return uris;
};
/**
* Enforces the loading of a shimed XHR, enforcing identical functionality
* in any browser, regardless of the current support.
* This is useful if you want to be DEAD SURE it will behave the same.
* Know that XHR is very buggy and present numerous and wide discrepancies
* between browsers, or even browsers versions - not only in IE.
*
* @member module:Spitfire.XHR
* @constant
* @type {String}
*/
root.XHR = 'xhr';
root.add({test: true, uri: 'xmlhttprequest'}, root.XHR);
/**
* Enforces the loading of a shimed JSON, enforcing identical functionality
* in any browser, regardless of the current support.
* This is useful if you want to be DEAD SURE it will behave the same.
* JSON and related functions are very buggy and have wide discrepancies between browsers.
*
* @member module:Spitfire.JSON
* @constant
* @type {String}
*/
root.JSON = 'json';
root.add({test: true, uri: 'json3'}, root.JSON);
/**
* Requests that "unsafe" shims are loaded.
* These are shims that don't actually provide real functionality, just create named methods
* to allow for ES5 code to actually *run* without errors.
* The drawback is that it will break feature detection in third-party libraries without
* actually providing functionality... Careful with that.
* @member module:Spitfire.UNSAFE
* @constant
* @type {String}
*/
root.UNSAFE = 'unsafe';
root.add({
test: !Function.isGenerator,
uri: 'function.isgenerator'
}, root.UNSAFE);
root.add({
test:
!Object.preventExtensions ||
!Object.isSealed ||
!Object.isFrozen ||
!Object.seal ||
!Object.freeze,
uri: 'es5.shim.unsafe'
}, root.UNSAFE);
/**
* This is the safe category, that should be used for any shim that is slick, does provide
* complete functionality for a given section.
* @member module:Spitfire.SAFE
* @constant
* @type {String}
*/
root.SAFE = 'safe';
/**
* ES5 provided shims
*/
var arrayTests =
([].unshift('test') === undefined) ||
([1, 2].splice(0).length != 2) ||
!Array.isArray ||
!Array.prototype.forEach ||
!Array.prototype.map ||
!Array.prototype.filter ||
!Array.prototype.every ||
!Array.prototype.some ||
!Array.prototype.reduce ||
!Array.prototype.reduceRight ||
!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1) ||
!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1);
var functionTests = !Function.prototype.bind;
var objectTests = !Object.keys;
var dateTests = !Date.now ||
!Date.prototype.toISOString || !Date.parse ||
/* isNaN(Date.parse("2000-01-01T00:00:00.000Z")) ||
(Date.parse('+275760-09-13T00:00:00.000Z') !== 8.64e15) ||*/
(new Date(-62198755200000).toISOString().indexOf('-000001') === -1) ||
(function() {
var dateToJSONIsSupported = false;
try {
dateToJSONIsSupported = (
Date.prototype.toJSON &&
new Date(NaN).toJSON() === null &&
new Date(-62198755200000).toJSON().indexOf('-000001') !== -1 &&
Date.prototype.toJSON.call({ // generic
toISOString: function() {
return true;
}
})
);
} catch (e) {
}
return !dateToJSONIsSupported;
})();
var stringTests = !!'0'.split(void 0, 0).length ||
(''.substr && '0b'.substr(-1) !== 'b') ||
!String.prototype.trim ||
'\x09\x0A\x0B\x0C\x0D \xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
'\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
'\u2029\uFEFF'.trim();
var es5Tests = arrayTests || functionTests || objectTests || dateTests || stringTests;
// Although in ES5-SHIM, most modern browsers unfortunately want this
/* root.add({
test: !es5Tests && (!String.prototype.trim ||
'\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
'\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
'\u2029\uFEFF'.trim()),
patch: function(){
var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
'\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
'\u2029\uFEFF';
ws = '[' + ws + ']';
var trimBeginRegexp = new RegExp('^' + ws + ws + '*'),
trimEndRegexp = new RegExp(ws + ws + '*$');
String.prototype.trim = function trim() {
if (this === undefined || this === null) {
throw new TypeError("can't convert " + this + ' to object');
}
return String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
};
}
}, root.SAFE);
*/
// WebKit modern bugs... patched by ES5-shim, but we want it in there to avoid it
/* root.add({
test: !!'0'.split(void 0, 0).length,
patch: function(){
var string_split = String.prototype.split;
String.prototype.split = function(separator, limit) {
if(separator === void 0 && limit === 0)return [];
return string_split.apply(this, arguments);
}
}
}, root.SAFE);
*/
// Present in ES5-SHAM, which we don't always want while this is useful
root.add({
test: Object.freeze && (function() {
try {
Object.freeze(function() {});
} catch (exception) {
return true;
}
return false;
})(),
patch: function() {
Object.freeze = (function freeze(freezeObject) {
return function freeze(object) {
if (typeof object == 'function') {
return object;
} else {
return freezeObject(object);
}
};
})(Object.freeze);
}
}, root.SAFE);
// Needed about everywhere
root.add({
test: (typeof TypeError == 'undefined'),
patch: function() {
window.TypeError = Error || function() {};
}
}, root.SAFE);
/**
* Standalone, other tests
*/
// ==========
// Objects - although these are available in es5-sham,
// they are bundled with other, riskier shams, so let's keep it
// separate for now
// ==========
root.add({
test: !Object.getPrototypeOf,
uri: 'object.getprototypeof'
}, root.SAFE);
root.add({
test: !Object.getOwnPropertyDescriptor,
uri: 'object.getownpropertydescriptor'
}, root.SAFE);
root.add({
test: !Object.getOwnPropertyNames,
uri: 'object.getownpropertynames'
}, root.SAFE);
root.add({
test: !Object.create,
uri: 'object.create'
}, root.SAFE);
root.add({
test: !Object.defineProperty,
uri: 'object.defineproperty'
}, root.SAFE);
root.add({
test: !Object.defineProperties,
uri: 'object.defineproperties'
}, root.SAFE);
root.add({
test: !Object.isExtensible,
uri: 'object.isextensible'
}, root.SAFE);
// ==========
// Events
// ==========
root.add({
test: !window.addEventListener,
uri: 'events'
}, root.SAFE);
// ==========
// Localstorage
// ==========
root.add({
test: !window.localStorage,
uri: 'localstorage'
}, root.SAFE);
// ==========
// Geolocation
// ==========
root.add({
test: !navigator.geolocation,
uri: 'geolocation'
}, root.SAFE);
/**
* Provided by third-party
*/
// ==========
// ES5
// ==========
root.add({
test: es5Tests,
uri: 'es5.shim'
}, root.SAFE);
// ==========
// JSON
// ==========
root.add({
test: !window.JSON,
uri: 'json3'
}, root.SAFE);
// ==========
// XHR
// ==========
root.add({
test: !window.XMLHttpRequest,
uri: 'xmlhttprequest'
}, root.SAFE);
// ==========
// Console
// ==========
root.add({
test: !window.console || eval('/*@cc_on @_jscript_version <= 9@*/') || !(function() {
var ok = true;
var props = [
'log', 'debug', 'info', 'warn', 'error', 'assert' /*, 'dir', 'dirxml', 'exception', 'time',
'timeEnd', 'table',
'clear', 'trace', 'group', 'groupCollapsed', 'groupEnd', 'timeStamp', 'profile',
'profileEnd', 'count'*/
];
for (var x = 0; x < props.length; x++)
ok &= !!window.console[props[x]];
return ok;
})(),
uri: 'console'
}, root.SAFE);
// Use all safe shims by default
root.use(root.SAFE);
// ==========
// Request animation frame
// ==========
root.add({
test: !window.requestAnimationFrame || !window.cancelAnimationFrame,
uri: 'animationframe'
}, root.SAFE);
root.add({
test: !Array.from || !Array.of,
uri: 'es6.array'
}, root.SAFE);
root.add({
// XXX incomplete
test: !Math.acosh || !Math.asinh || !Math.atanh || !Math.cosh || !Math.sinh || !Math.tanh ||
!Math.expm1,
uri: 'es6.math'
}, root.SAFE);
root.add({
test: !Number.isFinite || !Number.isInteger || !Number.isNaN || !Number.toInteger,
uri: 'es6.number'
}, root.SAFE);
root.add({
test: !Object.getOwnPropertyDescriptors || !Object.getPropertyDescriptor ||
!Object.getPropertyNames || !Object.is || !Object.isnt,
uri: 'es6.object'
}, root.SAFE);
root.add({
test: !String.prototype.repeat || !String.prototype.startsWith ||
!String.prototype.endsWith || !String.prototype.contains,
uri: 'es6.string'
}, root.SAFE);
// IE at large doesn't support additional arguments on settimeout.
// This can't be shimed independtly considering we work synchronously for now with loader
// AND XXX BEWARE - this means that setTimeout can't be used in following code
// BEFORE this specific setTimeout runs out
setTimeout(function(a) {
if (!a) {
var deref = window.setTimeout;
window.setTimeout = function(callback, delay) {
var a = Array.prototype.slice.call(arguments);
a.shift();
a.shift();
var cl = function() {
callback.apply(this, a);
};
deref(cl, delay);
};
}
}, 1, true);
}).apply(this);
// http://www.calormen.com/polyfill/
// https://github.com/mozilla/shumway
// Check for modernizr once again as well
// https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills
// This is a nutshell meant to be aggregated AFTER loader-lab.js and spitfire.js
(function() {
/*jshint browser:true,evil:true*/
/*global Spitfire:false, define:false, exports:false*/
'use strict';
// List of available static resources to be served via getPack
// var statics = '{SPIT-STATICS}';
/**
* Hash-passed parameters handling
*/
// Default parameters values
var params = {
notminified: false,
debug: false,
trunk: false,
experimental: false,
base: null
};
// Extract parameters from script uri
var ref = document.getElementsByTagName('script');
for (var i = 0, tup, item; (i < ref.length); i++) {
item = ref[i].src;
if (/there\.is\.only\.jsboot/.test(item)) {
// Have a base on us - still, allow for deplaced routing
params.base = item.replace(/[^\/]+(?:[#]+)?$/, '');
params.notminified = !/-min/.test(item);
if (/#/.test(item)) {
tup = item.split('#').pop().split(',');
while (tup.length)
params[tup.pop()] = true;
}
break;
}
}
// Debug implies not minified
params.notminified = params.notminified || params.debug;
// Dumb-as-shit closure for AMD fuckwadry until gister gets in and we can save using all this crap
var beWise = function(ld, shim) {
/**
* Abstract spitfire loader
*/
var insertThing = function(url, minified) {
if (minified)
url = url.replace(/(\.[^.]+$)/, '-min$1');
var t = url.match(/\.([^.]+)$/);
if (t)
t = t.pop().toLowerCase();
switch (t) {
case 'js':
// XXX failure to load should STOP
ld.script(url);
break;
case 'css':
// XXX media?
ld.style(url, 'all');
break;
default:
// Make jshint happy...
if (true)