From a3024011a91d3941f81481dd4d600e9684eb0fd4 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 2 Feb 2012 00:11:51 -0800 Subject: upgrading to Montage v0.6 Signed-off-by: Valerio Virgillito --- node_modules/montage/ui/application.js | 128 +++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 55 deletions(-) (limited to 'node_modules/montage/ui/application.js') diff --git a/node_modules/montage/ui/application.js b/node_modules/montage/ui/application.js index 21449b8d..c7b3dc73 100755 --- a/node_modules/montage/ui/application.js +++ b/node_modules/montage/ui/application.js @@ -127,15 +127,6 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta } }, - /** - A collection of components that the application creates at startup. - @type {Object} - @default null - */ - components: { - value: null - }, - /** The application's delegate object.
The application delegate is notified of events during the application's life cycle. @@ -146,13 +137,6 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta value: null }, - /** - @private - */ - _template: { - value: null - }, - /** Description TODO @function @@ -161,32 +145,16 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta load: { value: function(callback) { var template = Template.create().initWithDocument(window.document), - components, component, - self = this, - isInstance = Application.isPrototypeOf(this); - - template.instantiateWithOwnerAndDocument(isInstance ? this : null, window.document, function(rootObject) { - // The states we need to take care of: - // 1) Static Application.load() called and the template root object is an application - // 2) Static Application.load() called and the template root object is NOT an application - // 3) Instance application.load() called and the template root object is an application - // 4) Instance application.load() called and the template root object is NOT an application - if (rootObject !== self) { // Need to setup the application object - if (Application.isPrototypeOf(rootObject)) { // the root object is an application already, use it - self = rootObject; - } else { // the root object is something else, need to create an application to "wrap" it or use "this" in case of an instance (vs static) call - self = isInstance ? self : Application.create(); - self.components = [rootObject]; - require("ui/component").__root__.needsDraw = true; - } - } + component, + self = this; - self._template = template; - components = self.components || []; - for (var i = 0; (component = components[i]); i++) { - component.needsDraw = true; - } + self = Application.isPrototypeOf(self) ? self : Application.create(); + // assign to the exports so that it is available in the deserialization of the template + exports.application = self; + + template.instantiateWithOwnerAndDocument(null, window.document, function() { + require("ui/component").__root__.needsDraw = true; if (callback) { callback(self); } @@ -198,7 +166,22 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta _alertPopup: {value: null, enumerable: false}, _confirmPopup: {value: null, enumerable: false}, _notifyPopup: {value: null, enumerable: false}, + _zIndex: {value: null}, + + _isSystemPopup: {value: function(type) { + return (type === 'alert' || type === 'confirm' || type === 'loading'); + }}, + _createPopupSlot: {value: function(zIndex) { + var slotEl = document.createElement('div'); + document.body.appendChild(slotEl); + slotEl.style['z-index'] = zIndex; + slotEl.style.position = 'absolute'; + + var popupSlot = Slot.create(); + popupSlot.element = slotEl; + return popupSlot; + }}, getPopupSlot: { value: function(type, content, callback) { @@ -206,16 +189,11 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta var self = this; require.async("ui/slot.reel/slot", function(exports) { Slot = Slot || exports.Slot; - type = type || "custom"; - // type = custom|alert|confirm + var isSystemPopup = self._isSystemPopup(type), zIndex, slotEl, popupSlot; self.popupSlots = self.popupSlots || {}; - var popupSlot = self.popupSlots[type]; - // create a slot for this type of popup - if (!popupSlot) { - var slotEl = document.createElement('div'), zIndex; - slotEl.style.position = 'absolute'; + if(isSystemPopup) { switch (type) { case "alert": zIndex = 9004; @@ -226,16 +204,24 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta case "loading": zIndex = 9002; break; - default: - zIndex = 9001; - break; } - slotEl.style['z-index'] = zIndex; + } else { + // custom popup + if(!self._zIndex) { + self._zIndex = 7000; + } else { + self._zIndex = self._zIndex + 1; + } + zIndex = self._zIndex; + } - document.body.appendChild(slotEl); - popupSlot = Slot.create(); - popupSlot.element = slotEl; - self.popupSlots[type] = popupSlot; + popupSlot = self.popupSlots[type]; + if (!popupSlot) { + popupSlot = self.popupSlots[type] = self._createPopupSlot(zIndex); + } + // use the new zIndex for custom popup + if(!isSystemPopup) { + popupSlot.element.style['z-index'] = zIndex; } popupSlot.content = content; @@ -243,6 +229,38 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta }); } + }, + + returnPopupSlot: {value: function(type) { + var self = this; + if(self.popupSlots && self.popupSlots[type]) { + var popupSlot = self.popupSlots[type]; + popupSlot.content = null; + // is there a way to remove the Slot + // OR should we remove the slotEl from the DOM to clean up ? + } + + }}, + + // private + _getActivePopupSlots: { + value: function() { + var arr = []; + if(this.popupSlots) { + var keys = Object.keys(this.popupSlots); + if(keys && keys.length > 0) { + var i=0, len = keys.length, slot; + for(i=0; i< len; i++) { + slot = this.popupSlots[keys[i]]; + if(slot && slot.content !== null) { + arr.push(slot); + } + + } + } + } + return arr; + } } }); -- cgit v1.2.3