sc-frank-cucumber 1.2.1.00af28c

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +38 -0
  4. data/bin/frank +6 -0
  5. data/bin/frank-skeleton +33 -0
  6. data/frank-skeleton/features/my_first.feature +12 -0
  7. data/frank-skeleton/features/step_definitions/launch_steps.rb +20 -0
  8. data/frank-skeleton/features/support/env.rb +8 -0
  9. data/frank-skeleton/frank_static_resources.bundle/ViewAttributeMapping.plist +63 -0
  10. data/frank-skeleton/frank_static_resources.bundle/ViewAttributeMappingMac.plist +99 -0
  11. data/frank-skeleton/frank_static_resources.bundle/images/ajax-loader.gif +0 -0
  12. data/frank-skeleton/frank_static_resources.bundle/images/file.gif +0 -0
  13. data/frank-skeleton/frank_static_resources.bundle/images/folder-closed.gif +0 -0
  14. data/frank-skeleton/frank_static_resources.bundle/images/folder.gif +0 -0
  15. data/frank-skeleton/frank_static_resources.bundle/images/loader.gif +0 -0
  16. data/frank-skeleton/frank_static_resources.bundle/images/loader.png +0 -0
  17. data/frank-skeleton/frank_static_resources.bundle/images/minus.gif +0 -0
  18. data/frank-skeleton/frank_static_resources.bundle/images/plus.gif +0 -0
  19. data/frank-skeleton/frank_static_resources.bundle/images/treeview-black-line.gif +0 -0
  20. data/frank-skeleton/frank_static_resources.bundle/images/treeview-black.gif +0 -0
  21. data/frank-skeleton/frank_static_resources.bundle/images/treeview-default-line.gif +0 -0
  22. data/frank-skeleton/frank_static_resources.bundle/images/treeview-default.gif +0 -0
  23. data/frank-skeleton/frank_static_resources.bundle/images/treeview-famfamfam-line.gif +0 -0
  24. data/frank-skeleton/frank_static_resources.bundle/images/treeview-famfamfam.gif +0 -0
  25. data/frank-skeleton/frank_static_resources.bundle/images/treeview-gray-line.gif +0 -0
  26. data/frank-skeleton/frank_static_resources.bundle/images/treeview-gray.gif +0 -0
  27. data/frank-skeleton/frank_static_resources.bundle/images/treeview-red-line.gif +0 -0
  28. data/frank-skeleton/frank_static_resources.bundle/images/treeview-red.gif +0 -0
  29. data/frank-skeleton/frank_static_resources.bundle/index.html +86 -0
  30. data/frank-skeleton/frank_static_resources.bundle/index.html.haml +76 -0
  31. data/frank-skeleton/frank_static_resources.bundle/js/accessible_views_view.coffee +41 -0
  32. data/frank-skeleton/frank_static_resources.bundle/js/accessible_views_view.js +46 -0
  33. data/frank-skeleton/frank_static_resources.bundle/js/controller.coffee +134 -0
  34. data/frank-skeleton/frank_static_resources.bundle/js/controller.js +139 -0
  35. data/frank-skeleton/frank_static_resources.bundle/js/details_view.coffee +42 -0
  36. data/frank-skeleton/frank_static_resources.bundle/js/details_view.js +51 -0
  37. data/frank-skeleton/frank_static_resources.bundle/js/dropdown_control.coffee +64 -0
  38. data/frank-skeleton/frank_static_resources.bundle/js/dropdown_control.js +73 -0
  39. data/frank-skeleton/frank_static_resources.bundle/js/ersatz_model.coffee +46 -0
  40. data/frank-skeleton/frank_static_resources.bundle/js/ersatz_model.js +60 -0
  41. data/frank-skeleton/frank_static_resources.bundle/js/ersatz_view.coffee +167 -0
  42. data/frank-skeleton/frank_static_resources.bundle/js/ersatz_view.js +205 -0
  43. data/frank-skeleton/frank_static_resources.bundle/js/experiment_bar_model.coffee +10 -0
  44. data/frank-skeleton/frank_static_resources.bundle/js/experiment_bar_model.js +17 -0
  45. data/frank-skeleton/frank_static_resources.bundle/js/experiment_bar_view.coffee +44 -0
  46. data/frank-skeleton/frank_static_resources.bundle/js/experiment_bar_view.js +63 -0
  47. data/frank-skeleton/frank_static_resources.bundle/js/frank.coffee +96 -0
  48. data/frank-skeleton/frank_static_resources.bundle/js/frank.js +146 -0
  49. data/frank-skeleton/frank_static_resources.bundle/js/lib/backbone.js +1431 -0
  50. data/frank-skeleton/frank_static_resources.bundle/js/lib/coffee-script.js +8 -0
  51. data/frank-skeleton/frank_static_resources.bundle/js/lib/jquery-ui.min.js +405 -0
  52. data/frank-skeleton/frank_static_resources.bundle/js/lib/jquery.min.js +4 -0
  53. data/frank-skeleton/frank_static_resources.bundle/js/lib/jquery.treeview.js +251 -0
  54. data/frank-skeleton/frank_static_resources.bundle/js/lib/json2.js +481 -0
  55. data/frank-skeleton/frank_static_resources.bundle/js/lib/raphael.js +5815 -0
  56. data/frank-skeleton/frank_static_resources.bundle/js/lib/require.js +2053 -0
  57. data/frank-skeleton/frank_static_resources.bundle/js/lib/underscore.js +1059 -0
  58. data/frank-skeleton/frank_static_resources.bundle/js/main.coffee +27 -0
  59. data/frank-skeleton/frank_static_resources.bundle/js/main.js +29 -0
  60. data/frank-skeleton/frank_static_resources.bundle/js/tabs_controller.coffee +13 -0
  61. data/frank-skeleton/frank_static_resources.bundle/js/tabs_controller.js +22 -0
  62. data/frank-skeleton/frank_static_resources.bundle/js/toast_controller.coffee +15 -0
  63. data/frank-skeleton/frank_static_resources.bundle/js/toast_controller.js +28 -0
  64. data/frank-skeleton/frank_static_resources.bundle/js/transform_stack.coffee +59 -0
  65. data/frank-skeleton/frank_static_resources.bundle/js/transform_stack.js +78 -0
  66. data/frank-skeleton/frank_static_resources.bundle/js/tree_view.coffee +53 -0
  67. data/frank-skeleton/frank_static_resources.bundle/js/tree_view.js +64 -0
  68. data/frank-skeleton/frank_static_resources.bundle/js/view_hier_model.coffee +37 -0
  69. data/frank-skeleton/frank_static_resources.bundle/js/view_hier_model.js +48 -0
  70. data/frank-skeleton/frank_static_resources.bundle/js/view_model.coffee +39 -0
  71. data/frank-skeleton/frank_static_resources.bundle/js/view_model.js +62 -0
  72. data/frank-skeleton/frank_static_resources.bundle/pictos/index.html +329 -0
  73. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos-web.eot +0 -0
  74. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos-web.svg +114 -0
  75. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos-web.ttf +0 -0
  76. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos-web.woff +0 -0
  77. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos.css +20 -0
  78. data/frank-skeleton/frank_static_resources.bundle/pictos/pictos_base64.css +18 -0
  79. data/frank-skeleton/frank_static_resources.bundle/stylesheets/css/symbiote.css +1 -0
  80. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_elements.scss +28 -0
  81. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_header.scss +61 -0
  82. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_inspect_tabs_list_tabs.scss +194 -0
  83. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_jquery.treeview.scss +68 -0
  84. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_jqui.scss +2 -0
  85. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_layout.scss +13 -0
  86. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_mixins.sass +137 -0
  87. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_reset.scss +32 -0
  88. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_selector_test_toolbar.scss +81 -0
  89. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_solarized.scss +16 -0
  90. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_typography.scss +11 -0
  91. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_unicode.scss +3 -0
  92. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/_z_index.scss +2 -0
  93. data/frank-skeleton/frank_static_resources.bundle/stylesheets/sass/symbiote.scss +26 -0
  94. data/frank-skeleton/frankify.xcconfig.tt +6 -0
  95. data/frank-skeleton/libCocoaAsyncSocket.a +0 -0
  96. data/frank-skeleton/libCocoaAsyncSocketMac.a +0 -0
  97. data/frank-skeleton/libCocoaHTTPServer.a +0 -0
  98. data/frank-skeleton/libCocoaHTTPServerMac.a +0 -0
  99. data/frank-skeleton/libCocoaLumberjack.a +0 -0
  100. data/frank-skeleton/libCocoaLumberjackMac.a +0 -0
  101. data/frank-skeleton/libFrank.a +0 -0
  102. data/frank-skeleton/libFrankMac.a +0 -0
  103. data/frank-skeleton/libShelley.a +0 -0
  104. data/frank-skeleton/libShelleyMac.a +0 -0
  105. data/frank-skeleton/plugins/.empty_directory +0 -0
  106. data/lib/frank-cucumber.rb +15 -0
  107. data/lib/frank-cucumber/app_bundle_locator.rb +58 -0
  108. data/lib/frank-cucumber/bonjour.rb +73 -0
  109. data/lib/frank-cucumber/cli.rb +299 -0
  110. data/lib/frank-cucumber/color_helper.rb +13 -0
  111. data/lib/frank-cucumber/console.rb +28 -0
  112. data/lib/frank-cucumber/core_frank_steps.rb +260 -0
  113. data/lib/frank-cucumber/frank.xcconfig.erb +17 -0
  114. data/lib/frank-cucumber/frank_helper.rb +459 -0
  115. data/lib/frank-cucumber/frank_localize.rb +43 -0
  116. data/lib/frank-cucumber/frank_mac_helper.rb +120 -0
  117. data/lib/frank-cucumber/frankifier.rb +150 -0
  118. data/lib/frank-cucumber/gateway.rb +135 -0
  119. data/lib/frank-cucumber/gesture_helper.rb +99 -0
  120. data/lib/frank-cucumber/host_scripting.rb +96 -0
  121. data/lib/frank-cucumber/keyboard_helper.rb +69 -0
  122. data/lib/frank-cucumber/launcher.rb +70 -0
  123. data/lib/frank-cucumber/localize.yml +104 -0
  124. data/lib/frank-cucumber/location_helper.rb +20 -0
  125. data/lib/frank-cucumber/mac_launcher.rb +35 -0
  126. data/lib/frank-cucumber/plugins/plugin.rb +57 -0
  127. data/lib/frank-cucumber/rect.rb +26 -0
  128. data/lib/frank-cucumber/scroll_helper.rb +24 -0
  129. data/lib/frank-cucumber/version.rb +5 -0
  130. data/lib/frank-cucumber/wait_helper.rb +57 -0
  131. data/sc-frank-cucumber.gemspec +37 -0
  132. data/test/keyboard_helper_test.rb +84 -0
  133. data/test/launcher_test.rb +57 -0
  134. data/test/rect_test.rb +25 -0
  135. data/test/test_helper.rb +16 -0
  136. metadata +395 -0
