diff options
author | Jose Antonio Marquez | 2012-06-20 16:48:34 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-20 16:48:34 -0700 |
commit | 4eff115126ab946c5852d787fd596e07b156c9a5 (patch) | |
tree | f7d45b260f2fb5ba5dc4d1879076ca032d5ae2e6 /node_modules/montage/montage.js | |
parent | 7615da5c6ba54bd082eac4b8a6d9196084e5c590 (diff) | |
parent | 392a559e90357d48c910a07617261483b2b45476 (diff) | |
download | ninja-4eff115126ab946c5852d787fd596e07b156c9a5.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Color
Diffstat (limited to 'node_modules/montage/montage.js')
-rwxr-xr-x | node_modules/montage/montage.js | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/node_modules/montage/montage.js b/node_modules/montage/montage.js index c669f3f1..0906233f 100755 --- a/node_modules/montage/montage.js +++ b/node_modules/montage/montage.js | |||
@@ -41,11 +41,8 @@ if (typeof window !== "undefined") { | |||
41 | } | 41 | } |
42 | })(function (require, exports, module) { | 42 | })(function (require, exports, module) { |
43 | 43 | ||
44 | // The global context object, works for the browser and for node. | 44 | // The global context object |
45 | // XXX Will not work in strict mode | 45 | var global = new Function("return this")(); |
46 | var global = (function() { | ||
47 | return this; | ||
48 | })(); | ||
49 | 46 | ||
50 | /** | 47 | /** |
51 | * Initializes Montage and creates the application singleton if | 48 | * Initializes Montage and creates the application singleton if |
@@ -106,7 +103,7 @@ if (typeof window !== "undefined") { | |||
106 | }); | 103 | }); |
107 | }; | 104 | }; |
108 | 105 | ||
109 | if ('autoPackage' in params) { | 106 | if ("autoPackage" in params) { |
110 | montageRequire.injectPackageDescription(location, { | 107 | montageRequire.injectPackageDescription(location, { |
111 | dependencies: { | 108 | dependencies: { |
112 | montage: "*" | 109 | montage: "*" |
@@ -114,6 +111,16 @@ if (typeof window !== "undefined") { | |||
114 | }); | 111 | }); |
115 | } | 112 | } |
116 | 113 | ||
114 | // handle explicit package.json location | ||
115 | if (location.slice(location.length - 5) === ".json") { | ||
116 | var packageDescriptionLocation = location; | ||
117 | location = URL.resolve(location, "."); | ||
118 | montageRequire.injectPackageDescriptionLocation( | ||
119 | location, | ||
120 | packageDescriptionLocation | ||
121 | ); | ||
122 | } | ||
123 | |||
117 | return montageRequire.loadPackage(location) | 124 | return montageRequire.loadPackage(location) |
118 | .then(function (applicationRequire) { | 125 | .then(function (applicationRequire) { |
119 | global.require = applicationRequire; | 126 | global.require = applicationRequire; |
@@ -149,7 +156,7 @@ if (typeof window !== "undefined") { | |||
149 | // avoid attempting to initialize a non-object | 156 | // avoid attempting to initialize a non-object |
150 | if (!(object instanceof Object)) { | 157 | if (!(object instanceof Object)) { |
151 | // avoid attempting to reinitialize an aliased property | 158 | // avoid attempting to reinitialize an aliased property |
152 | } else if (object.hasOwnProperty("_montage_metadata")) { | 159 | } else if (object.hasOwnProperty("_montage_metadata") && !object._montage_metadata.isInstance) { |
153 | object._montage_metadata.aliases.push(name); | 160 | object._montage_metadata.aliases.push(name); |
154 | object._montage_metadata.objectName = name; | 161 | object._montage_metadata.objectName = name; |
155 | } else if (!Object.isSealed(object)) { | 162 | } else if (!Object.isSealed(object)) { |
@@ -269,7 +276,7 @@ if (typeof window !== "undefined") { | |||
269 | 276 | ||
270 | getConfig: function() { | 277 | getConfig: function() { |
271 | return { | 278 | return { |
272 | location: '' + window.location | 279 | location: "" + window.location |
273 | }; | 280 | }; |
274 | }, | 281 | }, |
275 | 282 | ||
@@ -379,7 +386,7 @@ if (typeof window !== "undefined") { | |||
379 | } | 386 | } |
380 | }; | 387 | }; |
381 | 388 | ||
382 | global.bootstrap('core/mini-url', urlModuleFactory); | 389 | global.bootstrap("core/mini-url", urlModuleFactory); |
383 | 390 | ||
384 | // miniature module system | 391 | // miniature module system |
385 | var bootModules = {}; | 392 | var bootModules = {}; |
@@ -410,31 +417,54 @@ if (typeof window !== "undefined") { | |||
410 | }, | 417 | }, |
411 | 418 | ||
412 | initMontage: function (montageRequire, applicationRequire, params) { | 419 | initMontage: function (montageRequire, applicationRequire, params) { |
413 | // If a module was specified in the config then we initialize it now | 420 | var Promise, defaultEventManager, application; |
414 | if (params.module) { | 421 | |
415 | applicationRequire.async(params.module) | 422 | montageRequire.async("core/promise").then(function(exports) { |
416 | .end(); | 423 | Promise = exports.Promise; |
417 | } else { | 424 | Promise.all([ |
418 | // otherwise we load the application | 425 | montageRequire.async("core/event/event-manager"), |
419 | montageRequire.async("ui/application", function(exports) { | 426 | montageRequire.async("core/deserializer") |
420 | montageRequire.async("core/event/event-manager", function(eventManagerExports) { | 427 | ]).then(function(exportsArray) { |
428 | // Load the event-manager | ||
429 | defaultEventManager = exportsArray[0].EventManager.create().initWithWindow(window); | ||
430 | |||
431 | // montageWillLoad is mostly for testing purposes | ||
432 | if (typeof global.montageWillLoad === "function") { | ||
433 | global.montageWillLoad(); | ||
434 | } | ||
421 | 435 | ||
422 | var defaultEventManager = eventManagerExports.defaultEventManager; | 436 | // Load the application |
423 | 437 | ||
424 | // montageWillLoad is mostly for testing purposes | 438 | var appProto = applicationRequire.packageDescription.applicationPrototype, |
425 | if (typeof global.montageWillLoad === "function") { | 439 | applicationDescription, appModulePromise; |
426 | global.montageWillLoad(); | 440 | if (appProto) { |
427 | } | 441 | applicationDescription = exportsArray[1].Deserializer.parseForModuleAndName(appProto); |
428 | exports.Application.load(function(application) { | 442 | appModulePromise = applicationRequire.async(applicationDescription.module); |
429 | window.document.application = application; | 443 | } else { |
430 | defaultEventManager.application = application; | 444 | appModulePromise = montageRequire.async("ui/application"); |
431 | application.eventManager = defaultEventManager; | 445 | } |
446 | |||
447 | if (typeof window !== "undefined") { | ||
448 | montageRequire.async("core/event/binding").end(); | ||
449 | } | ||
450 | |||
451 | appModulePromise.then(function(exports) { | ||
452 | application = exports[(applicationDescription ? applicationDescription.name : "Application")].create(); | ||
453 | window.document.application = application; | ||
454 | defaultEventManager.application = application; | ||
455 | application.eventManager = defaultEventManager; | ||
456 | application._load(applicationRequire, function() { | ||
457 | if (params.module) { | ||
458 | // If a module was specified in the config then we initialize it now | ||
459 | applicationRequire.async(params.module).end(); | ||
460 | } | ||
432 | }); | 461 | }); |
433 | }); | 462 | }).end(); |
434 | }); | ||
435 | } | ||
436 | } | ||
437 | 463 | ||
464 | }).end(); | ||
465 | |||
466 | }); | ||
467 | } | ||
438 | }; | 468 | }; |
439 | 469 | ||
440 | if (typeof window !== "undefined") { | 470 | if (typeof window !== "undefined") { |