diff options
author | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
---|---|---|
committer | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
commit | 10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e (patch) | |
tree | 12b31910a3c7c7fa2ee0b26d8aaa611710e139a5 /node_modules/montage/require/require.js | |
parent | 7f8730c3add146f1ba107e6fc22d1f5a8348ed8b (diff) | |
parent | 668510892537eaaeb2e11520831d87b44b2489b7 (diff) | |
download | ninja-10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into text-tool
Conflicts:
_scss/compass_app_log.txt
css/ninja.css
Diffstat (limited to 'node_modules/montage/require/require.js')
-rwxr-xr-x | node_modules/montage/require/require.js | 997 |
1 files changed, 412 insertions, 585 deletions
diff --git a/node_modules/montage/require/require.js b/node_modules/montage/require/require.js index 988dd811..8273b660 100755 --- a/node_modules/montage/require/require.js +++ b/node_modules/montage/require/require.js | |||
@@ -3,12 +3,37 @@ | |||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> |
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | bootstrap("require/require", function (require, CJS) { | ||
7 | 6 | ||
8 | var Promise = require("core/promise").Promise; | 7 | (function (definition) { |
9 | var URL = require("core/url"); | ||
10 | 8 | ||
11 | var global = (function () {return this})(); | 9 | // Boostrapping Browser |
10 | if (typeof bootstrap !== "undefined") { | ||
11 | bootstrap("require/require", function (require, exports) { | ||
12 | var Promise = require("core/promise").Promise; | ||
13 | var URL = require("core/mini-url"); | ||
14 | definition(exports, Promise, URL); | ||
15 | require("require/browser"); | ||
16 | }); | ||
17 | |||
18 | // Node Server | ||
19 | } else if (typeof process !== "undefined") { | ||
20 | var Promise = (require)("../core/promise").Promise; | ||
21 | var URL = (require)("../core/url"); | ||
22 | definition(exports, Promise, URL); | ||
23 | require("./node"); | ||
24 | if (require.main == module) | ||
25 | exports.main(); | ||
26 | |||
27 | } else { | ||
28 | throw new Error("Can't support require on this platform"); | ||
29 | } | ||
30 | |||
31 | })(function (Require, Promise, URL) { | ||
32 | |||
33 | if (!this) | ||
34 | throw new Error("Require does not work in strict mode."); | ||
35 | |||
36 | var global = this; | ||
12 | var globalEval = eval; // reassigning causes eval to not use lexical scope. | 37 | var globalEval = eval; // reassigning causes eval to not use lexical scope. |
13 | 38 | ||
14 | // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. | 39 | // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. |
@@ -17,228 +42,192 @@ bootstrap("require/require", function (require, CJS) { | |||
17 | // Returns the root "require" function. If this root "require()" function is called the loader will be in synchronous mode. | 42 | // Returns the root "require" function. If this root "require()" function is called the loader will be in synchronous mode. |
18 | // To get asynchronous loading you MUST call the root "require.async()". In async mode all subsequent calls to "require()" will | 43 | // To get asynchronous loading you MUST call the root "require.async()". In async mode all subsequent calls to "require()" will |
19 | // be asynchronously loaded, and synchronously executed. | 44 | // be asynchronously loaded, and synchronously executed. |
20 | CJS.Sandbox = function(config) { | 45 | Require.Sandbox = function(config) { |
21 | // Configuration defaults: | 46 | // Configuration defaults: |
22 | config = config || {}; | 47 | config = config || {}; |
23 | config.location = URL.resolve(config.location || CJS.pwd(), "."); | 48 | config.location = URL.resolve(config.location || Require.getLocation(), "."); |
24 | config.lib = URL.resolve(config.location, config.lib || "."); | 49 | config.lib = URL.resolve(config.location, config.lib || "."); |
25 | config.paths = config.paths || [config.lib]; | 50 | config.paths = config.paths || [config.lib]; |
26 | config.mappings = config.mappings || {}; // EXTENSION | 51 | config.mappings = config.mappings || {}; // EXTENSION |
27 | config.definitions = config.definitions || {}; | 52 | config.exposedConfigs = config.exposedConfigs || Require.defaultExposedConfigs; |
28 | config.modules = config.modules || {}; | 53 | config.makeLoader = config.makeLoader || Require.DefaultLoaderConstructor; |
29 | config.exposedConfigs = config.exposedConfigs || [ | 54 | config.load = config.load || config.makeLoader(config); |
30 | "paths", | 55 | config.makeCompiler = config.makeCompiler || Require.DefaultCompilerConstructor; |
31 | "mappings", | 56 | config.compile = config.compile || config.makeCompiler(config); |
32 | "loader", | ||
33 | "definitions", | ||
34 | "base", | ||
35 | "location", | ||
36 | "packageDescription", | ||
37 | "loadPackage" | ||
38 | ]; | ||
39 | config.makeLoader = config.makeLoader || CJS.DefaultLoaderConstructor; | ||
40 | config.loader = config.loader || config.makeLoader(config); | ||
41 | config.makeCompiler = config.makeCompiler || CJS.DefaultCompilerConstructor; | ||
42 | config.compiler = config.compiler || config.makeCompiler(config); | ||
43 | 57 | ||
44 | // Sandbox state: | 58 | // Sandbox state: |
45 | // Module instances: { exports, id, path, uri } | 59 | // Modules: { exports, id, location, directory, factory, dependencies, dependees, text, type } |
46 | var modules = config.modules; | 60 | var modules = config.modules = config.modules || {}; |
47 | // Module definition objects: { factory, dependencies, path } | ||
48 | var definitions = config.definitions; | ||
49 | // Arrays of callbacks to be executed once a module definition has been loaded | ||
50 | var definitionListeners = {}; | ||
51 | // Mapping from canonical IDs to the initial top ID used to load module | 61 | // Mapping from canonical IDs to the initial top ID used to load module |
52 | var urisToIds = {}; | 62 | var locationsToIds = {}; |
53 | |||
54 | // Ensures a module definition is loaded before returning or executing the callback. | ||
55 | // Supports multiple calls for the same topId by registering callback as a listener if it has already been initiated. | ||
56 | function loadDefinition(topId, callback) { | ||
57 | if (callback) { | ||
58 | // already loaded | ||
59 | if (has(definitions, topId) && definitions[topId].factory) { | ||
60 | callback(topId); | ||
61 | } | ||
62 | // in progress | ||
63 | else if (has(definitionListeners, topId)) { | ||
64 | definitionListeners[topId].push(callback); | ||
65 | } | ||
66 | // pre-arranged | ||
67 | else if (has(definitions, topId) && definitions[topId].path !== undefined) { | ||
68 | var def = definitions[topId]; | ||
69 | CJS.read(def.path).then(function (text) { | ||
70 | def.text = text; | ||
71 | config.compiler(def); | ||
72 | callback(topId); | ||
73 | }, function (reason) { | ||
74 | console.warn("Can't read " + JSON.stringify(def.path) + ": " + reason); | ||
75 | callback(null); | ||
76 | }); | ||
77 | } | ||
78 | // hasn't started | ||
79 | else { | ||
80 | definitionListeners[topId] = [callback]; | ||
81 | 63 | ||
82 | config.loader(topId, function(definition) { | 64 | function getModule(id) { |
83 | if (!definition) { | 65 | if (!has(modules, id)) { |
84 | CJS.warn("Can't find module " + JSON.stringify(topId)); | 66 | modules[id] = { |
85 | } | 67 | id: id, |
86 | definitions[topId] = definition || null; | 68 | display: config.location + "#" + id // EXTENSION |
87 | 69 | }; | |
88 | CJS.progress.loadedModules.push([ | 70 | } |
89 | config.location, | 71 | return modules[id]; |
90 | topId | 72 | } |
91 | ].join("#")); | 73 | config.module = getModule; |
92 | 74 | ||
93 | definitionListeners[topId].forEach(function(fn) { | 75 | function inject(id, exports) { |
94 | fn(topId); | 76 | var module = getModule(id) |
95 | }); | 77 | module.exports = exports; |
78 | module.location = URL.resolve(config.location, id); | ||
79 | module.directory = URL.resolve(module.location, "."); | ||
80 | } | ||
96 | 81 | ||
82 | // Ensures a module definition is loaded, compiled, analyzed | ||
83 | var load = memoize(function (topId, viaId) { | ||
84 | var module = getModule(topId); | ||
85 | return Promise.call(function () { | ||
86 | // already loaded, already instantiated, or redirection | ||
87 | if ( | ||
88 | module.factory !== void 0 || | ||
89 | module.exports !== void 0 || | ||
90 | module.redirect !== void 0 | ||
91 | ) { | ||
92 | return module; | ||
93 | // load | ||
94 | } else { | ||
95 | Require.progress.requiredModules.push(module.display); | ||
96 | return Promise.call(config.load, null, topId, module) | ||
97 | .then(function () { | ||
98 | Require.progress.loadedModules.push(module.display); | ||
99 | return module; | ||
97 | }); | 100 | }); |
98 | } | 101 | } |
99 | } else { | 102 | }) |
100 | // already loaded | 103 | .then(function (module) { |
101 | if (has(definitions, topId)) { | 104 | // analyze dependencies |
102 | return; | 105 | config.compile(module); |
103 | } | 106 | var dependencies = module.dependencies = module.dependencies || []; |
104 | // hasn't started | 107 | if (module.redirect !== void 0) { |
105 | else { | 108 | dependencies.push(module.redirect); |
106 | var definition = config.loader(topId); | ||
107 | if (!definition) { | ||
108 | CJS.warn("Can't find module " + JSON.stringify(topId)); | ||
109 | } | ||
110 | definitions[topId] = definition || null; | ||
111 | } | 109 | } |
112 | } | 110 | return module; |
111 | }); | ||
112 | }); | ||
113 | |||
114 | // Load a module definition, and the definitions of its transitive | ||
115 | // dependencies | ||
116 | function deepLoad(id, viaId, loading) { | ||
117 | // this is a memo of modules already being loaded so we don’t | ||
118 | // data-lock on a cycle of dependencies. | ||
119 | loading = loading || {}; | ||
120 | // has this all happened before? will it happen again? | ||
121 | if (has(loading, id)) | ||
122 | return; // break the cycle of violence. | ||
123 | loading[id] = true; // this has happened before | ||
124 | return load(id, viaId) | ||
125 | .then(function (module) { | ||
126 | // load the transitive dependencies using the magic of | ||