@@ -0,0 +1,2053 @@
1
+ /** vim: et:ts=4:sw=4:sts=4
2
+ * @license RequireJS 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
3
+ * Available via the MIT or new BSD license.
4
+ * see: http://github.com/jrburke/requirejs for details
5
+ */
6
+ //Not using strict: uneven strict support in browsers, #392, and causes
7
+ //problems with requirejs.exec()/transpiler plugins that may not be strict.
8
+ /*jslint regexp: true, nomen: true, sloppy: true */
9
+ /*global window, navigator, document, importScripts, jQuery, setTimeout, opera */
10
+
11
+ var requirejs, require, define;
12
+ (function (global) {
13
+ var req, s, head, baseElement, dataMain, src,
14
+ interactiveScript, currentlyAddingScript, mainScript, subPath,
15
+ version = '2.0.5',
16
+ commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
17
+ cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
18
+ jsSuffixRegExp = /\.js$/,
19
+ currDirRegExp = /^\.\//,
20
+ op = Object.prototype,
21
+ ostring = op.toString,
22
+ hasOwn = op.hasOwnProperty,
23
+ ap = Array.prototype,
24
+ aps = ap.slice,
25
+ apsp = ap.splice,
26
+ isBrowser = !!(typeof window !== 'undefined' && navigator && document),
27
+ isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
28
+ //PS3 indicates loaded and complete, but need to wait for complete
29
+ //specifically. Sequence is 'loading', 'loaded', execution,
30
+ // then 'complete'. The UA check is unfortunate, but not sure how
31
+ //to feature test w/o causing perf issues.
32
+ readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
33
+ /^complete$/ : /^(complete|loaded)$/,
34
+ defContextName = '_',
35
+ //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
36
+ isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
37
+ contexts = {},
38
+ cfg = {},
39
+ globalDefQueue = [],
40
+ useInteractive = false;
41
+
42
+ function isFunction(it) {
43
+ return ostring.call(it) === '[object Function]';
44
+ }
45
+
46
+ function isArray(it) {
47
+ return ostring.call(it) === '[object Array]';
48
+ }
49
+
50
+ /**
51
+ * Helper function for iterating over an array. If the func returns
52
+ * a true value, it will break out of the loop.
53
+ */
54
+ function each(ary, func) {
55
+ if (ary) {
56
+ var i;
57
+ for (i = 0; i < ary.length; i += 1) {
58
+ if (ary[i] && func(ary[i], i, ary)) {
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Helper function for iterating over an array backwards. If the func
67
+ * returns a true value, it will break out of the loop.
68
+ */
69
+ function eachReverse(ary, func) {
70
+ if (ary) {
71
+ var i;
72
+ for (i = ary.length - 1; i > -1; i -= 1) {
73
+ if (ary[i] && func(ary[i], i, ary)) {
74
+ break;
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ function hasProp(obj, prop) {
81
+ return hasOwn.call(obj, prop);
82
+ }
83
+
84
+ /**
85
+ * Cycles over properties in an object and calls a function for each
86
+ * property value. If the function returns a truthy value, then the
87
+ * iteration is stopped.
88
+ */
89
+ function eachProp(obj, func) {
90
+ var prop;
91
+ for (prop in obj) {
92
+ if (obj.hasOwnProperty(prop)) {
93
+ if (func(obj[prop], prop)) {
94
+ break;
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Simple function to mix in properties from source into target,
102
+ * but only if target does not already have a property of the same name.
103
+ * This is not robust in IE for transferring methods that match
104
+ * Object.prototype names, but the uses of mixin here seem unlikely to
105
+ * trigger a problem related to that.
106
+ */
107
+ function mixin(target, source, force, deepStringMixin) {
108
+ if (source) {
109
+ eachProp(source, function (value, prop) {
110
+ if (force || !hasProp(target, prop)) {
111
+ if (deepStringMixin && typeof value !== 'string') {
112
+ if (!target[prop]) {
113
+ target[prop] = {};
114
+ }
115
+ mixin(target[prop], value, force, deepStringMixin);
116
+ } else {
117
+ target[prop] = value;
118
+ }
119
+ }
120
+ });
121
+ }
122
+ return target;
123
+ }
124
+
125
+ //Similar to Function.prototype.bind, but the 'this' object is specified
126
+ //first, since it is easier to read/figure out what 'this' will be.
127
+ function bind(obj, fn) {
128
+ return function () {
129
+ return fn.apply(obj, arguments);
130
+ };
131
+ }
132
+
133
+ function scripts() {
134
+ return document.getElementsByTagName('script');
135
+ }
136
+
137
+ //Allow getting a global that expressed in
138
+ //dot notation, like 'a.b.c'.
139
+ function getGlobal(value) {
140
+ if (!value) {
141
+ return value;
142
+ }
143
+ var g = global;
144
+ each(value.split('.'), function (part) {
145
+ g = g[part];
146
+ });
147
+ return g;
148
+ }
149
+
150
+ function makeContextModuleFunc(func, relMap, enableBuildCallback) {
151
+ return function () {
152
+ //A version of a require function that passes a moduleName
153
+ //value for items that may need to
154
+ //look up paths relative to the moduleName
155
+ var args = aps.call(arguments, 0), lastArg;
156
+ if (enableBuildCallback &&
157
+ isFunction((lastArg = args[args.length - 1]))) {
158
+ lastArg.__requireJsBuild = true;
159
+ }
160
+ args.push(relMap);
161
+ return func.apply(null, args);
162
+ };
163
+ }
164
+
165
+ function addRequireMethods(req, context, relMap) {
166
+ each([
167
+ ['toUrl'],
168
+ ['undef'],
169
+ ['defined', 'requireDefined'],
170
+ ['specified', 'requireSpecified']
171
+ ], function (item) {
172
+ var prop = item[1] || item[0];
173
+ req[item[0]] = context ? makeContextModuleFunc(context[prop], relMap) :
174
+ //If no context, then use default context. Reference from
175
+ //contexts instead of early binding to default context, so
176
+ //that during builds, the latest instance of the default
177
+ //context with its config gets used.
178
+ function () {
179
+ var ctx = contexts[defContextName];
180
+ return ctx[prop].apply(ctx, arguments);
181
+ };
182
+ });
183
+ }
184
+
185
+ /**
186
+ * Constructs an error with a pointer to an URL with more information.
187
+ * @param {String} id the error ID that maps to an ID on a web page.
188
+ * @param {String} message human readable error.
189
+ * @param {Error} [err] the original error, if there is one.
190
+ *
191
+ * @returns {Error}
192
+ */
193
+ function makeError(id, msg, err, requireModules) {
194
+ var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
195
+ e.requireType = id;
196
+ e.requireModules = requireModules;
197
+ if (err) {
198
+ e.originalError = err;
199
+ }
200
+ return e;
201
+ }
202
+
203
+ if (typeof define !== 'undefined') {
204
+ //If a define is already in play via another AMD loader,
205
+ //do not overwrite.
206
+ return;
207
+ }
208
+
209
+ if (typeof requirejs !== 'undefined') {
210
+ if (isFunction(requirejs)) {
211
+ //Do not overwrite and existing requirejs instance.
212
+ return;
213
+ }
214
+ cfg = requirejs;
215
+ requirejs = undefined;
216
+ }
217
+
218
+ //Allow for a require config object
219
+ if (typeof require !== 'undefined' && !isFunction(require)) {
220
+ //assume it is a config object.
221
+ cfg = require;
222
+ require = undefined;
223
+ }
224
+
225
+ function newContext(contextName) {
226
+ var inCheckLoaded, Module, context, handlers,
227
+ checkLoadedTimeoutId,
228
+ config = {
229
+ waitSeconds: 7,
230
+ baseUrl: './',
231
+ paths: {},
232
+ pkgs: {},
233
+ shim: {}
234
+ },
235
+ registry = {},
236
+ undefEvents = {},
237
+ defQueue = [],
238
+ defined = {},
239
+ urlFetched = {},
240
+ requireCounter = 1,
241
+ unnormalizedCounter = 1,
242
+ //Used to track the order in which modules
243
+ //should be executed, by the order they
244
+ //load. Important for consistent cycle resolution
245
+ //behavior.
246
+ waitAry = [];
247
+
248
+ /**
249
+ * Trims the . and .. from an array of path segments.
250
+ * It will keep a leading path segment if a .. will become
251
+ * the first path segment, to help with module name lookups,
252
+ * which act like paths, but can be remapped. But the end result,
253
+ * all paths that use this function should look normalized.
254
+ * NOTE: this method MODIFIES the input array.
255
+ * @param {Array} ary the array of path segments.
256
+ */
257
+ function trimDots(ary) {
258
+ var i, part;
259
+ for (i = 0; ary[i]; i += 1) {
260
+ part = ary[i];
261
+ if (part === '.') {
262
+ ary.splice(i, 1);
263
+ i -= 1;
264
+ } else if (part === '..') {
265
+ if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
266
+ //End of the line. Keep at least one non-dot
267
+ //path segment at the front so it can be mapped
268
+ //correctly to disk. Otherwise, there is likely
269
+ //no path mapping for a path starting with '..'.
270
+ //This can still fail, but catches the most reasonable
271
+ //uses of ..
272
+ break;
273
+ } else if (i > 0) {
274
+ ary.splice(i - 1, 2);
275
+ i -= 2;
276
+ }
277
+ }
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Given a relative module name, like ./something, normalize it to
283
+ * a real name that can be mapped to a path.
284
+ * @param {String} name the relative name
285
+ * @param {String} baseName a real name that the name arg is relative
286
+ * to.
287
+ * @param {Boolean} applyMap apply the map config to the value. Should
288
+ * only be done if this normalization is for a dependency ID.
289
+ * @returns {String} normalized name
290
+ */
291
+ function normalize(name, baseName, applyMap) {
292
+ var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment,
293
+ foundMap, foundI, foundStarMap, starI,
294
+ baseParts = baseName && baseName.split('/'),
295
+ normalizedBaseParts = baseParts,
296
+ map = config.map,
297
+ starMap = map && map['*'];
298
+
299
+ //Adjust any relative paths.
300
+ if (name && name.charAt(0) === '.') {
301
+ //If have a base name, try to normalize against it,
302
+ //otherwise, assume it is a top-level require that will
303
+ //be relative to baseUrl in the end.
304
+ if (baseName) {
305
+ if (config.pkgs[baseName]) {
306
+ //If the baseName is a package name, then just treat it as one
307
+ //name to concat the name with.
308
+ normalizedBaseParts = baseParts = [baseName];
309
+ } else {
310
+ //Convert baseName to array, and lop off the last part,
311
+ //so that . matches that 'directory' and not name of the baseName's
312
+ //module. For instance, baseName of 'one/two/three', maps to
313
+ //'one/two/three.js', but we want the directory, 'one/two' for
314
+ //this normalization.
315
+ normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
316
+ }
317
+
318
+ name = normalizedBaseParts.concat(name.split('/'));
319
+ trimDots(name);
320
+
321
+ //Some use of packages may use a . path to reference the
322
+ //'main' module name, so normalize for that.
323
+ pkgConfig = config.pkgs[(pkgName = name[0])];
324
+ name = name.join('/');
325
+ if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
326
+ name = pkgName;
327
+ }
328
+ } else if (name.indexOf('./') === 0) {
329
+ // No baseName, so this is ID is resolved relative
330
+ // to baseUrl, pull off the leading dot.
331
+ name = name.substring(2);
332
+ }
333
+ }
334
+
335
+ //Apply map config if available.
336
+ if (applyMap && (baseParts || starMap) && map) {
337
+ nameParts = name.split('/');
338
+
339
+ for (i = nameParts.length; i > 0; i -= 1) {
340
+ nameSegment = nameParts.slice(0, i).join('/');
341
+
342
+ if (baseParts) {
343
+ //Find the longest baseName segment match in the config.
344
+ //So, do joins on the biggest to smallest lengths of baseParts.
345
+ for (j = baseParts.length; j > 0; j -= 1) {
346
+ mapValue = map[baseParts.slice(0, j).join('/')];
347
+
348
+ //baseName segment has config, find if it has one for
349
+ //this name.
350
+ if (mapValue) {
351
+ mapValue = mapValue[nameSegment];
352
+ if (mapValue) {
353
+ //Match, update name to the new value.
354
+ foundMap = mapValue;
355
+ foundI = i;
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ }
361
+
362
+ if (foundMap) {
363
+ break;
364
+ }
365
+
366
+ //Check for a star map match, but just hold on to it,
367
+ //if there is a shorter segment match later in a matching
368
+ //config, then favor over this star map.
369
+ if (!foundStarMap && starMap && starMap[nameSegment]) {
370
+ foundStarMap = starMap[nameSegment];
371
+ starI = i;
372
+ }
373
+ }
374
+
375
+ if (!foundMap && foundStarMap) {
376
+ foundMap = foundStarMap;
377
+ foundI = starI;
378
+ }
379
+
380
+ if (foundMap) {
381
+ nameParts.splice(0, foundI, foundMap);
382
+ name = nameParts.join('/');
383
+ }
384
+ }
385
+
386
+ return name;
387
+ }
388
+
389
+ function removeScript(name) {
390
+ if (isBrowser) {
391
+ each(scripts(), function (scriptNode) {
392
+ if (scriptNode.getAttribute('data-requiremodule') === name &&
393
+ scriptNode.getAttribute('data-requirecontext') === context.contextName) {
394
+ scriptNode.parentNode.removeChild(scriptNode);
395
+ return true;
396
+ }
397
+ });
398
+ }
399
+ }
400
+
401
+ function hasPathFallback(id) {
402
+ var pathConfig = config.paths[id];
403
+ if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
404
+ removeScript(id);
405
+ //Pop off the first array value, since it failed, and
406
+ //retry
407
+ pathConfig.shift();
408
+ context.undef(id);
409
+ context.require([id]);
410
+ return true;
411
+ }
412
+ }
413
+
414
+ /**
415
+ * Creates a module mapping that includes plugin prefix, module
416
+ * name, and path. If parentModuleMap is provided it will
417
+ * also normalize the name via require.normalize()
418
+ *
419
+ * @param {String} name the module name
420
+ * @param {String} [parentModuleMap] parent module map
421
+ * for the module name, used to resolve relative names.
422
+ * @param {Boolean} isNormalized: is the ID already normalized.
423
+ * This is true if this call is done for a define() module ID.
424
+ * @param {Boolean} applyMap: apply the map config to the ID.
425
+ * Should only be true if this map is for a dependency.
426
+ *
427
+ * @returns {Object}
428
+ */
429
+ function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
430
+ var url, pluginModule, suffix,
431
+ index = name ? name.indexOf('!') : -1,
432
+ prefix = null,
433
+ parentName = parentModuleMap ? parentModuleMap.name : null,
434
+ originalName = name,
435
+ isDefine = true,
436
+ normalizedName = '';
437
+
438
+ //If no name, then it means it is a require call, generate an
439
+ //internal name.
440
+ if (!name) {
441
+ isDefine = false;
442
+ name = '_@r' + (requireCounter += 1);
443
+ }
444
+
445
+ if (index !== -1) {
446
+ prefix = name.substring(0, index);
447
+ name = name.substring(index + 1, name.length);
448
+ }
449
+
450
+ if (prefix) {
451
+ prefix = normalize(prefix, parentName, applyMap);
452
+ pluginModule = defined[prefix];
453
+ }
454
+
455
+ //Account for relative paths if there is a base name.
456
+ if (name) {
457
+ if (prefix) {
458
+ if (pluginModule && pluginModule.normalize) {
459
+ //Plugin is loaded, use its normalize method.
460
+ normalizedName = pluginModule.normalize(name, function (name) {
461
+ return normalize(name, parentName, applyMap);
462
+ });
463
+ } else {
464
+ normalizedName = normalize(name, parentName, applyMap);
465
+ }
466
+ } else {
467
+ //A regular module.
468
+ normalizedName = normalize(name, parentName, applyMap);
469
+ url = context.nameToUrl(normalizedName);
470
+ }
471
+ }
472
+
473
+ //If the id is a plugin id that cannot be determined if it needs
474
+ //normalization, stamp it with a unique ID so two matching relative
475
+ //ids that may conflict can be separate.
476
+ suffix = prefix && !pluginModule && !isNormalized ?
477
+ '_unnormalized' + (unnormalizedCounter += 1) :
478
+ '';
479
+
480
+ return {
481
+ prefix: prefix,
482
+ name: normalizedName,
483
+ parentMap: parentModuleMap,
484
+ unnormalized: !!suffix,
485
+ url: url,
486
+ originalName: originalName,
487
+ isDefine: isDefine,
488
+ id: (prefix ?
489
+ prefix + '!' + normalizedName :
490
+ normalizedName) + suffix
491
+ };
492
+ }
493
+
494
+ function getModule(depMap) {
495
+ var id = depMap.id,
496
+ mod = registry[id];
497
+
498
+ if (!mod) {
499
+ mod = registry[id] = new context.Module(depMap);
500
+ }
501
+
502
+ return mod;
503
+ }
504
+
505
+ function on(depMap, name, fn) {
506
+ var id = depMap.id,
507
+ mod = registry[id];
508
+
509
+ if (hasProp(defined, id) &&
510
+ (!mod || mod.defineEmitComplete)) {
511
+ if (name === 'defined') {
512
+ fn(defined[id]);
513
+ }
514
+ } else {
515
+ getModule(depMap).on(name, fn);
516
+ }
517
+ }
518
+
519
+ function onError(err, errback) {
520
+ var ids = err.requireModules,
521
+ notified = false;
522
+
523
+ if (errback) {
524
+ errback(err);
525
+ } else {
526
+ each(ids, function (id) {
527
+ var mod = registry[id];
528
+ if (mod) {
529
+ //Set error on module, so it skips timeout checks.
530
+ mod.error = err;
531
+ if (mod.events.error) {
532
+ notified = true;
533
+ mod.emit('error', err);
534
+ }
535
+ }
536
+ });
537
+
538
+ if (!notified) {
539
+ req.onError(err);
540
+ }
541
+ }
542
+ }
543
+
544
+ /**
545
+ * Internal method to transfer globalQueue items to this context's
546
+ * defQueue.
547
+ */
548
+ function takeGlobalQueue() {
549
+ //Push all the globalDefQueue items into the context's defQueue
550
+ if (globalDefQueue.length) {
551
+ //Array splice in the values since the context code has a
552
+ //local var ref to defQueue, so cannot just reassign the one
553
+ //on context.
554
+ apsp.apply(defQueue,
555
+ [defQueue.length - 1, 0].concat(globalDefQueue));
556
+ globalDefQueue = [];
557
+ }
558
+ }
559
+
560
+ /**
561
+ * Helper function that creates a require function object to give to
562
+ * modules that ask for it as a dependency. It needs to be specific
563
+ * per module because of the implication of path mappings that may
564
+ * need to be relative to the module name.
565
+ */
566
+ function makeRequire(mod, enableBuildCallback, altRequire) {
567
+ var relMap = mod && mod.map,
568
+ modRequire = makeContextModuleFunc(altRequire || context.require,
569
+ relMap,
570
+ enableBuildCallback);
571
+
572
+ addRequireMethods(modRequire, context, relMap);
573
+ modRequire.isBrowser = isBrowser;
574
+
575
+ return modRequire;
576
+ }
577
+
578
+ handlers = {
579
+ 'require': function (mod) {
580
+ return makeRequire(mod);
581
+ },
582
+ 'exports': function (mod) {
583
+ mod.usingExports = true;
584
+ if (mod.map.isDefine) {
585
+ return (mod.exports = defined[mod.map.id] = {});
586
+ }
587
+ },
588
+ 'module': function (mod) {
589
+ return (mod.module = {
590
+ id: mod.map.id,
591
+ uri: mod.map.url,
592
+ config: function () {
593
+ return (config.config && config.config[mod.map.id]) || {};
594
+ },
595
+ exports: defined[mod.map.id]
596
+ });
597
+ }
598
+ };
599
+
600
+ function removeWaiting(id) {
601
+ //Clean up machinery used for waiting modules.
602
+ delete registry[id];
603
+
604
+ each(waitAry, function (mod, i) {
605
+ if (mod.map.id === id) {
606
+ waitAry.splice(i, 1);
607
+ if (!mod.defined) {
608
+ context.waitCount -= 1;
609
+ }
610
+ return true;
611
+ }
612
+ });
613
+ }
614
+
615
+ function findCycle(mod, traced) {
616
+ var id = mod.map.id,
617
+ depArray = mod.depMaps,
618
+ foundModule;
619
+
620
+ //Do not bother with unitialized modules or not yet enabled
621
+ //modules.
622
+ if (!mod.inited) {
623
+ return;
624
+ }
625
+
626
+ //Found the cycle.
627
+ if (traced[id]) {
628
+ return mod;
629
+ }
630
+
631
+ traced[id] = true;
632
+
633
+ //Trace through the dependencies.
634
+ each(depArray, function (depMap) {
635
+ var depId = depMap.id,
636
+ depMod = registry[depId];
637
+
638
+ if (!depMod) {
639
+ return;
640
+ }
641
+
642
+ if (!depMod.inited || !depMod.enabled) {
643
+ //Dependency is not inited, so this cannot
644
+ //be used to determine a cycle.
645
+ foundModule = null;
646
+ delete traced[id];
647
+ return true;
648
+ }
649
+
650
+ //mixin traced to a new object for each dependency, so that
651
+ //sibling dependencies in this object to not generate a
652
+ //false positive match on a cycle. Ideally an Object.create
653
+ //type of prototype delegation would be used here, but
654
+ //optimizing for file size vs. execution speed since hopefully
655
+ //the trees are small for circular dependency scans relative
656
+ //to the full app perf.
657
+ return (foundModule = findCycle(depMod, mixin({}, traced)));
658
+ });
659
+
660
+ return foundModule;
661
+ }
662
+
663
+ function forceExec(mod, traced, uninited) {
664
+ var id = mod.map.id,
665
+ depArray = mod.depMaps;
666
+
667
+ if (!mod.inited || !mod.map.isDefine) {
668
+ return;
669
+ }
670
+
671
+ if (traced[id]) {
672
+ return defined[id];
673
+ }
674
+
675
+ traced[id] = mod;
676
+
677
+ each(depArray, function (depMap) {
678
+ var depId = depMap.id,
679
+ depMod = registry[depId],
680
+ value;
681
+
682
+ if (handlers[depId]) {
683
+ return;
684
+ }
685
+
686
+ if (depMod) {
687
+ if (!depMod.inited || !depMod.enabled) {
688
+ //Dependency is not inited,
689
+ //so this module cannot be
690
+ //given a forced value yet.
691
+ uninited[id] = true;
692
+ return;
693
+ }
694
+
695
+ //Get the value for the current dependency
696
+ value = forceExec(depMod, traced, uninited);
697
+
698
+ //Even with forcing it may not be done,
699
+ //in particular if the module is waiting
700
+ //on a plugin resource.
701
+ if (!uninited[depId]) {
702
+ mod.defineDepById(depId, value);
703
+ }
704
+ }
705
+ });
706
+
707
+ mod.check(true);
708
+
709
+ return defined[id];
710
+ }
711
+
712
+ function modCheck(mod) {
713
+ mod.check();
714
+ }
715
+
716
+ function checkLoaded() {
717
+ var map, modId, err, usingPathFallback,
718
+ waitInterval = config.waitSeconds * 1000,
719
+ //It is possible to disable the wait interval by using waitSeconds of 0.
720
+ expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
721
+ noLoads = [],
722
+ stillLoading = false,
723
+ needCycleCheck = true;
724
+
725
+ //Do not bother if this call was a result of a cycle break.
726
+ if (inCheckLoaded) {
727
+ return;
728
+ }
729
+
730
+ inCheckLoaded = true;
731
+
732
+ //Figure out the state of all the modules.
733
+ eachProp(registry, function (mod) {
734
+ map = mod.map;
735
+ modId = map.id;
736
+
737
+ //Skip things that are not enabled or in error state.
738
+ if (!mod.enabled) {
739
+ return;
740
+ }
741
+
742
+ if (!mod.error) {
743
+ //If the module should be executed, and it has not
744
+ //been inited and time is up, remember it.
745
+ if (!mod.inited && expired) {
746
+ if (hasPathFallback(modId)) {
747
+ usingPathFallback = true;
748
+ stillLoading = true;
749
+ } else {
750
+ noLoads.push(modId);
751
+ removeScript(modId);
752
+ }
753
+ } else if (!mod.inited && mod.fetched && map.isDefine) {
754
+ stillLoading = true;
755
+ if (!map.prefix) {
756
+ //No reason to keep looking for unfinished
757
+ //loading. If the only stillLoading is a
758
+ //plugin resource though, keep going,
759
+ //because it may be that a plugin resource
760
+ //is waiting on a non-plugin cycle.
761
+ return (needCycleCheck = false);
762
+ }
763
+ }
764
+ }
765
+ });
766
+
767
+ if (expired && noLoads.length) {
768
+ //If wait time expired, throw error of unloaded modules.
769
+ err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
770
+ err.contextName = context.contextName;
771
+ return onError(err);
772
+ }
773
+
774
+ //Not expired, check for a cycle.
775
+ if (needCycleCheck) {
776
+
777
+ each(waitAry, function (mod) {
778
+ if (mod.defined) {
779
+ return;
780
+ }
781
+
782
+ var cycleMod = findCycle(mod, {}),
783
+ traced = {};
784
+
785
+ if (cycleMod) {
786
+ forceExec(cycleMod, traced, {});
787
+
788
+ //traced modules may have been
789
+ //removed from the registry, but
790
+ //their listeners still need to
791
+ //be called.
792
+ eachProp(traced, modCheck);
793
+ }
794
+ });
795
+
796
+ //Now that dependencies have
797
+ //been satisfied, trigger the
798
+ //completion check that then
799
+ //notifies listeners.
800
+ eachProp(registry, modCheck);
801
+ }
802
+
803
+ //If still waiting on loads, and the waiting load is something
804
+ //other than a plugin resource, or there are still outstanding
805
+ //scripts, then just try back later.
806
+ if ((!expired || usingPathFallback) && stillLoading) {
807
+ //Something is still waiting to load. Wait for it, but only
808
+ //if a timeout is not already in effect.
809
+ if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
810
+ checkLoadedTimeoutId = setTimeout(function () {
811
+ checkLoadedTimeoutId = 0;
812
+ checkLoaded();
813
+ }, 50);
814
+ }
815
+ }
816
+
817
+ inCheckLoaded = false;
818
+ }
819
+
820
+ Module = function (map) {
821
+ this.events = undefEvents[map.id] || {};
822
+ this.map = map;
823
+ this.shim = config.shim[map.id];
824
+ this.depExports = [];
825
+ this.depMaps = [];
826
+ this.depMatched = [];
827
+ this.pluginMaps = {};
828
+ this.depCount = 0;
829
+
830
+ /* this.exports this.factory
831
+ this.depMaps = [],
832
+ this.enabled, this.fetched
833
+ */
834
+ };
835
+
836
+ Module.prototype = {
837
+ init: function (depMaps, factory, errback, options) {
838
+ options = options || {};
839
+
840
+ //Do not do more inits if already done. Can happen if there
841
+ //are multiple define calls for the same module. That is not
842
+ //a normal, common case, but it is also not unexpected.
843
+ if (this.inited) {
844
+ return;
845
+ }
846
+
847
+ this.factory = factory;
848
+
849
+ if (errback) {
850
+ //Register for errors on this module.
851
+ this.on('error', errback);
852
+ } else if (this.events.error) {
853
+ //If no errback already, but there are error listeners
854
+ //on this module, set up an errback to pass to the deps.
855
+ errback = bind(this, function (err) {
856
+ this.emit('error', err);
857
+ });
858
+ }
859
+
860
+ //Do a copy of the dependency array, so that
861
+ //source inputs are not modified. For example
862
+ //"shim" deps are passed in here directly, and
863
+ //doing a direct modification of the depMaps array
864
+ //would affect that config.
865
+ this.depMaps = depMaps && depMaps.slice(0);
866
+ this.depMaps.rjsSkipMap = depMaps.rjsSkipMap;
867
+
868
+ this.errback = errback;
869
+
870
+ //Indicate this module has be initialized
871
+ this.inited = true;
872
+
873
+ this.ignore = options.ignore;
874
+
875
+ //Could have option to init this module in enabled mode,
876
+ //or could have been previously marked as enabled. However,
877
+ //the dependencies are not known until init is called. So
878
+ //if enabled previously, now trigger dependencies as enabled.
879
+ if (options.enabled || this.enabled) {
880
+ //Enable this module and dependencies.
881
+ //Will call this.check()
882
+ this.enable();
883
+ } else {
884
+ this.check();
885
+ }
886
+ },
887
+
888
+ defineDepById: function (id, depExports) {
889
+ var i;
890
+
891
+ //Find the index for this dependency.
892
+ each(this.depMaps, function (map, index) {
893
+ if (map.id === id) {
894
+ i = index;
895
+ return true;
896
+ }
897
+ });
898
+
899
+ return this.defineDep(i, depExports);
900
+ },
901
+
902
+ defineDep: function (i, depExports) {
903
+ //Because of cycles, defined callback for a given
904
+ //export can be called more than once.
905
+ if (!this.depMatched[i]) {
906
+ this.depMatched[i] = true;
907
+ this.depCount -= 1;
908
+ this.depExports[i] = depExports;
909
+ }
910
+ },
911
+
912
+ fetch: function () {
913
+ if (this.fetched) {
914
+ return;
915
+ }
916
+ this.fetched = true;
917
+
918
+ context.startTime = (new Date()).getTime();
919
+
920
+ var map = this.map;
921
+
922
+ //If the manager is for a plugin managed resource,
923
+ //ask the plugin to load it now.
924
+ if (this.shim) {
925
+ makeRequire(this, true)(this.shim.deps || [], bind(this, function () {
926
+ return map.prefix ? this.callPlugin() : this.load();
927
+ }));
928
+ } else {
929
+ //Regular dependency.
930
+ return map.prefix ? this.callPlugin() : this.load();
931
+ }
932
+ },
933
+
934
+ load: function () {
935
+ var url = this.map.url;
936
+
937
+ //Regular dependency.
938
+ if (!urlFetched[url]) {
939
+ urlFetched[url] = true;
940
+ context.load(this.map.id, url);
941
+ }
942
+ },
943
+
944
+ /**
945
+ * Checks is the module is ready to define itself, and if so,
946
+ * define it. If the silent argument is true, then it will just
947
+ * define, but not notify listeners, and not ask for a context-wide
948
+ * check of all loaded modules. That is useful for cycle breaking.
949
+ */
950
+ check: function (silent) {
951
+ if (!this.enabled || this.enabling) {
952
+ return;
953
+ }
954
+
955
+ var err, cjsModule,
956
+ id = this.map.id,
957
+ depExports = this.depExports,
958
+ exports = this.exports,
959
+ factory = this.factory;
960
+
961
+ if (!this.inited) {
962
+ this.fetch();
963
+ } else if (this.error) {
964
+ this.emit('error', this.error);
965
+ } else if (!this.defining) {
966
+ //The factory could trigger another require call
967
+ //that would result in checking this module to
968
+ //define itself again. If already in the process
969
+ //of doing that, skip this work.
970
+ this.defining = true;
971
+
972
+ if (this.depCount < 1 && !this.defined) {
973
+ if (isFunction(factory)) {
974
+ //If there is an error listener, favor passing
975
+ //to that instead of throwing an error.
976
+ if (this.events.error) {
977
+ try {
978
+ exports = context.execCb(id, factory, depExports, exports);
979
+ } catch (e) {
980
+ err = e;
981
+ }
982
+ } else {
983
+ exports = context.execCb(id, factory, depExports, exports);
984
+ }
985
+
986
+ if (this.map.isDefine) {
987
+ //If setting exports via 'module' is in play,
988
+ //favor that over return value and exports. After that,
989
+ //favor a non-undefined return value over exports use.
990
+ cjsModule = this.module;
991
+ if (cjsModule &&
992
+ cjsModule.exports !== undefined &&
993
+ //Make sure it is not already the exports value
994
+ cjsModule.exports !== this.exports) {
995
+ exports = cjsModule.exports;
996
+ } else if (exports === undefined && this.usingExports) {
997
+ //exports already set the defined value.
998
+ exports = this.exports;
999
+ }
1000
+ }
1001
+
1002
+ if (err) {
1003
+ err.requireMap = this.map;
1004
+ err.requireModules = [this.map.id];
1005
+ err.requireType = 'define';
1006
+ return onError((this.error = err));
1007
+ }
1008
+
1009
+ } else {
1010
+ //Just a literal value
1011
+ exports = factory;
1012
+ }
1013
+
1014
+ this.exports = exports;
1015
+
1016
+ if (this.map.isDefine && !this.ignore) {
1017
+ defined[id] = exports;
1018
+
1019
+ if (req.onResourceLoad) {
1020
+ req.onResourceLoad(context, this.map, this.depMaps);
1021
+ }
1022
+ }
1023
+
1024
+ //Clean up
1025
+ delete registry[id];
1026
+
1027
+ this.defined = true;
1028
+ context.waitCount -= 1;
1029
+ if (context.waitCount === 0) {
1030
+ //Clear the wait array used for cycles.
1031
+ waitAry = [];
1032
+ }
1033
+ }
1034
+
1035
+ //Finished the define stage. Allow calling check again
1036
+ //to allow define notifications below in the case of a
1037
+ //cycle.
1038
+ this.defining = false;
1039
+
1040
+ if (!silent) {
1041
+ if (this.defined && !this.defineEmitted) {
1042
+ this.defineEmitted = true;
1043
+ this.emit('defined', this.exports);
1044
+ this.defineEmitComplete = true;
1045
+ }
1046
+ }
1047
+ }
1048
+ },
1049
+
1050
+ callPlugin: function () {
1051
+ var map = this.map,
1052
+ id = map.id,
1053
+ pluginMap = makeModuleMap(map.prefix, null, false, true);
1054
+
1055
+ on(pluginMap, 'defined', bind(this, function (plugin) {
1056
+ var load, normalizedMap, normalizedMod,
1057
+ name = this.map.name,
1058
+ parentName = this.map.parentMap ? this.map.parentMap.name : null;
1059
+
1060
+ //If current map is not normalized, wait for that
1061
+ //normalized name to load instead of continuing.
1062
+ if (this.map.unnormalized) {
1063
+ //Normalize the ID if the plugin allows it.
1064
+ if (plugin.normalize) {
1065
+ name = plugin.normalize(name, function (name) {
1066
+ return normalize(name, parentName, true);
1067
+ }) || '';
1068
+ }
1069
+
1070
+ normalizedMap = makeModuleMap(map.prefix + '!' + name,
1071
+ this.map.parentMap,
1072
+ false,
1073
+ true);
1074
+ on(normalizedMap,
1075
+ 'defined', bind(this, function (value) {
1076
+ this.init([], function () { return value; }, null, {
1077
+ enabled: true,
1078
+ ignore: true
1079
+ });
1080
+ }));
1081
+ normalizedMod = registry[normalizedMap.id];
1082
+ if (normalizedMod) {
1083
+ if (this.events.error) {
1084
+ normalizedMod.on('error', bind(this, function (err) {
1085
+ this.emit('error', err);
1086
+ }));
1087
+ }
1088
+ normalizedMod.enable();
1089
+ }
1090
+
1091
+ return;
1092
+ }
1093
+
1094
+ load = bind(this, function (value) {
1095
+ this.init([], function () { return value; }, null, {
1096
+ enabled: true
1097
+ });
1098
+ });
1099
+
1100
+ load.error = bind(this, function (err) {
1101
+ this.inited = true;
1102
+ this.error = err;
1103
+ err.requireModules = [id];
1104
+
1105
+ //Remove temp unnormalized modules for this module,
1106
+ //since they will never be resolved otherwise now.
1107
+ eachProp(registry, function (mod) {
1108
+ if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
1109
+ removeWaiting(mod.map.id);
1110
+ }
1111
+ });
1112
+
1113
+ onError(err);
1114
+ });
1115
+
1116
+ //Allow plugins to load other code without having to know the
1117
+ //context or how to 'complete' the load.
1118
+ load.fromText = function (moduleName, text) {
1119
+ /*jslint evil: true */
1120
+ var hasInteractive = useInteractive;
1121
+
1122
+ //Turn off interactive script matching for IE for any define
1123
+ //calls in the text, then turn it back on at the end.
1124
+ if (hasInteractive) {
1125
+ useInteractive = false;
1126
+ }
1127
+
1128
+ //Prime the system by creating a module instance for
1129
+ //it.
1130
+ getModule(makeModuleMap(moduleName));
1131
+
1132
+ req.exec(text);
1133
+
1134
+ if (hasInteractive) {
1135
+ useInteractive = true;
1136
+ }
1137
+
1138
+ //Support anonymous modules.
1139
+ context.completeLoad(moduleName);
1140
+ };
1141
+
1142
+ //Use parentName here since the plugin's name is not reliable,
1143
+ //could be some weird string with no path that actually wants to
1144
+ //reference the parentName's path.
1145
+ plugin.load(map.name, makeRequire(map.parentMap, true, function (deps, cb, er) {
1146
+ deps.rjsSkipMap = true;
1147
+ return context.require(deps, cb, er);
1148
+ }), load, config);
1149
+ }));
1150
+
1151
+ context.enable(pluginMap, this);
1152
+ this.pluginMaps[pluginMap.id] = pluginMap;
1153
+ },
1154
+
1155
+ enable: function () {
1156
+ this.enabled = true;
1157
+
1158
+ if (!this.waitPushed) {
1159
+ waitAry.push(this);
1160
+ context.waitCount += 1;
1161
+ this.waitPushed = true;
1162
+ }
1163
+
1164
+ //Set flag mentioning that the module is enabling,
1165
+ //so that immediate calls to the defined callbacks
1166
+ //for dependencies do not trigger inadvertent load
1167
+ //with the depCount still being zero.
1168
+ this.enabling = true;
1169
+
1170
+ //Enable each dependency
1171
+ each(this.depMaps, bind(this, function (depMap, i) {
1172
+ var id, mod, handler;
1173
+
1174
+ if (typeof depMap === 'string') {
1175
+ //Dependency needs to be converted to a depMap
1176
+ //and wired up to this module.
1177
+ depMap = makeModuleMap(depMap,
1178
+ (this.map.isDefine ? this.map : this.map.parentMap),
1179
+ false,
1180
+ !this.depMaps.rjsSkipMap);
1181
+ this.depMaps[i] = depMap;
1182
+
1183
+ handler = handlers[depMap.id];
1184
+
1185
+ if (handler) {
1186
+ this.depExports[i] = handler(this);
1187
+ return;
1188
+ }
1189
+
1190
+ this.depCount += 1;
1191
+
1192
+ on(depMap, 'defined', bind(this, function (depExports) {
1193
+ this.defineDep(i, depExports);
1194
+ this.check();
1195
+ }));
1196
+
1197
+ if (this.errback) {
1198
+ on(depMap, 'error', this.errback);
1199
+ }
1200
+ }
1201
+
1202
+ id = depMap.id;
1203
+ mod = registry[id];
1204
+
1205
+ //Skip special modules like 'require', 'exports', 'module'
1206
+ //Also, don't call enable if it is already enabled,
1207
+ //important in circular dependency cases.
1208
+ if (!handlers[id] && mod && !mod.enabled) {
1209
+ context.enable(depMap, this);
1210
+ }
1211
+ }));
1212
+
1213
+ //Enable each plugin that is used in
1214
+ //a dependency
1215
+ eachProp(this.pluginMaps, bind(this, function (pluginMap) {
1216
+ var mod = registry[pluginMap.id];
1217
+ if (mod && !mod.enabled) {
1218
+ context.enable(pluginMap, this);
1219
+ }
1220
+ }));
1221
+
1222
+ this.enabling = false;
1223
+
1224
+ this.check();
1225
+ },
1226
+
1227
+ on: function (name, cb) {
1228
+ var cbs = this.events[name];
1229
+ if (!cbs) {
1230
+ cbs = this.events[name] = [];
1231
+ }
1232
+ cbs.push(cb);
1233
+ },
1234
+
1235
+ emit: function (name, evt) {
1236
+ each(this.events[name], function (cb) {
1237
+ cb(evt);
1238
+ });
1239
+ if (name === 'error') {
1240
+ //Now that the error handler was triggered, remove
1241
+ //the listeners, since this broken Module instance
1242
+ //can stay around for a while in the registry/waitAry.
1243
+ delete this.events[name];
1244
+ }
1245
+ }
1246
+ };
1247
+
1248
+ function callGetModule(args) {
1249
+ getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
1250
+ }
1251
+
1252
+ function removeListener(node, func, name, ieName) {
1253
+ //Favor detachEvent because of IE9
1254
+ //issue, see attachEvent/addEventListener comment elsewhere
1255
+ //in this file.
1256
+ if (node.detachEvent && !isOpera) {
1257
+ //Probably IE. If not it will throw an error, which will be
1258
+ //useful to know.
1259
+ if (ieName) {
1260
+ node.detachEvent(ieName, func);
1261
+ }
1262
+ } else {
1263
+ node.removeEventListener(name, func, false);
1264
+ }
1265
+ }
1266
+
1267
+ /**
1268
+ * Given an event from a script node, get the requirejs info from it,
1269
+ * and then removes the event listeners on the node.
1270
+ * @param {Event} evt
1271
+ * @returns {Object}
1272
+ */
1273
+ function getScriptData(evt) {
1274
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1275
+ //all old browsers will be supported, but this one was easy enough
1276
+ //to support and still makes sense.
1277
+ var node = evt.currentTarget || evt.srcElement;
1278
+
1279
+ //Remove the listeners once here.
1280
+ removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
1281
+ removeListener(node, context.onScriptError, 'error');
1282
+
1283
+ return {
1284
+ node: node,
1285
+ id: node && node.getAttribute('data-requiremodule')
1286
+ };
1287
+ }
1288
+
1289
+ return (context = {
1290
+ config: config,
1291
+ contextName: contextName,
1292
+ registry: registry,
1293
+ defined: defined,
1294
+ urlFetched: urlFetched,
1295
+ waitCount: 0,
1296
+ defQueue: defQueue,
1297
+ Module: Module,
1298
+ makeModuleMap: makeModuleMap,
1299
+
1300
+ /**
1301
+ * Set a configuration for the context.
1302
+ * @param {Object} cfg config object to integrate.
1303
+ */
1304
+ configure: function (cfg) {
1305
+ //Make sure the baseUrl ends in a slash.
1306
+ if (cfg.baseUrl) {
1307
+ if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
1308
+ cfg.baseUrl += '/';
1309
+ }
1310
+ }
1311
+
1312
+ //Save off the paths and packages since they require special processing,
1313
+ //they are additive.
1314
+ var pkgs = config.pkgs,
1315
+ shim = config.shim,
1316
+ paths = config.paths,
1317
+ map = config.map;
1318
+
1319
+ //Mix in the config values, favoring the new values over
1320
+ //existing ones in context.config.
1321
+ mixin(config, cfg, true);
1322
+
1323
+ //Merge paths.
1324
+ config.paths = mixin(paths, cfg.paths, true);
1325
+
1326
+ //Merge map
1327
+ if (cfg.map) {
1328
+ config.map = mixin(map || {}, cfg.map, true, true);
1329
+ }
1330
+
1331
+ //Merge shim
1332
+ if (cfg.shim) {
1333
+ eachProp(cfg.shim, function (value, id) {
1334
+ //Normalize the structure
1335
+ if (isArray(value)) {
1336
+ value = {
1337
+ deps: value
1338
+ };
1339
+ }
1340
+ if (value.exports && !value.exports.__buildReady) {
1341
+ value.exports = context.makeShimExports(value.exports);
1342
+ }
1343
+ shim[id] = value;
1344
+ });
1345
+ config.shim = shim;
1346
+ }
1347
+
1348
+ //Adjust packages if necessary.
1349
+ if (cfg.packages) {
1350
+ each(cfg.packages, function (pkgObj) {
1351
+ var location;
1352
+
1353
+ pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
1354
+ location = pkgObj.location;
1355
+
1356
+ //Create a brand new object on pkgs, since currentPackages can
1357
+ //be passed in again, and config.pkgs is the internal transformed
1358
+ //state for all package configs.
1359
+ pkgs[pkgObj.name] = {
1360
+ name: pkgObj.name,
1361
+ location: location || pkgObj.name,
1362
+ //Remove leading dot in main, so main paths are normalized,
1363
+ //and remove any trailing .js, since different package
1364
+ //envs have different conventions: some use a module name,
1365
+ //some use a file name.
1366
+ main: (pkgObj.main || 'main')
1367
+ .replace(currDirRegExp, '')
1368
+ .replace(jsSuffixRegExp, '')
1369
+ };
1370
+ });
1371
+
1372
+ //Done with modifications, assing packages back to context config
1373
+ config.pkgs = pkgs;
1374
+ }
1375
+
1376
+ //If there are any "waiting to execute" modules in the registry,
1377
+ //update the maps for them, since their info, like URLs to load,
1378
+ //may have changed.
1379
+ eachProp(registry, function (mod, id) {
1380
+ //If module already has init called, since it is too
1381
+ //late to modify them, and ignore unnormalized ones
1382
+ //since they are transient.
1383
+ if (!mod.inited && !mod.map.unnormalized) {
1384
+ mod.map = makeModuleMap(id);
1385
+ }
1386
+ });
1387
+
1388
+ //If a deps array or a config callback is specified, then call
1389
+ //require with those args. This is useful when require is defined as a
1390
+ //config object before require.js is loaded.
1391
+ if (cfg.deps || cfg.callback) {
1392
+ context.require(cfg.deps || [], cfg.callback);
1393
+ }
1394
+ },
1395
+
1396
+ makeShimExports: function (exports) {
1397
+ var func;
1398
+ if (typeof exports === 'string') {
1399
+ func = function () {
1400
+ return getGlobal(exports);
1401
+ };
1402
+ //Save the exports for use in nodefine checking.
1403
+ func.exports = exports;
1404
+ return func;
1405
+ } else {
1406
+ return function () {
1407
+ return exports.apply(global, arguments);
1408
+ };
1409
+ }
1410
+ },
1411
+
1412
+ requireDefined: function (id, relMap) {
1413
+ return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
1414
+ },
1415
+
1416
+ requireSpecified: function (id, relMap) {
1417
+ id = makeModuleMap(id, relMap, false, true).id;
1418
+ return hasProp(defined, id) || hasProp(registry, id);
1419
+ },
1420
+
1421
+ require: function (deps, callback, errback, relMap) {
1422
+ var moduleName, id, map, requireMod, args;
1423
+ if (typeof deps === 'string') {
1424
+ if (isFunction(callback)) {
1425
+ //Invalid call
1426
+ return onError(makeError('requireargs', 'Invalid require call'), errback);
1427
+ }
1428
+
1429
+ //Synchronous access to one module. If require.get is
1430
+ //available (as in the Node adapter), prefer that.
1431
+ //In this case deps is the moduleName and callback is
1432
+ //the relMap
1433
+ if (req.get) {
1434
+ return req.get(context, deps, callback);
1435
+ }
1436
+
1437
+ //Just return the module wanted. In this scenario, the
1438
+ //second arg (if passed) is just the relMap.
1439
+ moduleName = deps;
1440
+ relMap = callback;
1441
+
1442
+ //Normalize module name, if it contains . or ..
1443
+ map = makeModuleMap(moduleName, relMap, false, true);
1444
+ id = map.id;
1445
+
1446
+ if (!hasProp(defined, id)) {
1447
+ return onError(makeError('notloaded', 'Module name "' +
1448
+ id +
1449
+ '" has not been loaded yet for context: ' +
1450
+ contextName));
1451
+ }
1452
+ return defined[id];
1453
+ }
1454
+
1455
+ //Callback require. Normalize args. if callback or errback is
1456
+ //not a function, it means it is a relMap. Test errback first.
1457
+ if (errback && !isFunction(errback)) {
1458
+ relMap = errback;
1459
+ errback = undefined;
1460
+ }
1461
+ if (callback && !isFunction(callback)) {
1462
+ relMap = callback;
1463
+ callback = undefined;
1464
+ }
1465
+
1466
+ //Any defined modules in the global queue, intake them now.
1467
+ takeGlobalQueue();
1468
+
1469
+ //Make sure any remaining defQueue items get properly processed.
1470
+ while (defQueue.length) {
1471
+ args = defQueue.shift();
1472
+ if (args[0] === null) {
1473
+ return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
1474
+ } else {
1475
+ //args are id, deps, factory. Should be normalized by the
1476
+ //define() function.
1477
+ callGetModule(args);
1478
+ }
1479
+ }
1480
+
1481
+ //Mark all the dependencies as needing to be loaded.
1482
+ requireMod = getModule(makeModuleMap(null, relMap));
1483
+
1484
+ requireMod.init(deps, callback, errback, {
1485
+ enabled: true
1486
+ });
1487
+
1488
+ checkLoaded();
1489
+
1490
+ return context.require;
1491
+ },
1492
+
1493
+ undef: function (id) {
1494
+ //Bind any waiting define() calls to this context,
1495
+ //fix for #408
1496
+ takeGlobalQueue();
1497
+
1498
+ var map = makeModuleMap(id, null, true),
1499
+ mod = registry[id];
1500
+
1501
+ delete defined[id];
1502
+ delete urlFetched[map.url];
1503
+ delete undefEvents[id];
1504
+
1505
+ if (mod) {
1506
+ //Hold on to listeners in case the
1507
+ //module will be attempted to be reloaded
1508
+ //using a different config.
1509
+ if (mod.events.defined) {
1510
+ undefEvents[id] = mod.events;
1511
+ }
1512
+
1513
+ removeWaiting(id);
1514
+ }
1515
+ },
1516
+
1517
+ /**
1518
+ * Called to enable a module if it is still in the registry
1519
+ * awaiting enablement. parent module is passed in for context,
1520
+ * used by the optimizer.
1521
+ */
1522
+ enable: function (depMap, parent) {
1523
+ var mod = registry[depMap.id];
1524
+ if (mod) {
1525
+ getModule(depMap).enable();
1526
+ }
1527
+ },
1528
+
1529
+ /**
1530
+ * Internal method used by environment adapters to complete a load event.
1531
+ * A load event could be a script load or just a load pass from a synchronous
1532
+ * load call.
1533
+ * @param {String} moduleName the name of the module to potentially complete.
1534
+ */
1535
+ completeLoad: function (moduleName) {
1536
+ var found, args, mod,
1537
+ shim = config.shim[moduleName] || {},
1538
+ shExports = shim.exports && shim.exports.exports;
1539
+
1540
+ takeGlobalQueue();
1541
+
1542
+ while (defQueue.length) {
1543
+ args = defQueue.shift();
1544
+ if (args[0] === null) {
1545
+ args[0] = moduleName;
1546
+ //If already found an anonymous module and bound it
1547
+ //to this name, then this is some other anon module
1548
+ //waiting for its completeLoad to fire.
1549
+ if (found) {
1550
+ break;
1551
+ }
1552
+ found = true;
1553
+ } else if (args[0] === moduleName) {
1554
+ //Found matching define call for this script!
1555
+ found = true;
1556
+ }
1557
+
1558
+ callGetModule(args);
1559
+ }
1560
+
1561
+ //Do this after the cycle of callGetModule in case the result
1562
+ //of those calls/init calls changes the registry.
1563
+ mod = registry[moduleName];
1564
+
1565
+ if (!found && !defined[moduleName] && mod && !mod.inited) {
1566
+ if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
1567
+ if (hasPathFallback(moduleName)) {
1568
+ return;
1569
+ } else {
1570
+ return onError(makeError('nodefine',
1571
+ 'No define call for ' + moduleName,
1572
+ null,
1573
+ [moduleName]));
1574
+ }
1575
+ } else {
1576
+ //A script that does not call define(), so just simulate
1577
+ //the call for it.
1578
+ callGetModule([moduleName, (shim.deps || []), shim.exports]);
1579
+ }
1580
+ }
1581
+
1582
+ checkLoaded();
1583
+ },
1584
+
1585
+ /**
1586
+ * Converts a module name + .extension into an URL path.
1587
+ * *Requires* the use of a module name. It does not support using
1588
+ * plain URLs like nameToUrl.
1589
+ */
1590
+ toUrl: function (moduleNamePlusExt, relModuleMap) {
1591
+ var index = moduleNamePlusExt.lastIndexOf('.'),
1592
+ ext = null;
1593
+
1594
+ if (index !== -1) {
1595
+ ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
1596
+ moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
1597
+ }
1598
+
1599
+ return context.nameToUrl(normalize(moduleNamePlusExt, relModuleMap && relModuleMap.id, true),
1600
+ ext);
1601
+ },
1602
+
1603
+ /**
1604
+ * Converts a module name to a file path. Supports cases where
1605
+ * moduleName may actually be just an URL.
1606
+ * Note that it **does not** call normalize on the moduleName,
1607
+ * it is assumed to have already been normalized. This is an
1608
+ * internal API, not a public one. Use toUrl for the public API.
1609
+ */
1610
+ nameToUrl: function (moduleName, ext) {
1611
+ var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
1612
+ parentPath;
1613
+
1614
+ //If a colon is in the URL, it indicates a protocol is used and it is just
1615
+ //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
1616
+ //or ends with .js, then assume the user meant to use an url and not a module id.
1617
+ //The slash is important for protocol-less URLs as well as full paths.
1618
+ if (req.jsExtRegExp.test(moduleName)) {
1619
+ //Just a plain path, not module name lookup, so just return it.
1620
+ //Add extension if it is included. This is a bit wonky, only non-.js things pass
1621
+ //an extension, this method probably needs to be reworked.
1622
+ url = moduleName + (ext || '');
1623
+ } else {
1624
+ //A module that needs to be converted to a path.
1625
+ paths = config.paths;
1626
+ pkgs = config.pkgs;
1627
+
1628
+ syms = moduleName.split('/');
1629
+ //For each module name segment, see if there is a path
1630
+ //registered for it. Start with most specific name
1631
+ //and work up from it.
1632
+ for (i = syms.length; i > 0; i -= 1) {
1633
+ parentModule = syms.slice(0, i).join('/');
1634
+ pkg = pkgs[parentModule];
1635
+ parentPath = paths[parentModule];
1636
+ if (parentPath) {
1637
+ //If an array, it means there are a few choices,
1638
+ //Choose the one that is desired
1639
+ if (isArray(parentPath)) {
1640
+ parentPath = parentPath[0];
1641
+ }
1642
+ syms.splice(0, i, parentPath);
1643
+ break;
1644
+ } else if (pkg) {
1645
+ //If module name is just the package name, then looking
1646
+ //for the main module.
1647
+ if (moduleName === pkg.name) {
1648
+ pkgPath = pkg.location + '/' + pkg.main;
1649
+ } else {
1650
+ pkgPath = pkg.location;
1651
+ }
1652
+ syms.splice(0, i, pkgPath);
1653
+ break;
1654
+ }
1655
+ }
1656
+
1657
+ //Join the path parts together, then figure out if baseUrl is needed.
1658
+ url = syms.join('/');
1659
+ url += (ext || (/\?/.test(url) ? '' : '.js'));
1660
+ url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
1661
+ }
1662
+
1663
+ return config.urlArgs ? url +
1664
+ ((url.indexOf('?') === -1 ? '?' : '&') +
1665
+ config.urlArgs) : url;
1666
+ },
1667
+
1668
+ //Delegates to req.load. Broken out as a separate function to
1669
+ //allow overriding in the optimizer.
1670
+ load: function (id, url) {
1671
+ req.load(context, id, url);
1672
+ },
1673
+
1674
+ /**
1675
+ * Executes a module callack function. Broken out as a separate function
1676
+ * solely to allow the build system to sequence the files in the built
1677
+ * layer in the right sequence.
1678
+ *
1679
+ * @private
1680
+ */
1681
+ execCb: function (name, callback, args, exports) {
1682
+ return callback.apply(exports, args);
1683
+ },
1684
+
1685
+ /**
1686
+ * callback for script loads, used to check status of loading.
1687
+ *
1688
+ * @param {Event} evt the event from the browser for the script
1689
+ * that was loaded.
1690
+ */
1691
+ onScriptLoad: function (evt) {
1692
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1693
+ //all old browsers will be supported, but this one was easy enough
1694
+ //to support and still makes sense.
1695
+ if (evt.type === 'load' ||
1696
+ (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
1697
+ //Reset interactive script so a script node is not held onto for
1698
+ //to long.
1699
+ interactiveScript = null;
1700
+
1701
+ //Pull out the name of the module and the context.
1702
+ var data = getScriptData(evt);
1703
+ context.completeLoad(data.id);
1704
+ }
1705
+ },
1706
+
1707
+ /**
1708
+ * Callback for script errors.
1709
+ */
1710
+ onScriptError: function (evt) {
1711
+ var data = getScriptData(evt);
1712
+ if (!hasPathFallback(data.id)) {
1713
+ return onError(makeError('scripterror', 'Script error', evt, [data.id]));
1714
+ }
1715
+ }
1716
+ });
1717
+ }
1718
+
1719
+ /**
1720
+ * Main entry point.
1721
+ *
1722
+ * If the only argument to require is a string, then the module that
1723
+ * is represented by that string is fetched for the appropriate context.
1724
+ *
1725
+ * If the first argument is an array, then it will be treated as an array
1726
+ * of dependency string names to fetch. An optional function callback can
1727
+ * be specified to execute when all of those dependencies are available.
1728
+ *
1729
+ * Make a local req variable to help Caja compliance (it assumes things
1730
+ * on a require that are not standardized), and to give a short
1731
+ * name for minification/local scope use.
1732
+ */
1733
+ req = requirejs = function (deps, callback, errback, optional) {
1734
+
1735
+ //Find the right context, use default
1736
+ var context, config,
1737
+ contextName = defContextName;
1738
+
1739
+ // Determine if have config object in the call.
1740
+ if (!isArray(deps) && typeof deps !== 'string') {
1741
+ // deps is a config object
1742
+ config = deps;
1743
+ if (isArray(callback)) {
1744
+ // Adjust args if there are dependencies
1745
+ deps = callback;
1746
+ callback = errback;
1747
+ errback = optional;
1748
+ } else {
1749
+ deps = [];
1750
+ }
1751
+ }
1752
+
1753
+ if (config && config.context) {
1754
+ contextName = config.context;
1755
+ }
1756
+
1757
+ context = contexts[contextName];
1758
+ if (!context) {
1759
+ context = contexts[contextName] = req.s.newContext(contextName);
1760
+ }
1761
+
1762
+ if (config) {
1763
+ context.configure(config);
1764
+ }
1765
+
1766
+ return context.require(deps, callback, errback);
1767
+ };
1768
+
1769
+ /**
1770
+ * Support require.config() to make it easier to cooperate with other
1771
+ * AMD loaders on globally agreed names.
1772
+ */
1773
+ req.config = function (config) {
1774
+ return req(config);
1775
+ };
1776
+
1777
+ /**
1778
+ * Export require as a global, but only if it does not already exist.
1779
+ */
1780
+ if (!require) {
1781
+ require = req;
1782
+ }
1783
+
1784
+ req.version = version;
1785
+
1786
+ //Used to filter out dependencies that are already paths.
1787
+ req.jsExtRegExp = /^\/|:|\?|\.js$/;
1788
+ req.isBrowser = isBrowser;
1789
+ s = req.s = {
1790
+ contexts: contexts,
1791
+ newContext: newContext
1792
+ };
1793
+
1794
+ //Create default context.
1795
+ req({});
1796
+
1797
+ //Exports some context-sensitive methods on global require, using
1798
+ //default context if no context specified.
1799
+ addRequireMethods(req);
1800
+
1801
+ if (isBrowser) {
1802
+ head = s.head = document.getElementsByTagName('head')[0];
1803
+ //If BASE tag is in play, using appendChild is a problem for IE6.
1804
+ //When that browser dies, this can be removed. Details in this jQuery bug:
1805
+ //http://dev.jquery.com/ticket/2709
1806
+ baseElement = document.getElementsByTagName('base')[0];
1807
+ if (baseElement) {
1808
+ head = s.head = baseElement.parentNode;
1809
+ }
1810
+ }
1811
+
1812
+ /**
1813
+ * Any errors that require explicitly generates will be passed to this
1814
+ * function. Intercept/override it if you want custom error handling.
1815
+ * @param {Error} err the error object.
1816
+ */
1817
+ req.onError = function (err) {
1818
+ throw err;
1819
+ };
1820
+
1821
+ /**
1822
+ * Does the request to load a module for the browser case.
1823
+ * Make this a separate function to allow other environments
1824
+ * to override it.
1825
+ *
1826
+ * @param {Object} context the require context to find state.
1827
+ * @param {String} moduleName the name of the module.
1828
+ * @param {Object} url the URL to the module.
1829
+ */
1830
+ req.load = function (context, moduleName, url) {
1831
+ var config = (context && context.config) || {},
1832
+ node;
1833
+ if (isBrowser) {
1834
+ //In the browser so use a script tag
1835
+ node = config.xhtml ?
1836
+ document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
1837
+ document.createElement('script');
1838
+ node.type = config.scriptType || 'text/javascript';
1839
+ node.charset = 'utf-8';
1840
+ node.async = true;
1841
+
1842
+ node.setAttribute('data-requirecontext', context.contextName);
1843
+ node.setAttribute('data-requiremodule', moduleName);
1844
+
1845
+ //Set up load listener. Test attachEvent first because IE9 has
1846
+ //a subtle issue in its addEventListener and script onload firings
1847
+ //that do not match the behavior of all other browsers with
1848
+ //addEventListener support, which fire the onload event for a
1849
+ //script right after the script execution. See:
1850
+ //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
1851
+ //UNFORTUNATELY Opera implements attachEvent but does not follow the script
1852
+ //script execution mode.
1853
+ if (node.attachEvent &&
1854
+ //Check if node.attachEvent is artificially added by custom script or
1855
+ //natively supported by browser
1856
+ //read https://github.com/jrburke/requirejs/issues/187
1857
+ //if we can NOT find [native code] then it must NOT natively supported.
1858
+ //in IE8, node.attachEvent does not have toString()
1859
+ //Note the test for "[native code" with no closing brace, see:
1860
+ //https://github.com/jrburke/requirejs/issues/273
1861
+ !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
1862
+ !isOpera) {
1863
+ //Probably IE. IE (at least 6-8) do not fire
1864
+ //script onload right after executing the script, so
1865
+ //we cannot tie the anonymous define call to a name.
1866
+ //However, IE reports the script as being in 'interactive'
1867
+ //readyState at the time of the define call.
1868
+ useInteractive = true;
1869
+
1870
+ node.attachEvent('onreadystatechange', context.onScriptLoad);
1871
+ //It would be great to add an error handler here to catch
1872
+ //404s in IE9+. However, onreadystatechange will fire before
1873
+ //the error handler, so that does not help. If addEvenListener
1874
+ //is used, then IE will fire error before load, but we cannot
1875
+ //use that pathway given the connect.microsoft.com issue
1876
+ //mentioned above about not doing the 'script execute,
1877
+ //then fire the script load event listener before execute
1878
+ //next script' that other browsers do.
1879
+ //Best hope: IE10 fixes the issues,
1880
+ //and then destroys all installs of IE 6-9.
1881
+ //node.attachEvent('onerror', context.onScriptError);
1882
+ } else {
1883
+ node.addEventListener('load', context.onScriptLoad, false);
1884
+ node.addEventListener('error', context.onScriptError, false);
1885
+ }
1886
+ node.src = url;
1887
+
1888
+ //For some cache cases in IE 6-8, the script executes before the end
1889
+ //of the appendChild execution, so to tie an anonymous define
1890
+ //call to the module name (which is stored on the node), hold on
1891
+ //to a reference to this node, but clear after the DOM insertion.
1892
+ currentlyAddingScript = node;
1893
+ if (baseElement) {
1894
+ head.insertBefore(node, baseElement);
1895
+ } else {
1896
+ head.appendChild(node);
1897
+ }
1898
+ currentlyAddingScript = null;
1899
+
1900
+ return node;
1901
+ } else if (isWebWorker) {
1902
+ //In a web worker, use importScripts. This is not a very
1903
+ //efficient use of importScripts, importScripts will block until
1904
+ //its script is downloaded and evaluated. However, if web workers
1905
+ //are in play, the expectation that a build has been done so that
1906
+ //only one script needs to be loaded anyway. This may need to be
1907
+ //reevaluated if other use cases become common.
1908
+ importScripts(url);
1909
+
1910
+ //Account for anonymous modules
1911
+ context.completeLoad(moduleName);
1912
+ }
1913
+ };
1914
+
1915
+ function getInteractiveScript() {
1916
+ if (interactiveScript && interactiveScript.readyState === 'interactive') {
1917
+ return interactiveScript;
1918
+ }
1919
+
1920
+ eachReverse(scripts(), function (script) {
1921
+ if (script.readyState === 'interactive') {
1922
+ return (interactiveScript = script);
1923
+ }
1924
+ });
1925
+ return interactiveScript;
1926
+ }
1927
+
1928
+ //Look for a data-main script attribute, which could also adjust the baseUrl.
1929
+ if (isBrowser) {
1930
+ //Figure out baseUrl. Get it from the script tag with require.js in it.
1931
+ eachReverse(scripts(), function (script) {
1932
+ //Set the 'head' where we can append children by
1933
+ //using the script's parent.
1934
+ if (!head) {
1935
+ head = script.parentNode;
1936
+ }
1937
+
1938
+ //Look for a data-main attribute to set main script for the page
1939
+ //to load. If it is there, the path to data main becomes the
1940
+ //baseUrl, if it is not already set.
1941
+ dataMain = script.getAttribute('data-main');
1942
+ if (dataMain) {
1943
+ //Set final baseUrl if there is not already an explicit one.
1944
+ if (!cfg.baseUrl) {
1945
+ //Pull off the directory of data-main for use as the
1946
+ //baseUrl.
1947
+ src = dataMain.split('/');
1948
+ mainScript = src.pop();
1949
+ subPath = src.length ? src.join('/') + '/' : './';
1950
+
1951
+ cfg.baseUrl = subPath;
1952
+ dataMain = mainScript;
1953
+ }
1954
+
1955
+ //Strip off any trailing .js since dataMain is now
1956
+ //like a module name.
1957
+ dataMain = dataMain.replace(jsSuffixRegExp, '');
1958
+
1959
+ //Put the data-main script in the files to load.
1960
+ cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
1961
+
1962
+ return true;
1963
+ }
1964
+ });
1965
+ }
1966
+
1967
+ /**
1968
+ * The function that handles definitions of modules. Differs from
1969
+ * require() in that a string for the module should be the first argument,
1970
+ * and the function to execute after dependencies are loaded should
1971
+ * return a value to define the module corresponding to the first argument's
1972
+ * name.
1973
+ */
1974
+ define = function (name, deps, callback) {
1975
+ var node, context;
1976
+
1977
+ //Allow for anonymous functions
1978
+ if (typeof name !== 'string') {
1979
+ //Adjust args appropriately
1980
+ callback = deps;
1981
+ deps = name;
1982
+ name = null;
1983
+ }
1984
+
1985
+ //This module may not have dependencies
1986
+ if (!isArray(deps)) {
1987
+ callback = deps;
1988
+ deps = [];
1989
+ }
1990
+
1991
+ //If no name, and callback is a function, then figure out if it a
1992
+ //CommonJS thing with dependencies.
1993
+ if (!deps.length && isFunction(callback)) {
1994
+ //Remove comments from the callback string,
1995
+ //look for require calls, and pull them into the dependencies,
1996
+ //but only if there are function args.
1997
+ if (callback.length) {
1998
+ callback
1999
+ .toString()
2000
+ .replace(commentRegExp, '')
2001
+ .replace(cjsRequireRegExp, function (match, dep) {
2002
+ deps.push(dep);
2003
+ });
2004
+
2005
+ //May be a CommonJS thing even without require calls, but still
2006
+ //could use exports, and module. Avoid doing exports and module
2007
+ //work though if it just needs require.
2008
+ //REQUIRES the function to expect the CommonJS variables in the
2009
+ //order listed below.
2010
+ deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
2011
+ }
2012
+ }
2013
+
2014
+ //If in IE 6-8 and hit an anonymous define() call, do the interactive
2015
+ //work.
2016
+ if (useInteractive) {
2017
+ node = currentlyAddingScript || getInteractiveScript();
2018
+ if (node) {
2019
+ if (!name) {
2020
+ name = node.getAttribute('data-requiremodule');
2021
+ }
2022
+ context = contexts[node.getAttribute('data-requirecontext')];
2023
+ }
2024
+ }
2025
+
2026
+ //Always save off evaluating the def call until the script onload handler.
2027
+ //This allows multiple modules to be in a file without prematurely
2028
+ //tracing dependencies, and allows for anonymous module support,
2029
+ //where the module name is not known until the script onload event
2030
+ //occurs. If no context, use the global queue, and get it processed
2031
+ //in the onscript load callback.
2032
+ (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
2033
+ };
2034
+
2035
+ define.amd = {
2036
+ jQuery: true
2037
+ };
2038
+
2039
+
2040
+ /**
2041
+ * Executes the text. Normally just uses eval, but can be modified
2042
+ * to use a better, environment-specific call. Only used for transpiling
2043
+ * loader plugins, not for plain JS modules.
2044
+ * @param {String} text the text to execute/evaluate.
2045
+ */
2046
+ req.exec = function (text) {
2047
+ /*jslint evil: true */
2048
+ return eval(text);
2049
+ };
2050
+
2051
+ //Set up with config info.
2052
+ req(cfg);
2053
+ }(this));