aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/montage.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/montage.js')
-rwxr-xr-xnode_modules/montage/montage.js68
1 files changed, 45 insertions, 23 deletions
diff --git a/node_modules/montage/montage.js b/node_modules/montage/montage.js
index 495b6c72..e9e9b455 100755
--- a/node_modules/montage/montage.js
+++ b/node_modules/montage/montage.js
@@ -60,22 +60,30 @@ if (typeof window !== "undefined") {
60 var params = platform.getParams(); 60 var params = platform.getParams();
61 var config = platform.getConfig(); 61 var config = platform.getConfig();
62 62
63 var montageLocation = URL.resolve(Require.getLocation(), params.montageLocation);
64
63 // setup the reel loader 65 // setup the reel loader
64 config.makeLoader = function (config) { 66 config.makeLoader = function (config) {
65 return exports.ReelLoader(config, 67 return exports.ReelLoader(
66 Require.DefaultLoaderConstructor(config)); 68 config,
69 Require.makeLoader(config)
70 );
67 }; 71 };
68 72
69 // setup serialization compiler 73 // setup serialization compiler
70 config.makeCompiler = function (config) { 74 config.makeCompiler = function (config) {
71 return exports.TemplateCompiler(config, 75 return exports.SerializationCompiler(
72 exports.SerializationCompiler(config, 76 config,
73 Require.DefaultCompilerConstructor(config))); 77 exports.TemplateCompiler(
78 config,
79 Require.makeCompiler(config)
80 )
81 );
74 }; 82 };
75 83
76 var location = URL.resolve(config.location, params["package"] || "."); 84 var location = URL.resolve(config.location, params["package"] || ".");
77 85
78 Require.PackageSandbox(params.montageBase, config) 86 Require.loadPackage(montageLocation, config)
79 .then(function (montageRequire) { 87 .then(function (montageRequire) {
80 montageRequire.inject("core/promise", Promise); 88 montageRequire.inject("core/promise", Promise);
81 montageRequire.inject("core/shim/timers", {}); 89 montageRequire.inject("core/shim/timers", {});
@@ -183,11 +191,12 @@ if (typeof window !== "undefined") {
183 return function(module) { 191 return function(module) {
184 if (!module.location) 192 if (!module.location)
185 return; 193 return;
186 var root = module.location.match(/(.*\/)?(?=[^\/]+\.html$)/); 194 var match = module.location.match(/(.*\/)?(?=[^\/]+\.html$)/);
187 if (root) { 195 if (match) {
188 module.dependencies = module.dependencies || []; 196 module.dependencies = module.dependencies || [];
189 module.exports = { 197 module.exports = {
190 root: root, 198 directory: match[1],
199 root: match, // deprecated
191 content: module.text 200 content: module.text
192 }; 201 };
193 return module; 202 return module;
@@ -216,7 +225,7 @@ if (typeof window !== "undefined") {
216 var relativeElement = document.createElement("a"); 225 var relativeElement = document.createElement("a");
217 exports.resolve = function (base, relative) { 226 exports.resolve = function (base, relative) {
218 base = String(base); 227 base = String(base);
219 if (!/^[\w\-]+:/.test(base)) { 228 if (!/^[\w\-]+:/.test(base)) { // isAbsolute(base)
220 throw new Error("Can't resolve from a relative location: " + JSON.stringify(base) + " " + JSON.stringify(relative)); 229 throw new Error("Can't resolve from a relative location: " + JSON.stringify(base) + " " + JSON.stringify(relative));
221 } 230 }
222 var restore = baseElement.href; 231 var restore = baseElement.href;
@@ -240,6 +249,7 @@ if (typeof window !== "undefined") {
240 var i, j, 249 var i, j,
241 match, 250 match,
242 script, 251 script,
252 montage,
243 attr, 253 attr,
244 name; 254 name;
245 if (!this._params) { 255 if (!this._params) {
@@ -249,8 +259,16 @@ if (typeof window !== "undefined") {
249 var scripts = document.getElementsByTagName("script"); 259 var scripts = document.getElementsByTagName("script");
250 for (i = 0; i < scripts.length; i++) { 260 for (i = 0; i < scripts.length; i++) {
251 script = scripts[i]; 261 script = scripts[i];
262 montage = false;
252 if (script.src && (match = script.src.match(/^(.*)montage.js(?:[\?\.]|$)/i))) { 263 if (script.src && (match = script.src.match(/^(.*)montage.js(?:[\?\.]|$)/i))) {
253 this._params.montageBase = match[1]; 264 this._params.montageLocation = match[1];
265 montage = true;
266 }
267 if (script.hasAttribute("data-montage")) {
268 this._params.montageLocation = script.getAttribute("data-montage");
269 montage = true;
270 }
271 if (montage) {
254 if (script.dataset) { 272 if (script.dataset) {
255 for (name in script.dataset) { 273 for (name in script.dataset) {
256 this._params[name] = script.dataset[name]; 274 this._params[name] = script.dataset[name];
@@ -304,17 +322,20 @@ if (typeof window !== "undefined") {
304 "core/next-tick" 322 "core/next-tick"
305 ]; 323 ];
306 324
307 // load in parallel 325 // load in parallel, but only if we’re not using a preloaded cache.
308 pending.forEach(function(name) { 326 // otherwise, these scripts will be inlined after already
309 var url = params.montageBase + name + ".js"; 327 if (typeof BUNDLE === "undefined") {
310 var script = document.createElement("script"); 328 pending.forEach(function(name) {
311 script.src = url; 329 var url = params.montageLocation + name + ".js";
312 script.onload = function () { 330 var script = document.createElement("script");
313 // remove clutter 331 script.src = url;
314 script.parentNode.removeChild(script); 332 script.onload = function () {
315 }; 333 // remove clutter
316 document.getElementsByTagName("head")[0].appendChild(script); 334 script.parentNode.removeChild(script);
317 }); 335 };
336 document.getElementsByTagName("head")[0].appendChild(script);
337 });
338 }
318 339
319 // register module definitions for deferred, 340 // register module definitions for deferred,
320 // serial execution 341 // serial execution
@@ -395,7 +416,8 @@ if (typeof window !== "undefined") {
395 exports.initMontage(); 416 exports.initMontage();
396 } 417 }
397 } else { 418 } else {
398 exports.getPlatform(); // may cause additional exports to be injected 419 // may cause additional exports to be injected:
420 exports.getPlatform();
399 } 421 }
400 422
401}); 423});