test<\/td><\/tr><\/tbody>";
309 | buggy = typeof el.tBodies[0] == "undefined";
310 | }
311 | }catch(e){}
312 | return buggy;
313 | });
314 |
315 | addtest("bug-script-rejects-textnode-append", function(g, d){
316 | var buggy = true,
317 | script = d.createElement("script");
318 |
319 | try{
320 | script.appendChild(d.createTextNode(""));
321 | buggy = !script.firstChild ||
322 | (script.firstChild && script.firstChild.nodeType != 3);
323 | }catch(e){}
324 | return buggy;
325 | });
326 |
327 | addtest("bug-getelementbyid-ids-names", function(g, d){
328 | var input
329 | name = "__test_" + Number(new Date()),
330 | root = d.getElementsByTagName("head")[0] || d.documentElement,
331 | buggy = null;
332 |
333 | if(has("dom-create-attr")){
334 | input = d.createElement(" ");
335 | }else{
336 | input = d.createElement("input");
337 | input.name = name;
338 | }
339 | try{
340 | root.insertBefore(input, root.firstChild);
341 | buggy = d.getElementById(name) == input;
342 | root.removeChild(input);
343 | }catch(e){}
344 | return buggy;
345 | });
346 |
347 | addtest("bug-getelementbyid-ignores-case", function(g, d){
348 | var buggy,
349 | id = "__test_" + Number(new Date()),
350 | script = d.createElement("script"),
351 | root = d.getElementsByTagName('script')[0].parentNode;
352 |
353 | script.id = id;
354 | script.type = "text/javascript";
355 | root.insertBefore(script, root.firstChild);
356 | buggy = d.getElementById(id.toUpperCase()) == script;
357 | root.removeChild(script);
358 | return buggy;
359 | });
360 |
361 | addtest("bug-getelementsbyname", function(g, d, el){
362 | var buggy,
363 | script = d.createElement("script"),
364 | id = "__test_" + Number(new Date()),
365 | root = d.getElementsByTagName('script')[0].parentNode;
366 |
367 | script.id = id;
368 | script.type = "text/javascript";
369 | root.insertBefore(script, root.firstChild);
370 | buggy = d.getElementsByName(id)[0] == script;
371 | root.removeChild(script);
372 | return buggy;
373 | });
374 |
375 | addtest("bug-xpath-position", function(g, d, el){
376 | var buggy = null,
377 | xpath = ".//*[local-name()='p' or local-name()='P'][position() = 2]";
378 |
379 | if(has.isHostType(d, "evaluate") && has.isHostType(g, "XPathResult")){
380 | el.appendChild(d.createElement("p")).appendChild(d.createTextNode("a"));
381 | el.appendChild(d.createElement("p")).appendChild(d.createTextNode("b"));
382 | xpath = d.evaluate(xpath, el, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
383 |
384 | if(xpath && has.isHostType(xpath, "snapshotItem")){
385 | xpath = xpath.snapshotItem(0);
386 | buggy = !!(xpath && xpath.firstChild) && xpath.firstChild.nodeValue != "b";
387 | }
388 | has.clearElement(el);
389 | }
390 | return buggy;
391 | });
392 |
393 | addtest("bug-overflow-style", function(g, d, el){
394 | el.innerHTML = "x
";
395 |
396 | var buggy = null,
397 | p = el.firstChild,
398 | style = p && p.style;
399 |
400 | if(style){
401 | style.overflow = "hidden";
402 | buggy = style.overflow != "hidden";
403 | }
404 | el.innerHTML = "";
405 | return buggy;
406 | });
407 |
408 | // TODO: Add more QSA tests
409 | addtest("bug-qsa", function(g, d, el){
410 | var buggy = null;
411 | if(has.isHostType(el, "querySelectorAll")){
412 | el.appendChild(d.createElement("object"))
413 | .appendChild(d.createElement("param"));
414 | buggy = el.querySelectorAll("param").length != 1;
415 | has.clearElement(el);
416 | }
417 | return buggy;
418 | });
419 |
420 | addtest("bug-string-split-regexp", function(){
421 | var buggy = null, s = "a_b";
422 | if(toString.call(s.split) == FUNCTION_CLASS){
423 | buggy = s.split(/(_)/).length != 3;
424 | }
425 | return buggy;
426 | });
427 |
428 | addtest("bug-function-expression", function(){
429 | // `x` should be resolved to `null` (the one we declared outside this function)
430 | // but since named function expression identifier leaks onto the enclosing scope in IE,
431 | // it will be resolved to a function
432 | var f = function x(){},
433 | buggy = typeof x == FN;
434 | if(buggy){
435 | x = null;
436 | }
437 | return buggy;
438 | });
439 |
440 | addtest("bug-string-replace-ignores-functions", function(){
441 | var buggy = null, s = "a";
442 | if(toString.call(s.replace) == FUNCTION_CLASS){
443 | buggy = s.replace(s, function(){ return ""; }) != "";
444 | }
445 | return buggy;
446 | });
447 |
448 | addtest("bug-arguments-instanceof-array", function(g){
449 | return arguments instanceof g.Array;
450 | });
451 |
452 | addtest("bug-array-concat-arguments", function(){
453 | return (function(){
454 | var buggy = null;
455 | if(has("bug-arguments-instanceof-array")){
456 | buggy = [].concat(arguments)[0] != 1;
457 | }
458 | return buggy;
459 | })(1,2);
460 | });
461 |
462 | addtest("bug-dontenum-enumerable", function(){
463 | for(var prop in { toString: true }){
464 | return false;
465 | }
466 | return true;
467 | });
468 |
469 | // ES5 added (\uFEFF) as a whitespace character
470 | var whitespace = "\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u180E\u2000\u2001\u2002"+
471 | "\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
472 |
473 | addtest("bug-es5-trim", function(){
474 | var buggy = null;
475 | if(has("string-trim")){
476 | buggy = !!whitespace.trim();
477 | }
478 | return buggy;
479 | });
480 |
481 | addtest("bug-es5-regexp", function(){
482 | return !(/^\s+$/).test(whitespace);
483 | });
484 |
485 | addtest("bug-tofixed-rounding", function(){
486 | return (.9).toFixed() == 0;
487 | });
488 |
489 | return has;
490 | });
491 | })(typeof define != "undefined" ? define : function(deps, factory){
492 | factory(has); // the use global has() if a module system is not available
493 | });
494 |
--------------------------------------------------------------------------------
/tests/require.js:
--------------------------------------------------------------------------------
1 | /** vim: et:ts=4:sw=4:sts=4
2 | * @license RequireJS 0.14.5 Copyright (c) 2010, 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 | //laxbreak is true to allow build pragmas to change some statements.
7 | /*jslint plusplus: false, nomen: false, laxbreak: true, regexp: false */
8 | /*global window: false, document: false, navigator: false,
9 | setTimeout: false, traceDeps: true, clearInterval: false, self: false,
10 | setInterval: false, importScripts: false, jQuery: false */
11 | "use strict";
12 |
13 | var require, define;
14 | (function () {
15 | //Change this version number for each release.
16 | var version = "0.14.5+",
17 | empty = {}, s,
18 | i, defContextName = "_", contextLoads = [],
19 | scripts, script, rePkg, src, m, dataMain, cfg = {}, setReadyState,
20 | readyRegExp = /^(complete|loaded)$/,
21 | commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,
22 | cjsRequireRegExp = /require\(["']([\w-_\.\/]+)["']\)/g,
23 | main,
24 | isBrowser = !!(typeof window !== "undefined" && navigator && document),
25 | isWebWorker = !isBrowser && typeof importScripts !== "undefined",
26 | ostring = Object.prototype.toString,
27 | ap = Array.prototype,
28 | aps = ap.slice, scrollIntervalId, req, baseElement,
29 | defQueue = [], useInteractive = false, currentlyAddingScript;
30 |
31 | function isFunction(it) {
32 | return ostring.call(it) === "[object Function]";
33 | }
34 |
35 | //Check for an existing version of require. If so, then exit out. Only allow
36 | //one version of require to be active in a page. However, allow for a require
37 | //config object, just exit quickly if require is an actual function.
38 | if (typeof require !== "undefined") {
39 | if (isFunction(require)) {
40 | return;
41 | } else {
42 | //assume it is a config object.
43 | cfg = require;
44 | }
45 | }
46 |
47 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
48 | /**
49 | * Calls a method on a plugin. The obj object should have two property,
50 | * name: the name of the method to call on the plugin
51 | * args: the arguments to pass to the plugin method.
52 | */
53 | function callPlugin(prefix, context, obj) {
54 | //Call the plugin, or load it.
55 | var plugin = s.plugins.defined[prefix], waiting;
56 | if (plugin) {
57 | plugin[obj.name].apply(null, obj.args);
58 | } else {
59 | //Put the call in the waiting call BEFORE requiring the module,
60 | //since the require could be synchronous in some environments,
61 | //like builds
62 | waiting = s.plugins.waiting[prefix] || (s.plugins.waiting[prefix] = []);
63 | waiting.push(obj);
64 |
65 | //Load the module
66 | req(["require/" + prefix], context.contextName);
67 | }
68 | }
69 | //>>excludeEnd("requireExcludePlugin");
70 |
71 | /**
72 | * Convenience method to call main for a require.def call that was put on
73 | * hold in the defQueue.
74 | */
75 | function callDefMain(args, context) {
76 | main.apply(req, args);
77 | //Mark the module loaded. Must do it here in addition
78 | //to doing it in require.def in case a script does
79 | //not call require.def
80 | context.loaded[args[0]] = true;
81 | }
82 |
83 | /**
84 | * Used to set up package paths from a packagePaths or packages config object.
85 | * @param {Object} packages the object to store the new package config
86 | * @param {Array} currentPackages an array of packages to configure
87 | * @param {String} [dir] a prefix dir to use.
88 | */
89 | function configurePackageDir(packages, currentPackages, dir) {
90 | var i, location, pkgObj;
91 | for (i = 0; (pkgObj = currentPackages[i]); i++) {
92 | pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
93 | location = pkgObj.location;
94 |
95 | //Add dir to the path, but avoid paths that start with a slash
96 | //or have a colon (indicates a protocol)
97 | if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
98 | pkgObj.location = dir + "/" + (pkgObj.location || pkgObj.name);
99 | }
100 |
101 | //Normalize package paths.
102 | pkgObj.location = pkgObj.location || pkgObj.name;
103 | pkgObj.lib = pkgObj.lib || "lib";
104 | pkgObj.main = pkgObj.main || "main";
105 |
106 | packages[pkgObj.name] = pkgObj;
107 | }
108 | }
109 |
110 | /**
111 | * Determine if priority loading is done. If so clear the priorityWait
112 | */
113 | function isPriorityDone(context) {
114 | var priorityDone = true,
115 | priorityWait = context.config.priorityWait,
116 | priorityName, i;
117 | if (priorityWait) {
118 | for (i = 0; (priorityName = priorityWait[i]); i++) {
119 | if (!context.loaded[priorityName]) {
120 | priorityDone = false;
121 | break;
122 | }
123 | }
124 | if (priorityDone) {
125 | delete context.config.priorityWait;
126 | }
127 | }
128 | return priorityDone;
129 | }
130 |
131 | /**
132 | * Resumes tracing of dependencies and then checks if everything is loaded.
133 | */
134 | function resume(context) {
135 | var args, i, paused = s.paused;
136 | if (context.scriptCount <= 0) {
137 | //Synchronous envs will push the number below zero with the
138 | //decrement above, be sure to set it back to zero for good measure.
139 | //require() calls that also do not end up loading scripts could
140 | //push the number negative too.
141 | context.scriptCount = 0;
142 |
143 | //Make sure any remaining defQueue items get properly processed.
144 | while (defQueue.length) {
145 | args = defQueue.shift();
146 | if (args[0] === null) {
147 | req.onError(new Error('Mismatched anonymous require.def modules'));
148 | } else {
149 | callDefMain(args, context);
150 | }
151 | }
152 |
153 | //Skip the resume if current context is in priority wait.
154 | if (context.config.priorityWait && !isPriorityDone(context)) {
155 | return;
156 | }
157 |
158 | if (paused.length) {
159 | for (i = 0; (args = paused[i]); i++) {
160 | req.checkDeps.apply(req, args);
161 | }
162 | }
163 |
164 | req.checkLoaded(s.ctxName);
165 | }
166 | }
167 |
168 | /**
169 | * Main entry point.
170 | *
171 | * If the only argument to require is a string, then the module that
172 | * is represented by that string is fetched for the appropriate context.
173 | *
174 | * If the first argument is an array, then it will be treated as an array
175 | * of dependency string names to fetch. An optional function callback can
176 | * be specified to execute when all of those dependencies are available.
177 | */
178 | require = function (deps, callback, contextName, relModuleName) {
179 | var context, config;
180 | if (typeof deps === "string" && !isFunction(callback)) {
181 | //Just return the module wanted. In this scenario, the
182 | //second arg (if passed) is just the contextName.
183 | return require.get(deps, callback, contextName, relModuleName);
184 | }
185 | // Dependencies first
186 | if (!require.isArray(deps)) {
187 | // deps is a config object
188 | config = deps;
189 | if (require.isArray(callback)) {
190 | // Adjust args if there are dependencies
191 | deps = callback;
192 | callback = contextName;
193 | contextName = relModuleName;
194 | relModuleName = arguments[4];
195 | } else {
196 | deps = [];
197 | }
198 | }
199 |
200 | main(null, deps, callback, config, contextName, relModuleName);
201 |
202 | //If the require call does not trigger anything new to load,
203 | //then resume the dependency processing. Context will be undefined
204 | //on first run of require.
205 | context = s.contexts[(contextName || (config && config.context) || s.ctxName)];
206 | if (context && context.scriptCount === 0) {
207 | resume(context);
208 | }
209 | //Returning undefined for Spidermonky strict checking in Komodo
210 | return undefined;
211 | };
212 |
213 | //Alias for caja compliance internally -
214 | //specifically: "Dynamically computed names should use require.async()"
215 | //even though this spec isn't really decided on.
216 | //Since it is here, use this alias to make typing shorter.
217 | req = require;
218 |
219 | /**
220 | * Any errors that require explicitly generates will be passed to this
221 | * function. Intercept/override it if you want custom error handling.
222 | * If you do override it, this method should *always* throw an error
223 | * to stop the execution flow correctly. Otherwise, other weird errors
224 | * will occur.
225 | * @param {Error} err the error object.
226 | */
227 | req.onError = function (err) {
228 | throw err;
229 | };
230 |
231 | /**
232 | * The function that handles definitions of modules. Differs from
233 | * require() in that a string for the module should be the first argument,
234 | * and the function to execute after dependencies are loaded should
235 | * return a value to define the module corresponding to the first argument's
236 | * name.
237 | */
238 | define = req.def = function (name, deps, callback, contextName) {
239 | var i, scripts, script, node = currentlyAddingScript;
240 |
241 | //Allow for anonymous functions
242 | if (typeof name !== 'string') {
243 | //Adjust args appropriately
244 | contextName = callback;
245 | callback = deps;
246 | deps = name;
247 | name = null;
248 | }
249 |
250 | //This module may not have dependencies
251 | if (!req.isArray(deps)) {
252 | contextName = callback;
253 | callback = deps;
254 | deps = [];
255 | }
256 |
257 | //If no name, and callback is a function, then figure out if it a
258 | //CommonJS thing with dependencies.
259 | if (!name && !deps.length && req.isFunction(callback)) {
260 | //Remove comments from the callback string,
261 | //look for require calls, and pull them into the dependencies.
262 | callback
263 | .toString()
264 | .replace(commentRegExp, "")
265 | .replace(cjsRequireRegExp, function (match, dep) {
266 | deps.push(dep);
267 | });
268 |
269 | //May be a CommonJS thing even without require calls, but still
270 | //could use exports, and such, so always add those as dependencies.
271 | //This is a bit wasteful for RequireJS modules that do not need
272 | //an exports or module object, but erring on side of safety.
273 | //REQUIRES the function to expect the CommonJS variables in the
274 | //order listed below.
275 | deps = ["require", "exports", "module"].concat(deps);
276 | }
277 |
278 | //If in IE 6-8 and hit an anonymous require.def call, do the interactive/
279 | //currentlyAddingScript scripts stuff.
280 | if (!name && useInteractive) {
281 | scripts = document.getElementsByTagName('script');
282 | for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
283 | if (script.readyState === 'interactive') {
284 | node = script;
285 | break;
286 | }
287 | }
288 | if (!node) {
289 | req.onError(new Error("ERROR: No matching script interactive for " + callback));
290 | }
291 |
292 | name = node.getAttribute("data-requiremodule");
293 | }
294 |
295 | if (typeof name === 'string') {
296 | //Do not try to auto-register a jquery later.
297 | //Do this work here and in main, since for IE/useInteractive, this function
298 | //is the earliest touch-point.
299 | s.contexts[s.ctxName].jQueryDef = (name === "jquery");
300 | }
301 |
302 | //Always save off evaluating the def call until the script onload handler.
303 | //This allows multiple modules to be in a file without prematurely
304 | //tracing dependencies, and allows for anonymous module support,
305 | //where the module name is not known until the script onload event
306 | //occurs.
307 | defQueue.push([name, deps, callback, null, contextName]);
308 | };
309 |
310 | main = function (name, deps, callback, config, contextName, relModuleName) {
311 | //Grab the context, or create a new one for the given context name.
312 | var context, newContext, loaded, pluginPrefix,
313 | canSetContext, prop, newLength, outDeps, mods, paths, index, i,
314 | deferMods, deferModArgs, lastModArg, waitingName, packages,
315 | packagePaths;
316 |
317 | contextName = contextName ? contextName : (config && config.context ? config.context : s.ctxName);
318 | context = s.contexts[contextName];
319 |
320 | if (name) {
321 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
322 | // Pull off any plugin prefix.
323 | index = name.indexOf("!");
324 | if (index !== -1) {
325 | pluginPrefix = name.substring(0, index);
326 | name = name.substring(index + 1, name.length);
327 | } else {
328 | //Could be that the plugin name should be auto-applied.
329 | //Used by i18n plugin to enable anonymous i18n modules, but
330 | //still associating the auto-generated name with the i18n plugin.
331 | pluginPrefix = context.defPlugin[name];
332 | }
333 |
334 | //>>excludeEnd("requireExcludePlugin");
335 |
336 | //If module already defined for context, or already waiting to be
337 | //evaluated, leave.
338 | waitingName = context.waiting[name];
339 | if (context && (context.defined[name] || (waitingName && waitingName !== ap[name]))) {
340 | return;
341 | }
342 | }
343 |
344 | if (contextName !== s.ctxName) {
345 | //If nothing is waiting on being loaded in the current context,
346 | //then switch s.ctxName to current contextName.
347 | loaded = (s.contexts[s.ctxName] && s.contexts[s.ctxName].loaded);
348 | canSetContext = true;
349 | if (loaded) {
350 | for (prop in loaded) {
351 | if (!(prop in empty)) {
352 | if (!loaded[prop]) {
353 | canSetContext = false;
354 | break;
355 | }
356 | }
357 | }
358 | }
359 | if (canSetContext) {
360 | s.ctxName = contextName;
361 | }
362 | }
363 |
364 | if (!context) {
365 | newContext = {
366 | contextName: contextName,
367 | config: {
368 | waitSeconds: 7,
369 | baseUrl: s.baseUrl || "./",
370 | paths: {},
371 | packages: {}
372 | },
373 | waiting: [],
374 | specified: {
375 | "require": true,
376 | "exports": true,
377 | "module": true
378 | },
379 | loaded: {},
380 | scriptCount: 0,
381 | urlFetched: {},
382 | defPlugin: {},
383 | defined: {},
384 | modifiers: {}
385 | };
386 |
387 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
388 | if (s.plugins.newContext) {
389 | s.plugins.newContext(newContext);
390 | }
391 | //>>excludeEnd("requireExcludePlugin");
392 |
393 | context = s.contexts[contextName] = newContext;
394 | }
395 |
396 | //If have a config object, update the context's config object with
397 | //the config values.
398 | if (config) {
399 | //Make sure the baseUrl ends in a slash.
400 | if (config.baseUrl) {
401 | if (config.baseUrl.charAt(config.baseUrl.length - 1) !== "/") {
402 | config.baseUrl += "/";
403 | }
404 | }
405 |
406 | //Save off the paths and packages since they require special processing,
407 | //they are additive.
408 | paths = context.config.paths;
409 | packages = context.config.packages;
410 |
411 | //Mix in the config values, favoring the new values over
412 | //existing ones in context.config.
413 | req.mixin(context.config, config, true);
414 |
415 | //Adjust paths if necessary.
416 | if (config.paths) {
417 | for (prop in config.paths) {
418 | if (!(prop in empty)) {
419 | paths[prop] = config.paths[prop];
420 | }
421 | }
422 | context.config.paths = paths;
423 | }
424 |
425 | packagePaths = config.packagePaths;
426 | if (packagePaths || config.packages) {
427 | //Convert packagePaths into a packages config.
428 | if (packagePaths) {
429 | for (prop in packagePaths) {
430 | if (!(prop in empty)) {
431 | configurePackageDir(packages, packagePaths[prop], prop);
432 | }
433 | }
434 | }
435 |
436 | //Adjust packages if necessary.
437 | if (config.packages) {
438 | configurePackageDir(packages, config.packages);
439 | }
440 |
441 | //Done with modifications, assing packages back to context config
442 | context.config.packages = packages;
443 | }
444 |
445 | //If priority loading is in effect, trigger the loads now
446 | if (config.priority) {
447 | //Create a separate config property that can be
448 | //easily tested for config priority completion.
449 | //Do this instead of wiping out the config.priority
450 | //in case it needs to be inspected for debug purposes later.
451 | req(config.priority);
452 | context.config.priorityWait = config.priority;
453 | }
454 |
455 | //If a deps array or a config callback is specified, then call
456 | //require with those args. This is useful when require is defined as a
457 | //config object before require.js is loaded.
458 | if (config.deps || config.callback) {
459 | req(config.deps || [], config.callback);
460 | }
461 |
462 | //>>excludeStart("requireExcludePageLoad", pragmas.requireExcludePageLoad);
463 | //Set up ready callback, if asked. Useful when require is defined as a
464 | //config object before require.js is loaded.
465 | if (config.ready) {
466 | req.ready(config.ready);
467 | }
468 | //>>excludeEnd("requireExcludePageLoad");
469 |
470 | //If it is just a config block, nothing else,
471 | //then return.
472 | if (!deps) {
473 | return;
474 | }
475 | }
476 |
477 | //Normalize dependency strings: need to determine if they have
478 | //prefixes and to also normalize any relative paths. Replace the deps
479 | //array of strings with an array of objects.
480 | if (deps) {
481 | outDeps = deps;
482 | deps = [];
483 | for (i = 0; i < outDeps.length; i++) {
484 | deps[i] = req.splitPrefix(outDeps[i], (name || relModuleName), context);
485 | }
486 | }
487 |
488 | //Store the module for later evaluation
489 | newLength = context.waiting.push({
490 | name: name,
491 | deps: deps,
492 | callback: callback
493 | });
494 |
495 | if (name) {
496 | //Store index of insertion for quick lookup
497 | context.waiting[name] = newLength - 1;
498 |
499 | //Mark the module as specified so no need to fetch it again.
500 | //Important to set specified here for the
501 | //pause/resume case where there are multiple modules in a file.
502 | context.specified[name] = true;
503 |
504 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
505 | //Load any modifiers for the module.
506 | mods = context.modifiers[name];
507 | if (mods) {
508 | req(mods, contextName);
509 | deferMods = mods.__deferMods;
510 | if (deferMods) {
511 | for (i = 0; i < deferMods.length; i++) {
512 | deferModArgs = deferMods[i];
513 |
514 | //Add the context name to the def call.
515 | lastModArg = deferModArgs[deferModArgs.length - 1];
516 | if (lastModArg === undefined) {
517 | deferModArgs[deferModArgs.length - 1] = contextName;
518 | } else if (typeof lastModArg === "string") {
519 | deferMods.push(contextName);
520 | }
521 |
522 | require.def.apply(require, deferModArgs);
523 | }
524 | }
525 | }
526 | //>>excludeEnd("requireExcludeModify");
527 | }
528 |
529 | //If the callback is not an actual function, it means it already
530 | //has the definition of the module as a literal value.
531 | if (name && callback && !req.isFunction(callback)) {
532 | context.defined[name] = callback;
533 | }
534 |
535 | //If a pluginPrefix is available, call the plugin, or load it.
536 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
537 | if (pluginPrefix) {
538 | callPlugin(pluginPrefix, context, {
539 | name: "require",
540 | args: [name, deps, callback, context]
541 | });
542 | }
543 | //>>excludeEnd("requireExcludePlugin");
544 |
545 | //Hold on to the module until a script load or other adapter has finished
546 | //evaluating the whole file. This helps when a file has more than one
547 | //module in it -- dependencies are not traced and fetched until the whole
548 | //file is processed.
549 | s.paused.push([pluginPrefix, name, deps, context]);
550 |
551 | //Set loaded here for modules that are also loaded
552 | //as part of a layer, where onScriptLoad is not fired
553 | //for those cases. Do this after the inline define and
554 | //dependency tracing is done.
555 | //Also check if auto-registry of jQuery needs to be skipped.
556 | if (name) {
557 | context.loaded[name] = true;
558 | context.jQueryDef = (name === "jquery");
559 | }
560 | };
561 |
562 | /**
563 | * Simple function to mix in properties from source into target,
564 | * but only if target does not already have a property of the same name.
565 | */
566 | req.mixin = function (target, source, force) {
567 | for (var prop in source) {
568 | if (!(prop in empty) && (!(prop in target) || force)) {
569 | target[prop] = source[prop];
570 | }
571 | }
572 | return req;
573 | };
574 |
575 | req.version = version;
576 |
577 | //Set up page state.
578 | s = req.s = {
579 | ctxName: defContextName,
580 | contexts: {},
581 | paused: [],
582 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
583 | plugins: {
584 | defined: {},
585 | callbacks: {},
586 | waiting: {}
587 | },
588 | //>>excludeEnd("requireExcludePlugin");
589 | //Stores a list of URLs that should not get async script tag treatment.
590 | skipAsync: {},
591 | isBrowser: isBrowser,
592 | isPageLoaded: !isBrowser,
593 | readyCalls: [],
594 | doc: isBrowser ? document : null
595 | };
596 |
597 | req.isBrowser = s.isBrowser;
598 | if (isBrowser) {
599 | s.head = document.getElementsByTagName("head")[0];
600 | //If BASE tag is in play, using appendChild is a problem for IE6.
601 | //When that browser dies, this can be removed. Details in this jQuery bug:
602 | //http://dev.jquery.com/ticket/2709
603 | baseElement = document.getElementsByTagName("base")[0];
604 | if (baseElement) {
605 | s.head = baseElement.parentNode;
606 | }
607 | }
608 |
609 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
610 | /**
611 | * Sets up a plugin callback name. Want to make it easy to test if a plugin
612 | * needs to be called for a certain lifecycle event by testing for
613 | * if (s.plugins.onLifeCyleEvent) so only define the lifecycle event
614 | * if there is a real plugin that registers for it.
615 | */
616 | function makePluginCallback(name, returnOnTrue) {
617 | var cbs = s.plugins.callbacks[name] = [];
618 | s.plugins[name] = function () {
619 | for (var i = 0, cb; (cb = cbs[i]); i++) {
620 | if (cb.apply(null, arguments) === true && returnOnTrue) {
621 | return true;
622 | }
623 | }
624 | return false;
625 | };
626 | }
627 |
628 | /**
629 | * Registers a new plugin for require.
630 | */
631 | req.plugin = function (obj) {
632 | var i, prop, call, prefix = obj.prefix, cbs = s.plugins.callbacks,
633 | waiting = s.plugins.waiting[prefix], generics,
634 | defined = s.plugins.defined, contexts = s.contexts, context;
635 |
636 | //Do not allow redefinition of a plugin, there may be internal
637 | //state in the plugin that could be lost.
638 | if (defined[prefix]) {
639 | return req;
640 | }
641 |
642 | //Save the plugin.
643 | defined[prefix] = obj;
644 |
645 | //Set up plugin callbacks for methods that need to be generic to
646 | //require, for lifecycle cases where it does not care about a particular
647 | //plugin, but just that some plugin work needs to be done.
648 | generics = ["newContext", "isWaiting", "orderDeps"];
649 | for (i = 0; (prop = generics[i]); i++) {
650 | if (!s.plugins[prop]) {
651 | makePluginCallback(prop, prop === "isWaiting");
652 | }
653 | cbs[prop].push(obj[prop]);
654 | }
655 |
656 | //Call newContext for any contexts that were already created.
657 | if (obj.newContext) {
658 | for (prop in contexts) {
659 | if (!(prop in empty)) {
660 | context = contexts[prop];
661 | obj.newContext(context);
662 | }
663 | }
664 | }
665 |
666 | //If there are waiting requests for a plugin, execute them now.
667 | if (waiting) {
668 | for (i = 0; (call = waiting[i]); i++) {
669 | if (obj[call.name]) {
670 | obj[call.name].apply(null, call.args);
671 | }
672 | }
673 | delete s.plugins.waiting[prefix];
674 | }
675 |
676 | return req;
677 | };
678 | //>>excludeEnd("requireExcludePlugin");
679 |
680 | /**
681 | * As of jQuery 1.4.3, it supports a readyWait property that will hold off
682 | * calling jQuery ready callbacks until all scripts are loaded. Be sure
683 | * to track it if readyWait is available. Also, since jQuery 1.4.3 does
684 | * not register as a module, need to do some global inference checking.
685 | * Even if it does register as a module, not guaranteed to be the precise
686 | * name of the global. If a jQuery is tracked for this context, then go
687 | * ahead and register it as a module too, if not already in process.
688 | */
689 | function jQueryCheck(context, jqCandidate) {
690 | if (!context.jQuery) {
691 | var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
692 | if ($ && "readyWait" in $) {
693 | context.jQuery = $;
694 |
695 | //Manually create a "jquery" module entry if not one already
696 | //or in process.
697 | if (!context.defined.jquery && !context.jQueryDef) {
698 | context.defined.jquery = $;
699 | }
700 |
701 | //Make sure
702 | if (context.scriptCount) {
703 | $.readyWait += 1;
704 | context.jQueryIncremented = true;
705 | }
706 | }
707 | }
708 | }
709 |
710 | /**
711 | * Internal method used by environment adapters to complete a load event.
712 | * A load event could be a script load or just a load pass from a synchronous
713 | * load call.
714 | * @param {String} moduleName the name of the module to potentially complete.
715 | * @param {Object} context the context object
716 | */
717 | req.completeLoad = function (moduleName, context) {
718 | //If there is a waiting require.def call
719 | var args;
720 | while (defQueue.length) {
721 | args = defQueue.shift();
722 | if (args[0] === null) {
723 | args[0] = moduleName;
724 | break;
725 | } else if (args[0] === moduleName) {
726 | //Found matching require.def call for this script!
727 | break;
728 | } else {
729 | //Some other named require.def call, most likely the result
730 | //of a build layer that included many require.def calls.
731 | callDefMain(args, context);
732 | }
733 | }
734 | if (args) {
735 | callDefMain(args, context);
736 | }
737 |
738 | //Mark the script as loaded. Note that this can be different from a
739 | //moduleName that maps to a require.def call. This line is important
740 | //for traditional browser scripts.
741 | context.loaded[moduleName] = true;
742 |
743 | //If a global jQuery is defined, check for it. Need to do it here
744 | //instead of main() since stock jQuery does not register as
745 | //a module via define.
746 | jQueryCheck(context);
747 |
748 | context.scriptCount -= 1;
749 | resume(context);
750 | };
751 |
752 | /**
753 | * Legacy function, remove at some point
754 | */
755 | req.pause = req.resume = function () {};
756 |
757 | /**
758 | * Trace down the dependencies to see if they are loaded. If not, trigger
759 | * the load.
760 | * @param {String} pluginPrefix the plugin prefix, if any associated with the name.
761 | *
762 | * @param {String} name: the name of the module that has the dependencies.
763 | *
764 | * @param {Array} deps array of dependencies.
765 | *
766 | * @param {Object} context: the loading context.
767 | *
768 | * @private
769 | */
770 | req.checkDeps = function (pluginPrefix, name, deps, context) {
771 | //Figure out if all the modules are loaded. If the module is not
772 | //being loaded or already loaded, add it to the "to load" list,
773 | //and request it to be loaded.
774 | var i, dep;
775 |
776 | if (pluginPrefix) {
777 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
778 | callPlugin(pluginPrefix, context, {
779 | name: "checkDeps",
780 | args: [name, deps, context]
781 | });
782 | //>>excludeEnd("requireExcludePlugin");
783 | } else {
784 | for (i = 0; (dep = deps[i]); i++) {
785 | if (!context.specified[dep.fullName]) {
786 | context.specified[dep.fullName] = true;
787 |
788 | //Reset the start time to use for timeouts
789 | context.startTime = (new Date()).getTime();
790 |
791 | //If a plugin, call its load method.
792 | if (dep.prefix) {
793 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
794 | callPlugin(dep.prefix, context, {
795 | name: "load",
796 | args: [dep.name, context.contextName]
797 | });
798 | //>>excludeEnd("requireExcludePlugin");
799 | } else {
800 | req.load(dep.name, context.contextName);
801 | }
802 | }
803 | }
804 | }
805 | };
806 |
807 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
808 | /**
809 | * Register a module that modifies another module. The modifier will
810 | * only be called once the target module has been loaded.
811 | *
812 | * First syntax:
813 | *
814 | * require.modify({
815 | * "some/target1": "my/modifier1",
816 | * "some/target2": "my/modifier2",
817 | * });
818 | *
819 | * With this syntax, the my/modifier1 will only be loaded when
820 | * "some/target1" is loaded.
821 | *
822 | * Second syntax, defining a modifier.
823 | *
824 | * require.modify("some/target1", "my/modifier",
825 | * ["some/target1", "some/other"],
826 | * function (target, other) {
827 | * //Modify properties of target here.
828 | * Only properties of target can be modified, but
829 | * target cannot be replaced.
830 | * }
831 | * );
832 | */
833 | req.modify = function (target, name, deps, callback, contextName) {
834 | var prop, modifier, list,
835 | cName = (typeof target === "string" ? contextName : name) || s.ctxName,
836 | context = s.contexts[cName],
837 | mods = context.modifiers;
838 |
839 | if (typeof target === "string") {
840 | //A modifier module.
841 | //First store that it is a modifier.
842 | list = mods[target] || (mods[target] = []);
843 | if (!list[name]) {
844 | list.push(name);
845 | list[name] = true;
846 | }
847 |
848 | //Trigger the normal module definition logic if the target
849 | //is already in the system.
850 | if (context.specified[target]) {
851 | req.def(name, deps, callback, contextName);
852 | } else {
853 | //Hold on to the execution/dependency checks for the modifier
854 | //until the target is fetched.
855 | (list.__deferMods || (list.__deferMods = [])).push([name, deps, callback, contextName]);
856 | }
857 | } else {
858 | //A list of modifiers. Save them for future reference.
859 | for (prop in target) {
860 | if (!(prop in empty)) {
861 | //Store the modifier for future use.
862 | modifier = target[prop];
863 | list = mods[prop] || (context.modifiers[prop] = []);
864 | if (!list[modifier]) {
865 | list.push(modifier);
866 | list[modifier] = true;
867 |
868 | if (context.specified[prop]) {
869 | //Load the modifier right away.
870 | req([modifier], cName);
871 | }
872 | }
873 | }
874 | }
875 | }
876 | };
877 | //>>excludeEnd("requireExcludeModify");
878 |
879 | req.isArray = function (it) {
880 | return ostring.call(it) === "[object Array]";
881 | };
882 |
883 | req.isFunction = isFunction;
884 |
885 | /**
886 | * Gets one module's exported value. This method is used by require().
887 | * It is broken out as a separate function to allow a host environment
888 | * shim to overwrite this function with something appropriate for that
889 | * environment.
890 | *
891 | * @param {String} moduleName the name of the module.
892 | * @param {String} [contextName] the name of the context to use. Uses
893 | * default context if no contextName is provided. You should never
894 | * pass the contextName explicitly -- it is handled by the require() code.
895 | * @param {String} [relModuleName] a module name to use for relative
896 | * module name lookups. You should never pass this argument explicitly --
897 | * it is handled by the require() code.
898 | *
899 | * @returns {Object} the exported module value.
900 | */
901 | req.get = function (moduleName, contextName, relModuleName) {
902 | if (moduleName === "require" || moduleName === "exports" || moduleName === "module") {
903 | req.onError(new Error("Explicit require of " + moduleName + " is not allowed."));
904 | }
905 | contextName = contextName || s.ctxName;
906 |
907 | var ret, context = s.contexts[contextName];
908 |
909 | //Normalize module name, if it contains . or ..
910 | moduleName = req.normalizeName(moduleName, relModuleName, context);
911 |
912 | ret = context.defined[moduleName];
913 | if (ret === undefined) {
914 | req.onError(new Error("require: module name '" +
915 | moduleName +
916 | "' has not been loaded yet for context: " +
917 | contextName));
918 | }
919 | return ret;
920 | };
921 |
922 | /**
923 | * Makes the request to load a module. May be an async load depending on
924 | * the environment and the circumstance of the load call. Override this
925 | * method in a host environment shim to do something specific for that
926 | * environment.
927 | *
928 | * @param {String} moduleName the name of the module.
929 | * @param {String} contextName the name of the context to use.
930 | */
931 | req.load = function (moduleName, contextName) {
932 | var context = s.contexts[contextName],
933 | urlFetched = context.urlFetched,
934 | loaded = context.loaded, url;
935 | s.isDone = false;
936 |
937 | //Only set loaded to false for tracking if it has not already been set.
938 | if (!loaded[moduleName]) {
939 | loaded[moduleName] = false;
940 | }
941 |
942 | if (contextName !== s.ctxName) {
943 | //Not in the right context now, hold on to it until
944 | //the current context finishes all its loading.
945 | contextLoads.push(arguments);
946 | } else {
947 | //First derive the path name for the module.
948 | url = req.nameToUrl(moduleName, null, contextName);
949 | if (!urlFetched[url]) {
950 | context.scriptCount += 1;
951 | req.attach(url, contextName, moduleName);
952 | urlFetched[url] = true;
953 |
954 | //If tracking a jQuery, then make sure its readyWait
955 | //is incremented to prevent its ready callbacks from
956 | //triggering too soon.
957 | if (context.jQuery && !context.jQueryIncremented) {
958 | context.jQuery.readyWait += 1;
959 | context.jQueryIncremented = true;
960 | }
961 | }
962 | }
963 | };
964 |
965 | req.jsExtRegExp = /\.js$/;
966 |
967 | /**
968 | * Given a relative module name, like ./something, normalize it to
969 | * a real name that can be mapped to a path.
970 | * @param {String} name the relative name
971 | * @param {String} baseName a real name that the name arg is relative
972 | * to.
973 | * @param {Object} context
974 | * @returns {String} normalized name
975 | */
976 | req.normalizeName = function (name, baseName, context) {
977 | //Adjust any relative paths.
978 | var part;
979 | if (name.charAt(0) === ".") {
980 | //If have a base name, try to normalize against it,
981 | //otherwise, assume it is a top-level require that will
982 | //be relative to baseUrl in the end.
983 | if (baseName) {
984 | if (context.config.packages[baseName]) {
985 | //If the baseName is a package name, then just treat it as one
986 | //name to concat the name with.
987 | baseName = [baseName];
988 | } else {
989 | //Convert baseName to array, and lop off the last part,
990 | //so that . matches that "directory" and not name of the baseName's
991 | //module. For instance, baseName of "one/two/three", maps to
992 | //"one/two/three.js", but we want the directory, "one/two" for
993 | //this normalization.
994 | baseName = baseName.split("/");
995 | baseName = baseName.slice(0, baseName.length - 1);
996 | }
997 |
998 | name = baseName.concat(name.split("/"));
999 | for (i = 0; (part = name[i]); i++) {
1000 | if (part === ".") {
1001 | name.splice(i, 1);
1002 | i -= 1;
1003 | } else if (part === "..") {
1004 | name.splice(i - 1, 2);
1005 | i -= 2;
1006 | }
1007 | }
1008 | name = name.join("/");
1009 | }
1010 | }
1011 | return name;
1012 | };
1013 |
1014 | /**
1015 | * Splits a name into a possible plugin prefix and
1016 | * the module name. If baseName is provided it will
1017 | * also normalize the name via require.normalizeName()
1018 | *
1019 | * @param {String} name the module name
1020 | * @param {String} [baseName] base name that name is
1021 | * relative to.
1022 | * @param {Object} context
1023 | *
1024 | * @returns {Object} with properties, 'prefix' (which
1025 | * may be null), 'name' and 'fullName', which is a combination
1026 | * of the prefix (if it exists) and the name.
1027 | */
1028 | req.splitPrefix = function (name, baseName, context) {
1029 | var index = name.indexOf("!"), prefix = null;
1030 | if (index !== -1) {
1031 | prefix = name.substring(0, index);
1032 | name = name.substring(index + 1, name.length);
1033 | }
1034 |
1035 | //Account for relative paths if there is a base name.
1036 | name = req.normalizeName(name, baseName, context);
1037 |
1038 | return {
1039 | prefix: prefix,
1040 | name: name,
1041 | fullName: prefix ? prefix + "!" + name : name
1042 | };
1043 | };
1044 |
1045 | /**
1046 | * Converts a module name to a file path.
1047 | */
1048 | req.nameToUrl = function (moduleName, ext, contextName, relModuleName) {
1049 | var paths, packages, pkg, pkgPath, syms, i, parentModule, url,
1050 | context = s.contexts[contextName],
1051 | config = context.config;
1052 |
1053 | //Normalize module name if have a base relative module name to work from.
1054 | moduleName = req.normalizeName(moduleName, relModuleName, context);
1055 |
1056 | //If a colon is in the URL, it indicates a protocol is used and it is just
1057 | //an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file.
1058 | //The slash is important for protocol-less URLs as well as full paths.
1059 | if (moduleName.indexOf(":") !== -1 || moduleName.charAt(0) === '/' || req.jsExtRegExp.test(moduleName)) {
1060 | //Just a plain path, not module name lookup, so just return it.
1061 | //Add extension if it is included. This is a bit wonky, only non-.js things pass
1062 | //an extension, this method probably needs to be reworked.
1063 | url = moduleName + (ext ? ext : "");
1064 | } else {
1065 | //A module that needs to be converted to a path.
1066 | paths = config.paths;
1067 | packages = config.packages;
1068 |
1069 | syms = moduleName.split("/");
1070 | //For each module name segment, see if there is a path
1071 | //registered for it. Start with most specific name
1072 | //and work up from it.
1073 | for (i = syms.length; i > 0; i--) {
1074 | parentModule = syms.slice(0, i).join("/");
1075 | if (paths[parentModule]) {
1076 | syms.splice(0, i, paths[parentModule]);
1077 | break;
1078 | } else if ((pkg = packages[parentModule])) {
1079 | //pkg can have just a string value to the path
1080 | //or can be an object with props:
1081 | //main, lib, name, location.
1082 | pkgPath = pkg.location + '/' + pkg.lib;
1083 | //If module name is just the package name, then looking
1084 | //for the main module.
1085 | if (moduleName === pkg.name) {
1086 | pkgPath += '/' + pkg.main;
1087 | }
1088 | syms.splice(0, i, pkgPath);
1089 | break;
1090 | }
1091 | }
1092 |
1093 | //Join the path parts together, then figure out if baseUrl is needed.
1094 | url = syms.join("/") + (ext || ".js");
1095 | url = (url.charAt(0) === '/' || url.match(/^\w+:/) ? "" : config.baseUrl) + url;
1096 | }
1097 | return config.urlArgs ? url +
1098 | ((url.indexOf('?') === -1 ? '?' : '&') +
1099 | config.urlArgs) : url;
1100 | };
1101 |
1102 | /**
1103 | * Checks if all modules for a context are loaded, and if so, evaluates the
1104 | * new ones in right dependency order.
1105 | *
1106 | * @private
1107 | */
1108 | req.checkLoaded = function (contextName) {
1109 | var context = s.contexts[contextName || s.ctxName],
1110 | waitInterval = context.config.waitSeconds * 1000,
1111 | //It is possible to disable the wait interval by using waitSeconds of 0.
1112 | expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
1113 | loaded, defined = context.defined,
1114 | modifiers = context.modifiers, waiting, noLoads = "",
1115 | hasLoadedProp = false, stillLoading = false, prop,
1116 |
1117 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
1118 | pIsWaiting = s.plugins.isWaiting, pOrderDeps = s.plugins.orderDeps,
1119 | //>>excludeEnd("requireExcludePlugin");
1120 |
1121 | i, module, allDone, loads, loadArgs, err;
1122 |
1123 | //If already doing a checkLoaded call,
1124 | //then do not bother checking loaded state.
1125 | if (context.isCheckLoaded) {
1126 | return;
1127 | }
1128 |
1129 | //Determine if priority loading is done. If so clear the priority. If
1130 | //not, then do not check
1131 | if (context.config.priorityWait) {
1132 | if (isPriorityDone(context)) {
1133 | //Call resume, since it could have
1134 | //some waiting dependencies to trace.
1135 | resume(context);
1136 | } else {
1137 | return;
1138 | }
1139 | }
1140 |
1141 | //Signal that checkLoaded is being require, so other calls that could be triggered
1142 | //by calling a waiting callback that then calls require and then this function
1143 | //should not proceed. At the end of this function, if there are still things
1144 | //waiting, then checkLoaded will be called again.
1145 | context.isCheckLoaded = true;
1146 |
1147 | //Grab waiting and loaded lists here, since it could have changed since
1148 | //this function was first called.
1149 | waiting = context.waiting;
1150 | loaded = context.loaded;
1151 |
1152 | //See if anything is still in flight.
1153 | for (prop in loaded) {
1154 | if (!(prop in empty)) {
1155 | hasLoadedProp = true;
1156 | if (!loaded[prop]) {
1157 | if (expired) {
1158 | noLoads += prop + " ";
1159 | } else {
1160 | stillLoading = true;
1161 | break;
1162 | }
1163 | }
1164 | }
1165 | }
1166 |
1167 | //Check for exit conditions.
1168 | if (!hasLoadedProp && !waiting.length
1169 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
1170 | && (!pIsWaiting || !pIsWaiting(context))
1171 | //>>excludeEnd("requireExcludePlugin");
1172 | ) {
1173 | //If the loaded object had no items, then the rest of
1174 | //the work below does not need to be done.
1175 | context.isCheckLoaded = false;
1176 | return;
1177 | }
1178 | if (expired && noLoads) {
1179 | //If wait time expired, throw error of unloaded modules.
1180 | err = new Error("require.js load timeout for modules: " + noLoads);
1181 | err.requireType = "timeout";
1182 | err.requireModules = noLoads;
1183 | req.onError(err);
1184 | }
1185 | if (stillLoading) {
1186 | //Something is still waiting to load. Wait for it.
1187 | context.isCheckLoaded = false;
1188 | if (isBrowser || isWebWorker) {
1189 | setTimeout(function () {
1190 | req.checkLoaded(contextName);
1191 | }, 50);
1192 | }
1193 | return;
1194 | }
1195 |
1196 | //Order the dependencies. Also clean up state because the evaluation
1197 | //of modules might create new loading tasks, so need to reset.
1198 | //Be sure to call plugins too.
1199 | context.waiting = [];
1200 | context.loaded = {};
1201 |
1202 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
1203 | //Call plugins to order their dependencies, do their
1204 | //module definitions.
1205 | if (pOrderDeps) {
1206 | pOrderDeps(context);
1207 | }
1208 | //>>excludeEnd("requireExcludePlugin");
1209 |
1210 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
1211 | //Before defining the modules, give priority treatment to any modifiers
1212 | //for modules that are already defined.
1213 | for (prop in modifiers) {
1214 | if (!(prop in empty)) {
1215 | if (defined[prop]) {
1216 | req.execModifiers(prop, {}, waiting, context);
1217 | }
1218 | }
1219 | }
1220 | //>>excludeEnd("requireExcludeModify");
1221 |
1222 | //Define the modules, doing a depth first search.
1223 | for (i = 0; (module = waiting[i]); i++) {
1224 | req.exec(module, {}, waiting, context);
1225 | }
1226 |
1227 | //Indicate checkLoaded is now done.
1228 | context.isCheckLoaded = false;
1229 |
1230 | if (context.waiting.length
1231 | //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
1232 | || (pIsWaiting && pIsWaiting(context))
1233 | //>>excludeEnd("requireExcludePlugin");
1234 | ) {
1235 | //More things in this context are waiting to load. They were probably
1236 | //added while doing the work above in checkLoaded, calling module
1237 | //callbacks that triggered other require calls.
1238 | req.checkLoaded(contextName);
1239 | } else if (contextLoads.length) {
1240 | //Check for other contexts that need to load things.
1241 | //First, make sure current context has no more things to
1242 | //load. After defining the modules above, new require calls
1243 | //could have been made.
1244 | loaded = context.loaded;
1245 | allDone = true;
1246 | for (prop in loaded) {
1247 | if (!(prop in empty)) {
1248 | if (!loaded[prop]) {
1249 | allDone = false;
1250 | break;
1251 | }
1252 | }
1253 | }
1254 |
1255 | if (allDone) {
1256 | s.ctxName = contextLoads[0][1];
1257 | loads = contextLoads;
1258 | //Reset contextLoads in case some of the waiting loads
1259 | //are for yet another context.
1260 | contextLoads = [];
1261 | for (i = 0; (loadArgs = loads[i]); i++) {
1262 | req.load.apply(req, loadArgs);
1263 | }
1264 | }
1265 | } else {
1266 | //Make sure we reset to default context.
1267 | s.ctxName = defContextName;
1268 | s.isDone = true;
1269 | if (req.callReady) {
1270 | req.callReady();
1271 | }
1272 | }
1273 | };
1274 |
1275 | /**
1276 | * Helper function that creates a setExports function for a "module"
1277 | * CommonJS dependency. Do this here to avoid creating a closure that
1278 | * is part of a loop in require.exec.
1279 | */
1280 | function makeSetExports(moduleObj) {
1281 | return function (exports) {
1282 | moduleObj.exports = exports;
1283 | };
1284 | }
1285 |
1286 | function makeContextModuleFunc(name, contextName, moduleName) {
1287 | return function () {
1288 | //A version of a require function that forces a contextName value
1289 | //and also passes a moduleName value for items that may need to
1290 | //look up paths relative to the moduleName
1291 | var args = [].concat(aps.call(arguments, 0));
1292 | args.push(contextName, moduleName);
1293 | return (name ? require[name] : require).apply(null, args);
1294 | };
1295 | }
1296 |
1297 | /**
1298 | * Helper function that creates a require function object to give to
1299 | * modules that ask for it as a dependency. It needs to be specific
1300 | * per module because of the implication of path mappings that may
1301 | * need to be relative to the module name.
1302 | */
1303 | function makeRequire(context, moduleName) {
1304 | var contextName = context.contextName,
1305 | modRequire = makeContextModuleFunc(null, contextName, moduleName);
1306 |
1307 | req.mixin(modRequire, {
1308 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
1309 | modify: makeContextModuleFunc("modify", contextName, moduleName),
1310 | //>>excludeEnd("requireExcludeModify");
1311 | def: makeContextModuleFunc("def", contextName, moduleName),
1312 | get: makeContextModuleFunc("get", contextName, moduleName),
1313 | nameToUrl: makeContextModuleFunc("nameToUrl", contextName, moduleName),
1314 | ready: req.ready,
1315 | context: context,
1316 | config: context.config,
1317 | isBrowser: s.isBrowser
1318 | });
1319 | return modRequire;
1320 | }
1321 |
1322 | /**
1323 | * Executes the modules in the correct order.
1324 | *
1325 | * @private
1326 | */
1327 | req.exec = function (module, traced, waiting, context) {
1328 | //Some modules are just plain script files, abddo not have a formal
1329 | //module definition,
1330 | if (!module) {
1331 | //Returning undefined for Spidermonky strict checking in Komodo
1332 | return undefined;
1333 | }
1334 |
1335 | var name = module.name, cb = module.callback, deps = module.deps, j, dep,
1336 | defined = context.defined, ret, args = [], depModule, cjsModule,
1337 | usingExports = false, depName;
1338 |
1339 | //If already traced or defined, do not bother a second time.
1340 | if (name) {
1341 | if (traced[name] || name in defined) {
1342 | return defined[name];
1343 | }
1344 |
1345 | //Mark this module as being traced, so that it is not retraced (as in a circular
1346 | //dependency)
1347 | traced[name] = true;
1348 | }
1349 |
1350 | if (deps) {
1351 | for (j = 0; (dep = deps[j]); j++) {
1352 | depName = dep.name;
1353 | if (depName === "require") {
1354 | depModule = makeRequire(context, name);
1355 | } else if (depName === "exports") {
1356 | //CommonJS module spec 1.1
1357 | depModule = defined[name] = {};
1358 | usingExports = true;
1359 | } else if (depName === "module") {
1360 | //CommonJS module spec 1.1
1361 | cjsModule = depModule = {
1362 | id: name,
1363 | uri: name ? req.nameToUrl(name, null, context.contextName) : undefined
1364 | };
1365 | cjsModule.setExports = makeSetExports(cjsModule);
1366 | } else {
1367 | //Get dependent module. It could not exist, for a circular
1368 | //dependency or if the loaded dependency does not actually call
1369 | //require. Favor not throwing an error here if undefined because
1370 | //we want to allow code that does not use require as a module
1371 | //definition framework to still work -- allow a web site to
1372 | //gradually update to contained modules. That is more
1373 | //important than forcing a throw for the circular dependency case.
1374 | depModule = depName in defined ? defined[depName] : (traced[depName] ? undefined : req.exec(waiting[waiting[depName]], traced, waiting, context));
1375 | }
1376 |
1377 | args.push(depModule);
1378 | }
1379 | }
1380 |
1381 | //Call the callback to define the module, if necessary.
1382 | cb = module.callback;
1383 | if (cb && req.isFunction(cb)) {
1384 | ret = req.execCb(name, cb, args);
1385 | if (name) {
1386 | //If using exports and the function did not return a value,
1387 | //and the "module" object for this definition function did not
1388 | //define an exported value, then use the exports object.
1389 | if (usingExports && ret === undefined && (!cjsModule || !("exports" in cjsModule))) {
1390 | ret = defined[name];
1391 | } else {
1392 | if (cjsModule && "exports" in cjsModule) {
1393 | ret = defined[name] = cjsModule.exports;
1394 | } else {
1395 | if (name in defined && !usingExports) {
1396 | req.onError(new Error(name + " has already been defined"));
1397 | }
1398 | defined[name] = ret;
1399 | }
1400 | }
1401 | }
1402 | }
1403 |
1404 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
1405 | //Execute modifiers, if they exist.
1406 | req.execModifiers(name, traced, waiting, context);
1407 | //>>excludeEnd("requireExcludeModify");
1408 |
1409 | return ret;
1410 | };
1411 |
1412 | /**
1413 | * Executes a module callack function. Broken out as a separate function
1414 | * solely to allow the build system to sequence the files in the built
1415 | * layer in the right sequence.
1416 | * @param {String} name the module name.
1417 | * @param {Function} cb the module callback/definition function.
1418 | * @param {Array} args The arguments (dependent modules) to pass to callback.
1419 | *
1420 | * @private
1421 | */
1422 | req.execCb = function (name, cb, args) {
1423 | return cb.apply(null, args);
1424 | };
1425 |
1426 | //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
1427 | /**
1428 | * Executes modifiers for the given module name.
1429 | * @param {String} target
1430 | * @param {Object} traced
1431 | * @param {Object} context
1432 | *
1433 | * @private
1434 | */
1435 | req.execModifiers = function (target, traced, waiting, context) {
1436 | var modifiers = context.modifiers, mods = modifiers[target], mod, i;
1437 | if (mods) {
1438 | for (i = 0; i < mods.length; i++) {
1439 | mod = mods[i];
1440 | //Not all modifiers define a module, they might collect other modules.
1441 | //If it is just a collection it will not be in waiting.
1442 | if (mod in waiting) {
1443 | req.exec(waiting[waiting[mod]], traced, waiting, context);
1444 | }
1445 | }
1446 | delete modifiers[target];
1447 | }
1448 | };
1449 | //>>excludeEnd("requireExcludeModify");
1450 |
1451 | /**
1452 | * callback for script loads, used to check status of loading.
1453 | *
1454 | * @param {Event} evt the event from the browser for the script
1455 | * that was loaded.
1456 | *
1457 | * @private
1458 | */
1459 | req.onScriptLoad = function (evt) {
1460 | //Using currentTarget instead of target for Firefox 2.0's sake. Not
1461 | //all old browsers will be supported, but this one was easy enough
1462 | //to support and still makes sense.
1463 | var node = evt.currentTarget || evt.srcElement, contextName, moduleName,
1464 | context;
1465 | if (evt.type === "load" || readyRegExp.test(node.readyState)) {
1466 | //Pull out the name of the module and the context.
1467 | contextName = node.getAttribute("data-requirecontext");
1468 | moduleName = node.getAttribute("data-requiremodule");
1469 | context = s.contexts[contextName];
1470 |
1471 | req.completeLoad(moduleName, context);
1472 |
1473 | //Clean up script binding.
1474 | if (node.removeEventListener) {
1475 | node.removeEventListener("load", req.onScriptLoad, false);
1476 | } else {
1477 | //Probably IE. If not it will throw an error, which will be
1478 | //useful to know.
1479 | node.detachEvent("onreadystatechange", req.onScriptLoad);
1480 | }
1481 | }
1482 | };
1483 |
1484 | /**
1485 | * Attaches the script represented by the URL to the current
1486 | * environment. Right now only supports browser loading,
1487 | * but can be redefined in other environments to do the right thing.
1488 | * @param {String} url the url of the script to attach.
1489 | * @param {String} contextName the name of the context that wants the script.
1490 | * @param {moduleName} the name of the module that is associated with the script.
1491 | * @param {Function} [callback] optional callback, defaults to require.onScriptLoad
1492 | * @param {String} [type] optional type, defaults to text/javascript
1493 | */
1494 | req.attach = function (url, contextName, moduleName, callback, type) {
1495 | var node, loaded, context;
1496 | if (isBrowser) {
1497 | //In the browser so use a script tag
1498 | callback = callback || req.onScriptLoad;
1499 | node = document.createElement("script");
1500 | node.type = type || "text/javascript";
1501 | node.charset = "utf-8";
1502 | //Use async so Gecko does not block on executing the script if something
1503 | //like a long-polling comet tag is being run first. Gecko likes
1504 | //to evaluate scripts in DOM order, even for dynamic scripts.
1505 | //It will fetch them async, but only evaluate the contents in DOM
1506 | //order, so a long-polling script tag can delay execution of scripts
1507 | //after it. But telling Gecko we expect async gets us the behavior
1508 | //we want -- execute it whenever it is finished downloading. Only
1509 | //Helps Firefox 3.6+
1510 | //Allow some URLs to not be fetched async. Mostly helps the order!
1511 | //plugin
1512 | if (!s.skipAsync[url]) {
1513 | node.async = true;
1514 | }
1515 | node.setAttribute("data-requirecontext", contextName);
1516 | node.setAttribute("data-requiremodule", moduleName);
1517 |
1518 | //Set up load listener.
1519 | if (node.addEventListener) {
1520 | node.addEventListener("load", callback, false);
1521 | } else {
1522 | //Probably IE. If not it will throw an error, which will be
1523 | //useful to know. IE (at least 6-8) do not fire
1524 | //script onload right after executing the script, so
1525 | //we cannot tie the anonymous require.def call to a name.
1526 | //However, IE reports the script as being in "interactive"
1527 | //readyState at the time of the require.def call.
1528 | useInteractive = true;
1529 | node.attachEvent("onreadystatechange", callback);
1530 | }
1531 | node.src = url;
1532 |
1533 | //For some cache cases in IE 6-8, the script executes before the end
1534 | //of the appendChild execution, so to tie an anonymous require.def
1535 | //call to the module name (which is stored on the node), hold on
1536 | //to a reference to this node, but clear after the DOM insertion.
1537 | currentlyAddingScript = node;
1538 | if (baseElement) {
1539 | s.head.insertBefore(node, baseElement);
1540 | } else {
1541 | s.head.appendChild(node);
1542 | }
1543 | currentlyAddingScript = null;
1544 | return node;
1545 | } else if (isWebWorker) {
1546 | //In a web worker, use importScripts. This is not a very
1547 | //efficient use of importScripts, importScripts will block until
1548 | //its script is downloaded and evaluated. However, if web workers
1549 | //are in play, the expectation that a build has been done so that
1550 | //only one script needs to be loaded anyway. This may need to be
1551 | //reevaluated if other use cases become common.
1552 | context = s.contexts[contextName];
1553 | loaded = context.loaded;
1554 | loaded[moduleName] = false;
1555 | importScripts(url);
1556 |
1557 | //Account for anonymous modules
1558 | req.completeLoad(moduleName, context);
1559 | }
1560 | return null;
1561 | };
1562 |
1563 | //Determine what baseUrl should be if not already defined via a require config object
1564 | s.baseUrl = cfg.baseUrl;
1565 | if (isBrowser && (!s.baseUrl || !s.head)) {
1566 | //Figure out baseUrl. Get it from the script tag with require.js in it.
1567 | scripts = document.getElementsByTagName("script");
1568 | if (cfg.baseUrlMatch) {
1569 | rePkg = cfg.baseUrlMatch;
1570 | } else {
1571 | //>>includeStart("jquery", pragmas.jquery);
1572 | rePkg = /(requireplugins-|require-)?jquery[\-\d\.]*(min)?\.js(\W|$)/i;
1573 | //>>includeEnd("jquery");
1574 |
1575 | //>>includeStart("dojoConvert", pragmas.dojoConvert);
1576 | rePkg = /dojo\.js(\W|$)/i;
1577 | //>>includeEnd("dojoConvert");
1578 |
1579 | //>>excludeStart("dojoConvert", pragmas.dojoConvert);
1580 |
1581 | //>>excludeStart("jquery", pragmas.jquery);
1582 | rePkg = /(allplugins-)?require\.js(\W|$)/i;
1583 | //>>excludeEnd("jquery");
1584 |
1585 | //>>excludeEnd("dojoConvert");
1586 | }
1587 |
1588 | for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
1589 | //Set the "head" where we can append children by
1590 | //using the script's parent.
1591 | if (!s.head) {
1592 | s.head = script.parentNode;
1593 | }
1594 |
1595 | //Look for a data-main attribute to set main script for the page
1596 | //to load.
1597 | if (!cfg.deps) {
1598 | dataMain = script.getAttribute('data-main');
1599 | if (dataMain) {
1600 | cfg.deps = [dataMain];
1601 | }
1602 | }
1603 |
1604 | //Using .src instead of getAttribute to get an absolute URL.
1605 | //While using a relative URL will be fine for script tags, other
1606 | //URLs used for text! resources that use XHR calls might benefit
1607 | //from an absolute URL.
1608 | src = script.src;
1609 | if (src && !s.baseUrl) {
1610 | m = src.match(rePkg);
1611 | if (m) {
1612 | s.baseUrl = src.substring(0, m.index);
1613 | break;
1614 | }
1615 | }
1616 | }
1617 | }
1618 |
1619 | //>>excludeStart("requireExcludePageLoad", pragmas.requireExcludePageLoad);
1620 | //****** START page load functionality ****************
1621 | /**
1622 | * Sets the page as loaded and triggers check for all modules loaded.
1623 | */
1624 | req.pageLoaded = function () {
1625 | if (!s.isPageLoaded) {
1626 | s.isPageLoaded = true;
1627 | if (scrollIntervalId) {
1628 | clearInterval(scrollIntervalId);
1629 | }
1630 |
1631 | //Part of a fix for FF < 3.6 where readyState was not set to
1632 | //complete so libraries like jQuery that check for readyState
1633 | //after page load where not getting initialized correctly.
1634 | //Original approach suggested by Andrea Giammarchi:
1635 | //http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
1636 | //see other setReadyState reference for the rest of the fix.
1637 | if (setReadyState) {
1638 | document.readyState = "complete";
1639 | }
1640 |
1641 | req.callReady();
1642 | }
1643 | };
1644 |
1645 | /**
1646 | * Internal function that calls back any ready functions. If you are
1647 | * integrating RequireJS with another library without require.ready support,
1648 | * you can define this method to call your page ready code instead.
1649 | */
1650 | req.callReady = function () {
1651 | var callbacks = s.readyCalls, i, callback, contexts, context, prop;
1652 |
1653 | if (s.isPageLoaded && s.isDone) {
1654 | if (callbacks.length) {
1655 | s.readyCalls = [];
1656 | for (i = 0; (callback = callbacks[i]); i++) {
1657 | callback();
1658 | }
1659 | }
1660 |
1661 | //If jQuery with readyWait is being tracked, updated its
1662 | //readyWait count.
1663 | contexts = s.contexts;
1664 | for (prop in contexts) {
1665 | if (!(prop in empty)) {
1666 | context = contexts[prop];
1667 | if (context.jQueryIncremented) {
1668 | context.jQuery.readyWait -= 1;
1669 | context.jQueryIncremented = false;
1670 | }
1671 | }
1672 | }
1673 | }
1674 | };
1675 |
1676 | /**
1677 | * Registers functions to call when the page is loaded
1678 | */
1679 | req.ready = function (callback) {
1680 | if (s.isPageLoaded && s.isDone) {
1681 | callback();
1682 | } else {
1683 | s.readyCalls.push(callback);
1684 | }
1685 | return req;
1686 | };
1687 |
1688 | if (isBrowser) {
1689 | if (document.addEventListener) {
1690 | //Standards. Hooray! Assumption here that if standards based,
1691 | //it knows about DOMContentLoaded.
1692 | document.addEventListener("DOMContentLoaded", req.pageLoaded, false);
1693 | window.addEventListener("load", req.pageLoaded, false);
1694 | //Part of FF < 3.6 readystate fix (see setReadyState refs for more info)
1695 | if (!document.readyState) {
1696 | setReadyState = true;
1697 | document.readyState = "loading";
1698 | }
1699 | } else if (window.attachEvent) {
1700 | window.attachEvent("onload", req.pageLoaded);
1701 |
1702 | //DOMContentLoaded approximation, as found by Diego Perini:
1703 | //http://javascript.nwbox.com/IEContentLoaded/
1704 | if (self === self.top) {
1705 | scrollIntervalId = setInterval(function () {
1706 | try {
1707 | //From this ticket:
1708 | //http://bugs.dojotoolkit.org/ticket/11106,
1709 | //In IE HTML Application (HTA), such as in a selenium test,
1710 | //javascript in the iframe can't see anything outside
1711 | //of it, so self===self.top is true, but the iframe is
1712 | //not the top window and doScroll will be available
1713 | //before document.body is set. Test document.body
1714 | //before trying the doScroll trick.
1715 | if (document.body) {
1716 | document.documentElement.doScroll("left");
1717 | req.pageLoaded();
1718 | }
1719 | } catch (e) {}
1720 | }, 30);
1721 | }
1722 | }
1723 |
1724 | //Check if document already complete, and if so, just trigger page load
1725 | //listeners. NOTE: does not work with Firefox before 3.6. To support
1726 | //those browsers, manually call require.pageLoaded().
1727 | if (document.readyState === "complete") {
1728 | req.pageLoaded();
1729 | }
1730 | }
1731 | //****** END page load functionality ****************
1732 | //>>excludeEnd("requireExcludePageLoad");
1733 |
1734 | //Set up default context. If require was a configuration object, use that as base config.
1735 | req(cfg);
1736 |
1737 | //If modules are built into require.js, then need to make sure dependencies are
1738 | //traced. Use a setTimeout in the browser world, to allow all the modules to register
1739 | //themselves. In a non-browser env, assume that modules are not built into require.js,
1740 | //which seems odd to do on the server.
1741 | if (typeof setTimeout !== "undefined") {
1742 | setTimeout(function () {
1743 | var ctx = s.contexts[(cfg.context || defContextName)];
1744 | //Allow for jQuery to be loaded/already in the page, and if jQuery 1.4.3,
1745 | //make sure to hold onto it for readyWait triggering.
1746 | jQueryCheck(ctx);
1747 | resume(ctx);
1748 | }, 0);
1749 | }
1750 | }());
1751 |
--------------------------------------------------------------------------------