aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/montage.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/montage.js')
-rwxr-xr-xnode_modules/montage-user/montage.js401
1 files changed, 401 insertions, 0 deletions
diff --git a/node_modules/montage-user/montage.js b/node_modules/montage-user/montage.js
new file mode 100755
index 00000000..cee1f27a
--- /dev/null
+++ b/node_modules/montage-user/montage.js
@@ -0,0 +1,401 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<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.
5 </copyright> */
6
7if (typeof window !== "undefined") {
8
9 document._montageTiming = {}
10 document._montageTiming.loadStartTime = Date.now();
11
12 // Give a threshold before we decide we need to show the bootstrapper progress
13 // Applications that use our loader will interact with this timeout
14 // and class name to coordinate a nice loading experience. Applications that do not will
15 // just go about business as usual and draw their content as soon as possible.
16 window.addEventListener("DOMContentLoaded", function() {
17 var bootstrappingDelay = 1000;
18 document._montageStartBootstrappingTimeout = setTimeout(function() {
19 document._montageStartBootstrappingTimeout = null;
20
21 var root = document.documentElement;
22 if(!!root.classList) {
23 root.classList.add("montage-app-bootstrapping");
24 } else {
25 root.className = root.className + " montage-app-bootstrapping";
26 }
27
28 document._montageTiming.bootstrappingStartTime = Date.now();
29 }, bootstrappingDelay);
30 });
31
32}
33
34(function (definition) {
35 if (typeof require !== "undefined") {
36 // CommonJS / NodeJS
37 definition(require, exports, module);
38 } else {
39 // <script>
40 definition({}, {}, {});
41 }
42})(function (require, exports, module) {
43
44 // The global context object, works for the browser and for node.
45 // XXX Will not work in strict mode
46 var global = (function() {
47 return this;
48 })();
49
50 /**
51 * Initializes Montage and creates the application singleton if necessary.
52 * @param options
53 * @param callback
54 */
55 exports.initMontage = function () {
56 var platform = exports.getPlatform();
57
58 // Platform dependent
59 platform.bootstrap(function (Require, Promise, URL) {
60 var params = platform.getParams();
61 var config = platform.getConfig();
62
63 // setup the reel loader
64 config.makeLoader = function (config) {
65 return exports.ReelLoader(config,
66 Require.DefaultLoaderConstructor(config));
67 };
68
69 // setup serialization compiler
70 config.makeCompiler = function (config) {
71 return exports.TemplateCompiler(config,
72 exports.SerializationCompiler(config,
73 Require.DefaultCompilerConstructor(config)));
74 };
75
76 var location = URL.resolve(config.location, params["package"] || ".");
77
78 Require.PackageSandbox(params.montageBase, config)
79 .then(function (montageRequire) {
80 montageRequire.inject("core/promise", Promise);
81 montageRequire.inject("core/shim/timeers", {});
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
101 return montageRequire.loadPackage(location)
102 .then(function (applicationRequire) {
103 global.require = applicationRequire;
104 global.montageRequire = montageRequire;
105 platform.initMontage(montageRequire, applicationRequire, params);
106 })
107 })
108 .end();
109
110 });
111
112 };
113
114 /**
115 Adds "_montage_metadata" property to all objects and function attached to
116 the exports object.
117 @see Compiler middleware in require/require.js
118 @param config
119 @param compiler
120 */
121 exports.SerializationCompiler = function(config, compile) {
122 return function(module) {
123 compile(module);
124 if (!module.factory)
125 return;
126 var defaultFactory = module.factory;
127 module.factory = function(require, exports, module) {
128 defaultFactory.call(this, require, exports, module);
129 for (var symbol in exports) {
130 var object = exports[symbol];
131 // avoid attempting to reinitialize an aliased property
132 if (object.hasOwnProperty("_montage_metadata")) {
133 object._montage_metadata.aliases.push(symbol);
134 object._montage_metadata.objectName = symbol;
135 } else if (!Object.isSealed(object)) {
136 Object.defineProperty(
137 object,
138 "_montage_metadata",
139 {
140 value: {
141 require: require,
142 moduleId: module.id,
143 objectName: symbol,
144 aliases: [symbol],
145 isInstance: false
146 }
147 }
148 );
149 }
150 }
151 };
152 return module;
153 };
154 };
155
156 /**
157 * Allows reel directories to load the contained eponymous JavaScript
158 * module.
159 * @see Loader middleware in require/require.js
160 * @param config
161 * @param loader the next loader in the chain
162 */
163 var reelExpression = /([^\/]+)\.reel$/;
164 exports.ReelLoader = function (config, load) {
165 return function (id, module) {
166 var match = reelExpression.exec(id);
167 if (match) {
168 module.redirect = id + "/" + match[1];
169 return module;
170 } else {
171 return load(id, module);
172 }
173 };
174 };
175
176 /**
177 Allows the reel's html file to be loaded via require.
178 @see Compiler middleware in require/require.js
179 @param config
180 @param compiler
181 */
182 exports.TemplateCompiler = function(config, compile) {
183 return function(module) {
184 if (!module.location)
185 return;
186 var root = module.location.match(/(.*\/)?(?=[^\/]+\.html$)/);
187 if (root) {
188 module.dependencies = module.dependencies || [];
189 module.exports = {
190 root: root,
191 content: module.text
192 };
193 return module;
194 } else {
195 compile(module);
196 }
197 };
198 };
199
200 // Bootstrapping for multiple-platforms
201
202 exports.getPlatform = function () {
203 if (typeof window !== "undefined" && window && window.document) {
204 return browser;
205 } else if (typeof process !== "undefined") {
206 return require("./node.js");
207 } else {
208 throw new Error("Platform not supported.");
209 }
210 };
211
212 var urlModuleFactory = function (require, exports) {
213 var baseElement = document.createElement("base");
214 baseElement.href = "";
215 document.querySelector("head").appendChild(baseElement);
216 var relativeElement = document.createElement("a");
217 exports.resolve = function (base, relative) {
218 base = String(base);
219 if (!/^[\w\-]+:/.test(base)) {
220 throw new Error("Can't resolve from a relative location: " + JSON.stringify(base) + " " + JSON.stringify(relative));
221 }
222 var restore = baseElement.href;
223 baseElement.href = base;
224 relativeElement.href = relative;
225 var resolved = relativeElement.href;
226 baseElement.href = restore;
227 return resolved;
228 };
229 };
230
231 var browser = {
232