forked from stealjs/steal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steal.js
3219 lines (2997 loc) · 91.1 KB
/
steal.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
// steal is a resource loader for JavaScript. It is broken into the following parts:
//
// - Helpers - basic utility methods used internally
// - AOP - aspect oriented code helpers
// - Deferred - a minimal deferred implementation
// - Uri - methods for dealing with urls
// - Api - steal's API
// - Module - an object that represents a resource that is loaded and run and has dependencies.
// - Type - a type systems used to load and run different types of resources
// - Packages - used to define packages
// - Extensions - makes steal pre-load a type based on an extension (ex: .coffee)
// - Mapping - configures steal to load resources in a different location
// - Startup - startup code
// - jQuery - code to make jQuery's readWait work
// - Error Handling - detect scripts failing to load
// - Has option - used to specify that one resources contains multiple other resources
// - Window Load - API for knowing when the window has loaded and all scripts have loaded
// - Interactive - Code for IE
// - Options -
(function (undefined) {
var requestFactory = function () {
return h.win.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
};
// ## Helpers ##
// The following are a list of helper methods used internally to steal
var h = {
// check that we have a document,
win: (function () {
return this
}).call(null),
// a jQuery-like $.each
each: function (o, cb) {
var i, len;
// weak array detection, but we only use this internally so don't
// pass it weird stuff
if (typeof o.length == 'number') {
for (i = 0, len = o.length; i < len; i++) {
cb.call(o[i], i, o[i], o)
}
} else {
for (i in o) {
if (o.hasOwnProperty(i)) {
cb.call(o[i], i, o[i], o)
}
}
}
return o;
},
// adds the item to the array only if it doesn't currently exist
uniquePush: function (arr, item) {
if (h.inArray(arr, item) === -1) {
return arr.push(item)
}
},
// if o is a string
isString: function (o) {
return typeof o == "string";
},
// if o is a function
isFn: function (o) {
return typeof o == "function";
},
// dummy function
noop: function () {},
endsInSlashRegex: /\/$/,
// creates an element
createElement: function (nodeName) {
return h.doc.createElement(nodeName)
},
// creates a script tag
scriptTag: function () {
var start = h.createElement("script");
start.type = "text/javascript";
return start;
},
// minify-able verstion of getElementsByTagName
getElementsByTagName: function (tag) {
return h.doc.getElementsByTagName(tag);
},
// A function that returns the head element
// creates and caches the lookup for faster
// performance.
head: function () {
var hd = h.getElementsByTagName("head")[0];
if (!hd) {
hd = h.createElement("head");
h.docEl.insertBefore(hd, h.docEl.firstChild);
}
// replace head so it runs fast next time.
h.head = function () {
return hd;
}
return hd;
},
// extends one object with another
extend: function (d, s) {
// only extend if we have something to extend
s && h.each(s, function (k) {
if (s.hasOwnProperty(k)) {
d[k] = s[k];
}
});
return d;
},
// makes an array of things, or a mapping of things
map: function (args, cb) {
var arr = [];
h.each(args, function (i, str) {
arr.push(cb ? (h.isString(cb) ? str[cb] : cb.call(str, str)) : str)
});
return arr;
},
// ## AOP ##
// Aspect oriented programming helper methods are used to
// weave in functionality into steal's API.
// calls `before` before `f` is called.
// steal.complete = before(steal.complete, f)
// `changeArgs=true` makes before return the same args
before: function (f, before, changeArgs) {
return changeArgs ?
function before_changeArgs() {
return f.apply(this, before.apply(this, arguments));
} : function before_args() {
before.apply(this, arguments);
return f.apply(this, arguments);
}
},
// returns a function that calls `after`
// after `f`
after: function (f, after, changeRet) {
return changeRet ?
function after_CRet() {
return after.apply(this, [f.apply(this, arguments)].concat(h.map(arguments)));
} : function after_Ret() {
var ret = f.apply(this, arguments);
after.apply(this, arguments);
return ret;
}
},
/**
* Performs an XHR request
* @param {Object} options
* @param {Function} success
* @param {Function} error
*/
request: function (options, success, error) {
var request = new requestFactory(),
contentType = (options.contentType || "application/x-www-form-urlencoded; charset=utf-8"),
clean = function () {
request = check = clean = null;
},
check = function () {
var status;
if (request && request.readyState === 4) {
status = request.status;
if (status === 500 || status === 404 || status === 2 || request.status < 0 || (!status && request.responseText === "")) {
error && error(request.status);
} else {
success(request.responseText);
}
clean();
}
};
request.open("GET", options.src + '', !(options.async === false));
request.setRequestHeader("Content-type", contentType);
if (request.overrideMimeType) {
request.overrideMimeType(contentType);
}
request.onreadystatechange = check;
try {
request.send(null);
}
catch (e) {
if (clean) {
console.error(e);
error && error();
clean();
}
}
},
matchesId: function (loc, id) {
if (loc === "*") {
return true;
} else if (id.indexOf(loc) === 0) {
return true;
}
},
// are we in production
stealCheck: /steal\.(production\.)?js.*/,
// get script that loaded steal
getStealScriptSrc: function () {
if (!h.doc) {
return;
}
var scripts = h.getElementsByTagName("script"),
script;
// find the steal script and setup initial paths.
h.each(scripts, function (i, s) {
if (h.stealCheck.test(s.src)) {
script = s;
}
});
return script;
},
inArray: function (arr, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return i;
}
}
return -1;
},
addEvent: function (elem, type, fn) {
if (elem.addEventListener) {
elem.addEventListener(type, fn, false);
} else if (elem.attachEvent) {
elem.attachEvent("on" + type, fn);
} else {
fn();
}
},
useIEShim: false
}
h.doc = h.win.document;
h.docEl = h.doc && h.doc.documentElement;
h.support = {
// does onerror work in script tags?
error: h.doc && (function () {
var script = h.scriptTag();
script.onerror = h.noop;
return h.isFn(script.onerror) || "onerror" in script;
})(),
// If scripts support interactive ready state.
// This is tested later.
interactive: false,
// use attachEvent for event listening (IE)
attachEvent: h.doc && h.scriptTag().attachEvent
}
// steal's deferred library. It is used through steal
// to support jQuery like API for file loading.
var Deferred = function (func) {
if (!(this instanceof Deferred)) return new Deferred();
// arrays for `done` and `fail` callbacks
this.doneFuncs = [];
this.failFuncs = [];
this.resultArgs = null;
this.status = "";
// check for option function: call it with this as context and as first
// parameter, as specified in jQuery api
func && func.call(this, this);
}
Deferred.when = function () {
var args = h.map(arguments);
if (args.length < 2) {
var obj = args[0];
if (obj && (h.isFn(obj.isResolved) && h.isFn(obj.isRejected))) {
return obj;
} else {
return Deferred().resolve(obj);
}
} else {
var df = Deferred(),
done = 0,
// resolve params: params of each resolve, we need to track down
// them to be able to pass them in the correct order if the master
// needs to be resolved
rp = [];
h.each(args, function (j, arg) {
arg.done(function () {
rp[j] = (arguments.length < 2) ? arguments[0] : arguments;
if (++done == args.length) {
df.resolve.apply(df, rp);
}
}).fail(function () {
df.reject(arguments);
});
});
return df;
}
}
// call resolve functions
var resolveFunc = function (type, status) {
return function (context) {
var args = this.resultArgs = (arguments.length > 1) ? arguments[1] : [];
return this.exec(context, this[type], args, status);
}
},
doneFunc = function (type, status) {
return function () {
var self = this;
h.each(arguments, function (i, v, args) {
if (!v) return;
if (v.constructor === Array) {
args.callee.apply(self, v)
} else {
// immediately call the function if the deferred has been resolved
if (self.status === status) v.apply(this, self.resultArgs || []);
self[type].push(v);
}
});
return this;
}
};
h.extend(Deferred.prototype, {
resolveWith: resolveFunc("doneFuncs", "rs"),
rejectWith: resolveFunc("failFuncs", "rj"),
done: doneFunc("doneFuncs", "rs"),
fail: doneFunc("failFuncs", "rj"),
always: function () {
var args = h.map(arguments);
if (args.length && args[0]) this.done(args[0]).fail(args[0]);
return this;
},
then: function () {
var args = h.map(arguments);
// fail function(s)
if (args.length > 1 && args[1]) this.fail(args[1]);
// done function(s)
if (args.length && args[0]) this.done(args[0]);
return this;
},
isResolved: function () {
return this.status === "rs";
},
isRejected: function () {
return this.status === "rj";
},
reject: function () {
return this.rejectWith(this, arguments);
},
resolve: function () {
return this.resolveWith(this, arguments);
},
exec: function (context, dst, args, st) {
if (this.status !== "") return this;
this.status = st;
h.each(dst, function (i, d) {
d.apply(context, args);
});
return this;
}
});
// ## HELPER METHODS FOR DEFERREDS
// Used to call a method on an object or resolve a
// deferred on it when a group of deferreds is resolved.
//
// whenEach(resources,"complete",resource,"execute")
var whenEach = function (arr, func, obj, func2) {
var deferreds = h.map(arr, func)
return Deferred.when.apply(Deferred, deferreds).then(function () {
if (h.isFn(obj[func2])) {
obj[func2]()
} else {
obj[func2].resolve();
}
});
};
// ## URI ##
/**
* @class steal.URI
* @parent steal
*
* A URL / URI helper for getting information from a URL.
*
* var uri = URI( "http://stealjs.com/index.html" )
* uri.path //-> "/index.html"
*/
var URI = function (url) {
if (this.constructor !== URI) {
return new URI(url);
}
h.extend(this, URI.parse("" + url));
};
// the current url (relative to root, which is relative from page)
// normalize joins from this
//
h.extend(URI, {
// parses a URI into it's basic parts
parse: function (string) {
var uriParts = string.split("?"),
uri = uriParts.shift(),
queryParts = uriParts.join("").split("#"),
protoParts = uri.split("://"),
parts = {
query: queryParts.shift(),
fragment: queryParts.join("#")
},
pathParts;
if (protoParts[1]) {
parts.protocol = protoParts.shift();
pathParts = protoParts[0].split("/");
parts.host = pathParts.shift();
parts.path = "/" + pathParts.join("/");
} else {
parts.path = protoParts[0];
}
return parts;
}
});
/**
* @attribute page
* The location of the page as a URI.
*
* st.URI.page.protocol //-> "http"
*/
URI.page = URI(h.win.location && location.href);
/**
* @attribute cur
*
* The current working directory / path. Anything
* loaded relative will be loaded relative to this.
*/
URI.cur = URI();
/**
* @prototype
*/
h.extend(URI.prototype, {
dir: function () {
var parts = this.path.split("/");
parts.pop();
return URI(this.domain() + parts.join("/"))
},
filename: function () {
return this.path.split("/").pop();
},
ext: function () {
var filename = this.filename();
return (filename.indexOf(".") > -1) ? filename.split(".").pop() : "";
},
domain: function () {
return this.protocol ? this.protocol + "://" + this.host : "";
},
isCrossDomain: function (uri) {
uri = URI(uri || h.win.location.href);
var domain = this.domain(),
uriDomain = uri.domain()
return (domain && uriDomain && domain != uriDomain) || this.protocol === "file" || (domain && !uriDomain);
},
isRelativeToDomain: function () {
return !this.path.indexOf("/");
},
hash: function () {
return this.fragment ? "#" + this.fragment : ""
},
search: function () {
return this.query ? "?" + this.query : ""
},
// like join, but returns a string
add: function (uri) {
return this.join(uri) + '';
},
join: function (uri, min) {
uri = URI(uri);
if (uri.isCrossDomain(this)) {
return uri;
}
if (uri.isRelativeToDomain()) {
return URI(this.domain() + uri)
}
// at this point we either
// - have the same domain
// - this has a domain but uri does not
// - both don't have domains
var left = this.path ? this.path.split("/") : [],
right = uri.path.split("/"),
part = right[0];
//if we are joining from a folder like cookbook/, remove the last empty part
if (this.path.match(/\/$/)) {
left.pop();
}
while (part == ".." && left.length && left[left.length - 1] !== "..") {
// if we've emptied out, folders, just break
// leaving any additional ../s
if (!left.pop()) {
break;
}
right.shift();
part = right[0];
}
return h.extend(URI(this.domain() + left.concat(right).join("/")), {
query: uri.query
});
},
/**
* For a given path, a given working directory, and file location, update the
* path so it points to a location relative to steal's root.
*
* We want everything relative to steal's root so the same app can work in
* multiple pages.
*
* ./files/a.js = steals a.js
* ./files/a = a/a.js
* files/a = //files/a/a.js
* files/a.js = loads //files/a.js
*/
normalize: function (cur) {
cur = cur ? cur.dir() : URI.cur.dir();
var path = this.path,
res = URI(path);
//if path is rooted from steal's root (DEPRECATED)
if (!path.indexOf("//")) {
res = URI(path.substr(2));
} else if (!path.indexOf("./")) { // should be relative
res = cur.join(path.substr(2));
}
// only if we start with ./ or have a /foo should we join from cur
else if (this.isRelative()) {
res = cur.join(this.domain() + path)
}
res.query = this.query;
return res;
},
isRelative: function () {
return /^[\.|\/]/.test(this.path)
},
// a min path from 2 urls that share the same domain
pathTo: function (uri) {
uri = URI(uri);
var uriParts = uri.path.split("/"),
thisParts = this.path.split("/"),
result = [];
while (uriParts.length && thisParts.length && uriParts[0] == thisParts[0]) {
uriParts.shift();
thisParts.shift();
}
h.each(thisParts, function () {
result.push("../")
})
return URI(result.join("") + uriParts.join("/"));
},
mapJoin: function (url) {
return this.join(URI(url).insertMapping());
},
// helper to go from jquery to jquery/jquery.js
addJS: function () {
var ext = this.ext();
if (!ext) {
// if first character of path is a . or /, just load this file
if (!this.isRelative()) {
this.path += "/" + this.filename();
}
this.path += ".js"
}
return this;
}
});
// This can't be added to the prototype using extend because
// then for some reason IE < 9 won't recognize it.
URI.prototype.toString = function () {
return this.domain() + this.path + this.search() + this.hash();
};
// =============================== MAPPING ===============================
// TODO: this can likely be removed
URI.prototype.insertMapping = function () {
// go through mappings
var orig = "" + this,
key, value;
for (key in steal.mappings) {
value = steal.mappings[key]
if (value.test.test(orig)) {
return orig.replace(key, value.path);
}
}
return URI(orig);
};
// --- END URI
/*
* @hide
* `new ConfigManager(config)` creates configuration profile for the steal context.
* It keeps all config parameters in the instance which allows steal to clone it's
* context.
*
* config.stealConfig is tipically set up in __stealconfig.js__. The available options are:
*
* - map - map an id to another id
* - paths - maps an id to a file
* - root - the path to the "root" folder
* - env - `"development"` or `"production"`
* - types - processor rules for various types
* - ext - behavior rules for extensions
* - urlArgs - extra queryString arguments
* - startId - the file to load
*
* ## map
*
* Maps an id to another id with a certain scope of other ids. This can be
* used to use different modules within the same id or map ids to another id.
* Example:
*
* st.config({
* map: {
* "*": {
* "jquery/jquery.js": "jquery"
* },
* "compontent1":{
* "underscore" : "underscore1.2"
* },
* "component2":{
* "underscore" : "underscore1.1"
* }
* }
* })
*
* ## paths
*
* Maps an id or matching ids to a url. Each mapping is specified
* by an id or part of the id to match and what that
* part should be replaced with.
*
* st.config({
* paths: {
* // maps everything in a jquery folder like: `jquery/controller`
* // to http://cdn.com/jquery/controller/controller.com
* "jquery/" : "http://cdn.com/jquery/"
*
* // if path does not end with /, it matches only that id
* "jquery" : "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
* }
* })
*
* ## root
* ## env
*
* If production, does not load "ignored" scripts and loads production script. If development gives more warnings / errors.
*
* ## types
*
* The types option can specify how a type is loaded.
*
* ## ext
*
* The ext option specifies the default behavior if file is loaded with the
* specified extension. For a given extension, a file that configures the type can be given or
* an existing type. For example, for ejs:
*
* st.config({ext: {"ejs": "can/view/ejs/ejs.js"}})
*
* This tells steal to make sure `can/view/ejs/ejs.js` is executed before any file with
* ".ejs" is executed.
*
*
*/
var ConfigManager = function (options) {
this.stealConfig = {};
this.callbacks = [];
this.attr(ConfigManager.defaults);
this.attr(options)
}
/**
* @add steal.config
*/
h.extend(ConfigManager.prototype, {
// get or set config.stealConfig attributes
attr: function (config, value) {
if (!config) { // called as a getter, so just return
return this.stealConfig;
}
if (typeof config === "string") { // getter / setter
if (arguments.length === 1) {
return this.stealConfig && this.stealConfig[config];
} else {
var temp = {};
temp[config] = value;
config = temp;
}
}
this.stealConfig = this.stealConfig || {};
for (var prop in config) {
var value = config[prop];
// if it's a special function
this[prop] ?
// run it
this[prop](value) :
// otherwise set or extend
(typeof value == "object" && this.stealConfig[prop] ?
// extend
h.extend(this.stealConfig[prop], value) :
// set
this.stealConfig[prop] = value);
}
for (var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i](this.stealConfig)
}
return this;
},
// add callbacks which are called after config is changed
on: function (cb) {
this.callbacks.push(cb)
},
// get the current start file
/**
* @attribute startId
*
* `steal.config("startId", startModuleId )` configures the
* first file that steal loads. This is important for
* builds.
*
*
*/
startId: function (startFile) {
// make sure startFile and production look right
this.stealConfig.startId = "" + URI(startFile).addJS()
if (!this.stealConfig.productionId) {
this.stealConfig.productionId = URI(this.stealConfig.startId).dir() + "/production.js";
}
},
/**
* @attribute root
* Read or define the path relative URI's should be referenced from.
*
* window.location //-> "http://foo.com/site/index.html"
* st.URI.root("http://foo.com/app/files/")
* st.root.toString() //-> "../../app/files/"
*/
root: function (relativeURI) {
if (relativeURI !== undefined) {
var root = URI(relativeURI);
// the current folder-location of the page http://foo.com/bar/card
var cleaned = URI.page,
// the absolute location or root
loc = cleaned.join(relativeURI);
// cur now points to the 'root' location, but from the page
URI.cur = loc.pathTo(cleaned)
this.stealConfig.root = root;
return this;
}
this.stealConfig.root = root || URI("");
},
//var stealConfig = configs[configContext];
cloneContext: function () {
return new ConfigManager(h.extend({}, this.stealConfig));
}
})
// ConfigManager's defaults
ConfigManager.defaults = {
types: {},
/**
* @attribute ext
*
* `steal.config("ext", extensionConfig)` configures
* processing behavior of moduleId extensions. For example:
*
* steal.config("ext",{
* js: "js",
* css: "css",
* less: "steal/less/less.js",
* mustache: "can/view/mustache/mustache.js"
* })
*
* `extensionConfig` maps a filename extension to
* be processed by a [steal.config.types type]
* (like `js: "js"`) or to a dependency moduleId that
* defines that type (like `less: "steal/less/less.js"`).
*
*/
ext: {},
/**
* @attribute env
*
* `steal.config("env", environment )` configures steal's
* environment to either:
*
* - `'development'` - loads all modules seperately
* - `'production'` - load modules in minified production scripts and styles.
*
*
* ## Setting Env
*
* Typically, changing the environment is done by changing
* `steal/steal.js` to `steal/steal.production.js` like:
*
* <script src="../steal/steal.production.js?myapp">
* </script>
*
* It can also be set in the queryparams like:
*
* <script src="../steal/steal.js?myapp,production">
* </script>
*
* Or set before steal is loaded like:
*
* <script>
* steal = {env: "production"}
* </script>
* <script src="../steal/steal.js?myapp">
* </script>
*
* Of course, it can also be set in `stealconfig.js`, but you
* probably shouldn't.
*
*
*/
env: "development",
/**
* @attribute loadProduction
*
* `steal.config("loadProduction",loadProduction)` tells steal
* to load [steal.config.productionId productionId] when
* [steal.config.env env] is `"production"`. It's true
* by default.
*
* `steal.config("loadProduction",false)` is used when steal is
* bundled with the production script.
*
*/
loadProduction: true,
logLevel: 0,
root: "",
/**
* @attribute amd
*
* `steal.config("amd",true)` turns on steal's AMD support. This needs
* to be configured before steal loads like:
*
* <script>
* steal = {amd: true}
* </script>
* <script src='../../public/steal/steal.js?app'>
* </script>
*
* This lets you use `define([id], [deps...], definition)` and
* `require([deps], definition)`.
*/
amd: false
/**
* @attribute map
*
* `steal.config( "map", mapConfig )` maps
* moduleIds to other moduleIds when stolen
* in a particular location.
*
* The following maps "jquery/jquery.js" to
* `"jquery-1.8.3.js" in "filemanager" and
* "jquery/jquery.js" to `"jquery-1.4.2.js"` in
* "taskmanager":
*
* steal.config({
* maps: {
* filemanager: {
* "jquery/jquery.js": "jquery-1.8.3.js"
* },
* taskmanager: {
* "jquery/jquery.js": "jquery-1.4.2.js"
* }
* }
* });
*
* In _filemanager/filemanager.js_:
*
* steal('jquery')
*
* ... will load `jquery-1.8.3.js`. To configure the location of
* `jquery-1.8.3.js`, use [steal.config.paths].
*
* To map ids within any location, use "*":
*
* steal.config({
* maps: {
* "*": {
* "jquery/jquery.js": "jquery-1.8.3.js"
* }
* }
* });
*
* ## mapConfig
*
* `mapConfig` is a map of a "require-er" moduleId
* to a mapping of ids like:
*
* {
* "require-er" : {requiredId: moduleId}
* }
*
* where:
*
* - __require-er__ is a moduleId or folderId where the `requiredId`
* is stolen.
* - __requiredId__ is the id returned by [steal.id].
* - __moduleId__ is the moduleId that will be retrieved.
*/
//
/**
* @attribute paths
*
* `steal.config( "paths", pathConfig )` maps moduleIds
* to paths. This is used to
* override [steal.idToUri]. Often, this can be used to
* specify loading from a CDN like:
*
* steal.config({
* paths: {
* "jquery" : "http://cdn.google.com/jquery"
* }
* });
*
* To keep loading jQuery in production from the CDN, use
* [steal.config.shim] and set the "exclude" option.
*/
//
/**
* @attribute productionId
* `steal.config("productionId", productionid )` configures
* the id to load the production package. It defaults
* to replacing [steal.config.startId]
* with "`production.js`". For example,
* `myapp/myapp.js` becomes `myapp/production.js`.
*
* The best way to configure `productionId` is
* with a `steal` object before steal.js is loaded:
*
* <script>
* steal = {productionId: "myapp/myapp.production.js"}
* </script>
* <script src="../steal/steal.js?myapp">
* </script>
*
* If you change `productionId`, make sure you change
* your build script.
*/
//
/**
* @attribute completed
*
* `steal.config("completed", completedIds)` marks
* the modules represented by `completedIds` as
* completed (already loaded and run).
*
* The following can be used to indicate that
* `production.css` has already been loaded and run:
*
* <link rel="stylesheet" type="text/css"
* href="../myapp/production.css">
* <script>
* steal = {completed: ["myapp/production.css"]}
* </script>
* <script src="../steal/steal.production.js?myapp">
* </script>
*
*/
// code in core.js w/i config.on callback
};
/**
* @add steal.config
*/
// ### TYPES ##
/**
* @function types
*
* `steal.config("types",types)` registers alternative types. The
* `types` object is a mapping of a `type path` to
* a `type converter`. For example, the following creates a "coffee" type
* that converts a [http://jashkenas.github.com/coffee-script/ CoffeeScript]
* file to JavaScript:
*