diff options
author | hwc487 | 2012-02-03 09:33:35 -0800 |
---|---|---|
committer | hwc487 | 2012-02-03 09:33:35 -0800 |
commit | 7dd20aec0a91731c2acaa0abfa66b754b6c82fe6 (patch) | |
tree | 278b656279d028d4d20ac5345837f1eb87ba4192 /node_modules/montage/montage.js | |
parent | e02deaf0d1b1f7dbcf022442cb730490ac8cee8b (diff) | |
parent | c630ead20487c3948fa36448d3e7d5f7b5cba782 (diff) | |
download | ninja-7dd20aec0a91731c2acaa0abfa66b754b6c82fe6.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into working
Diffstat (limited to 'node_modules/montage/montage.js')
-rwxr-xr-x | node_modules/montage/montage.js | 213 |
1 files changed, 126 insertions, 87 deletions
diff --git a/node_modules/montage/montage.js b/node_modules/montage/montage.js index 07975ae8..cee1f27a 100755 --- a/node_modules/montage/montage.js +++ b/node_modules/montage/montage.js | |||
@@ -4,28 +4,32 @@ | |||
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 | 6 | ||
7 | document._montageTiming = {} | 7 | if (typeof window !== "undefined") { |
8 | document._montageTiming.loadStartTime = Date.now(); | 8 | |
9 | 9 | document._montageTiming = {} | |
10 | // Give a threshold before we decide we need to show the bootstrapper progress | 10 | document._montageTiming.loadStartTime = Date.now(); |
11 | // Applications that use our loader will interact with this timeout | 11 | |
12 | // and class name to coordinate a nice loading experience. Applications that do not will | 12 | // Give a threshold before we decide we need to show the bootstrapper progress |
13 | // just go about business as usual and draw their content as soon as possible. | 13 | // Applications that use our loader will interact with this timeout |
14 | window.addEventListener("DOMContentLoaded", function() { | 14 | // and class name to coordinate a nice loading experience. Applications that do not will |
15 | var bootstrappingDelay = 1000; | 15 | // just go about business as usual and draw their content as soon as possible. |
16 | document._montageStartBootstrappingTimeout = setTimeout(function() { | 16 | window.addEventListener("DOMContentLoaded", function() { |
17 | document._montageStartBootstrappingTimeout = null; | 17 | var bootstrappingDelay = 1000; |
18 | 18 | document._montageStartBootstrappingTimeout = setTimeout(function() { | |
19 | var root = document.documentElement; | 19 | document._montageStartBootstrappingTimeout = null; |
20 | if(!!root.classList) { | 20 | |
21 | root.classList.add("montage-app-bootstrapping"); | 21 | var root = document.documentElement; |
22 | } else { | 22 | if(!!root.classList) { |
23 | root.className = root.className + " montage-app-bootstrapping"; | 23 | root.classList.add("montage-app-bootstrapping"); |
24 | } | 24 | } else { |
25 | root.className = root.className + " montage-app-bootstrapping"; | ||
26 | } | ||
25 | 27 | ||
26 | document._montageTiming.bootstrappingStartTime = Date.now(); | 28 | document._montageTiming.bootstrappingStartTime = Date.now(); |
27 | }, bootstrappingDelay); | 29 | }, bootstrappingDelay); |
28 | }); | 30 | }); |
31 | |||
32 | } | ||
29 | 33 | ||
30 | (function (definition) { | 34 | (function (definition) { |
31 | if (typeof require !== "undefined") { | 35 | if (typeof require !== "undefined") { |
@@ -50,32 +54,50 @@ window.addEventListener("DOMContentLoaded", function() { | |||
50 | */ | 54 | */ |
51 | exports.initMontage = function () { | 55 | exports.initMontage = function () { |
52 | var platform = exports.getPlatform(); | 56 | var platform = exports.getPlatform(); |
53 | var params = platform.getParams(); | ||
54 | var config = platform.getConfig(); | ||
55 | 57 | ||
56 | // Platform dependent | 58 | // Platform dependent |
57 | platform.loadCJS(function (CJS, Q, URL) { | 59 | platform.bootstrap(function (Require, Promise, URL) { |
60 | var params = platform.getParams(); | ||
61 | var config = platform.getConfig(); | ||
58 | 62 | ||
59 | // setup the reel loader | 63 | // setup the reel loader |
60 | config.makeLoader = function (config) { | 64 | config.makeLoader = function (config) { |
61 | return exports.ReelLoader(config, | 65 | return exports.ReelLoader(config, |
62 | CJS.DefaultLoaderConstructor(config)); | 66 | Require.DefaultLoaderConstructor(config)); |
63 | }; | 67 | }; |
64 | 68 | ||
65 | // setup serialization compiler | 69 | // setup serialization compiler |
66 | config.makeCompiler = function (config) { | 70 | config.makeCompiler = function (config) { |
67 | return exports.TemplateCompiler(config, | 71 | return exports.TemplateCompiler(config, |
68 | exports.SerializationCompiler(config, | 72 | exports.SerializationCompiler(config, |
69 | CJS.DefaultCompilerConstructor(config))); | 73 | Require.DefaultCompilerConstructor(config))); |
70 | }; | 74 | }; |
71 | 75 | ||
72 | var location = URL.resolve(window.location, params["package"] || "."); | 76 | var location = URL.resolve(config.location, params["package"] || "."); |
73 | 77 | ||
74 | CJS.PackageSandbox(params.montageBase, config) | 78 | Require.PackageSandbox(params.montageBase, config) |
75 | .then(function (montageRequire) { | 79 | .then(function (montageRequire) { |
76 | montageRequire.config.modules["core/promise"] = {exports: Q}; | 80 | montageRequire.inject("core/promise", Promise); |
77 | montageRequire.config.modules["core/url"] = {exports: URL}; | 81 | montageRequire.inject("core/shim/timeers", {}); |
78 | montageRequire.config.modules["core/shim/timers"] = {exports: {}}; | 82 | |
83 | // install the linter, which loads on the first error | ||
84 | config.lint = function (module) { | ||
85 | montageRequire.async("core/jshint") | ||
86 | .then(function (JSHINT) { | ||
87 | if (!JSHINT.JSHINT(module.text)) { | ||
88 | console.warn("JSHint Error: "+module.location); | ||
89 | JSHINT.JSHINT.errors.forEach(function(error) { | ||
90 | if (error) { | ||
91 | console.warn("Problem at line "+error.line+" character "+error.character+": "+error.reason); | ||
92 | if (error.evidence) { | ||
93 | console.warn(" " + error.evidence); | ||
94 | } | ||
95 | } | ||
96 | }); | ||
97 | } | ||
98 | }); | ||
99 | }; | ||
100 | |||
79 | return montageRequire.loadPackage(location) | 101 | return montageRequire.loadPackage(location) |
80 | .then(function (applicationRequire) { | 102 | .then(function (applicationRequire) { |
81 | global.require = applicationRequire; | 103 | global.require = applicationRequire; |
@@ -96,25 +118,23 @@ window.addEventListener("DOMContentLoaded", function() { | |||
96 | @param config | 118 | @param config |
97 | @param compiler | 119 | @param compiler |
98 | */ | 120 | */ |
99 | exports.SerializationCompiler = function(config, compiler) { | 121 | exports.SerializationCompiler = function(config, compile) { |
100 | return function(def) { | 122 | return function(module) { |
101 | def = compiler(def); | 123 | compile(module); |
102 | var defaultFactory = def.factory; | 124 | if (!module.factory) |
103 | def.factory = function(require, exports, module) { | 125 | return; |
126 | var defaultFactory = module.factory; | ||
127 | module.factory = function(require, exports, module) { | ||
104 | defaultFactory.call(this, require, exports, module); | 128 | defaultFactory.call(this, require, exports, module); |
105 | for (var symbol in exports) { | 129 | for (var symbol in exports) { |
130 | var object = exports[symbol]; | ||
106 | // avoid attempting to reinitialize an aliased property | 131 | // avoid attempting to reinitialize an aliased property |
107 | if ( | 132 | if (object.hasOwnProperty("_montage_metadata")) { |
108 | Object.prototype.hasOwnProperty.call( | 133 | object._montage_metadata.aliases.push(symbol); |
109 | exports[symbol], | 134 | object._montage_metadata.objectName = symbol; |
110 | "_montage_metadata" | 135 | } else if (!Object.isSealed(object)) { |
111 | ) | ||
112 | ) { | ||
113 | exports[symbol]._montage_metadata.aliases.push(symbol); | ||
114 | exports[symbol]._montage_metadata.objectName = symbol; | ||
115 | } else if (!Object.isSealed(exports[symbol])) { | ||
116 | Object.defineProperty( | 136 | Object.defineProperty( |
117 | exports[symbol], | 137 | object, |
118 | "_montage_metadata", | 138 | "_montage_metadata", |
119 | { | 139 | { |
120 | value: { | 140 | value: { |
@@ -129,7 +149,7 @@ window.addEventListener("DOMContentLoaded", function() { | |||
129 | } | 149 | } |
130 | } | 150 | } |
131 | }; | 151 | }; |
132 | return def; | 152 | return module; |
133 | }; | 153 | }; |
134 | }; | 154 | }; |
135 | 155 | ||
@@ -141,13 +161,14 @@ window.addEventListener("DOMContentLoaded", function() { | |||
141 | * @param loader the next loader in the chain | 161 | * @param loader the next loader in the chain |
142 | */ | 162 | */ |
143 | var reelExpression = /([^\/]+)\.reel$/; | 163 | var reelExpression = /([^\/]+)\.reel$/; |
144 | exports.ReelLoader = function (config, loader) { | 164 | exports.ReelLoader = function (config, load) { |
145 | return function (id, callback) { | 165 | return function (id, module) { |
146 | var match = reelExpression.exec(id); | 166 | var match = reelExpression.exec(id); |
147 | if (match) { | 167 | if (match) { |
148 | return loader(id + "/" + match[1], callback); | 168 | module.redirect = id + "/" + match[1]; |
169 | return module; | ||
149 | } else { | 170 | } else { |
150 | return loader(id, callback); | 171 | return load(id, module); |
151 | } | 172 | } |
152 | }; | 173 | }; |
153 | }; | 174 | }; |
@@ -158,23 +179,20 @@ window.addEventListener("DOMContentLoaded", function() { | |||
158 | @param config | 179 | @param config |
159 | @param compiler | 180 | @param compiler |
160 | */ | 181 | */ |
161 | exports.TemplateCompiler = function(config, compiler) { | 182 | exports.TemplateCompiler = function(config, compile) { |
162 | return function(def) { | 183 | return function(module) { |
163 | var root = def.path.match(/(.*\/)?(?=[^\/]+\.html$)/); | 184 | if (!module.location) |
185 | return; | ||
186 | var root = module.location.match(/(.*\/)?(?=[^\/]+\.html$)/); | ||
164 | if (root) { | 187 | if (root) { |
165 | def.dependencies = def.dependencies || []; | 188 | module.dependencies = module.dependencies || []; |
166 | var originalFactory = def.factory; | 189 | module.exports = { |
167 | def.factory = function(require, exports, module) { | 190 | root: root, |
168 | if (originalFactory) { | 191 | content: module.text |
169 | originalFactory(require, exports, module); | ||
170 | } | ||
171 | // Use module.exports in case originalFactory changed it. | ||
172 | module.exports.root = module.exports.root || root; | ||
173 | module.exports.content = module.exports.content || def.text; | ||
174 | }; | 192 | }; |
175 | return def; | 193 | return module; |
176 | } else { | 194 | } else { |
177 | return compiler(def); | 195 | compile(module); |
178 | } | 196 | } |