diff options
Diffstat (limited to 'node_modules/montage/ui/application.js')
-rwxr-xr-x | node_modules/montage/ui/application.js | 128 |
1 files changed, 73 insertions, 55 deletions
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 | |||
@@ -128,15 +128,6 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
128 | }, | 128 | }, |
129 | 129 | ||
130 | /** | 130 | /** |
131 | A collection of components that the application creates at startup. | ||
132 | @type {Object} | ||
133 | @default null | ||
134 | */ | ||
135 | components: { | ||
136 | value: null | ||
137 | }, | ||
138 | |||
139 | /** | ||
140 | The application's delegate object.<br> | 131 | The application's delegate object.<br> |
141 | The application delegate is notified of events during the application's life cycle. | 132 | The application delegate is notified of events during the application's life cycle. |
142 | @type {Object} | 133 | @type {Object} |
@@ -147,13 +138,6 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
147 | }, | 138 | }, |
148 | 139 | ||
149 | /** | 140 | /** |
150 | @private | ||
151 | */ | ||
152 | _template: { | ||
153 | value: null | ||
154 | }, | ||
155 | |||
156 | /** | ||
157 | Description TODO | 141 | Description TODO |
158 | @function | 142 | @function |
159 | @param {Function} callback A function to invoke after the method has completed. | 143 | @param {Function} callback A function to invoke after the method has completed. |
@@ -161,32 +145,16 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
161 | load: { | 145 | load: { |
162 | value: function(callback) { | 146 | value: function(callback) { |
163 | var template = Template.create().initWithDocument(window.document), | 147 | var template = Template.create().initWithDocument(window.document), |
164 | components, component, | 148 | component, |
165 | self = this, | 149 | self = this; |
166 | isInstance = Application.isPrototypeOf(this); | ||
167 | |||
168 | template.instantiateWithOwnerAndDocument(isInstance ? this : null, window.document, function(rootObject) { | ||
169 | // The states we need to take care of: | ||
170 | // 1) Static Application.load() called and the template root object is an application | ||
171 | // 2) Static Application.load() called and the template root object is NOT an application | ||
172 | // 3) Instance application.load() called and the template root object is an application | ||
173 | // 4) Instance application.load() called and the template root object is NOT an application | ||
174 | if (rootObject !== self) { // Need to setup the application object | ||
175 | if (Application.isPrototypeOf(rootObject)) { // the root object is an application already, use it | ||
176 | self = rootObject; | ||
177 | } 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 | ||
178 | self = isInstance ? self : Application.create(); | ||
179 | self.components = [rootObject]; | ||
180 | require("ui/component").__root__.needsDraw = true; | ||
181 | } | ||
182 | } | ||
183 | 150 | ||
184 | self._template = template; | 151 | self = Application.isPrototypeOf(self) ? self : Application.create(); |
185 | components = self.components || []; | ||
186 | for (var i = 0; (component = components[i]); i++) { | ||
187 | component.needsDraw = true; | ||
188 | } | ||
189 | 152 | ||
153 | // assign to the exports so that it is available in the deserialization of the template | ||
154 | exports.application = self; | ||
155 | |||
156 | template.instantiateWithOwnerAndDocument(null, window.document, function() { | ||
157 | require("ui/component").__root__.needsDraw = true; | ||
190 | if (callback) { | 158 | if (callback) { |
191 | callback(self); | 159 | callback(self); |
192 | } | 160 | } |
@@ -198,7 +166,22 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
198 | _alertPopup: {value: null, enumerable: false}, | 166 | _alertPopup: {value: null, enumerable: false}, |
199 | _confirmPopup: {value: null, enumerable: false}, | 167 | _confirmPopup: {value: null, enumerable: false}, |
200 | _notifyPopup: {value: null, enumerable: false}, | 168 | _notifyPopup: {value: null, enumerable: false}, |
169 | _zIndex: {value: null}, | ||
170 | |||
171 | _isSystemPopup: {value: function(type) { | ||
172 | return (type === 'alert' || type === 'confirm' || type === 'loading'); | ||
173 | }}, | ||
201 | 174 | ||
175 | _createPopupSlot: {value: function(zIndex) { | ||
176 | var slotEl = document.createElement('div'); | ||
177 | document.body.appendChild(slotEl); | ||
178 | slotEl.style['z-index'] = zIndex; | ||
179 | slotEl.style.position = 'absolute'; | ||
180 | |||
181 | var popupSlot = Slot.create(); | ||
182 | popupSlot.element = slotEl; | ||
183 | return popupSlot; | ||
184 | }}, | ||
202 | 185 | ||
203 | getPopupSlot: { | 186 | getPopupSlot: { |
204 | value: function(type, content, callback) { | 187 | value: function(type, content, callback) { |
@@ -206,16 +189,11 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
206 | var self = this; | 189 | var self = this; |
207 | require.async("ui/slot.reel/slot", function(exports) { | 190 | require.async("ui/slot.reel/slot", function(exports) { |
208 | Slot = Slot || exports.Slot; | 191 | Slot = Slot || exports.Slot; |
209 | |||
210 | type = type || "custom"; | 192 | type = type || "custom"; |
211 | // type = custom|alert|confirm | 193 | var isSystemPopup = self._isSystemPopup(type), zIndex, slotEl, popupSlot; |
212 | self.popupSlots = self.popupSlots || {}; | 194 | self.popupSlots = self.popupSlots || {}; |
213 | var popupSlot = self.popupSlots[type]; | ||
214 | // create a slot for this type of popup | ||
215 | if (!popupSlot) { | ||
216 | var slotEl = document.createElement('div'), zIndex; | ||
217 | slotEl.style.position = 'absolute'; | ||
218 | 195 | ||
196 | if(isSystemPopup) { | ||
219 | switch (type) { | 197 | switch (type) { |
220 | case "alert": | 198 | case "alert": |
221 | zIndex = 9004; | 199 | zIndex = 9004; |
@@ -226,16 +204,24 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
226 | case "loading": | 204 | case "loading": |
227 | zIndex = 9002; | 205 | zIndex = 9002; |
228 | break; | 206 | break; |
229 | default: | ||
230 | zIndex = 9001; | ||
231 | break; | ||
232 | } | 207 | } |
233 | slotEl.style['z-index'] = zIndex; | 208 | } else { |
209 | // custom popup | ||
210 | if(!self._zIndex) { | ||
211 | self._zIndex = 7000; | ||
212 | } else { | ||
213 | self._zIndex = self._zIndex + 1; | ||
214 | } | ||
215 | zIndex = self._zIndex; | ||
216 | } | ||
234 | 217 | ||
235 | document.body.appendChild(slotEl); | 218 | popupSlot = self.popupSlots[type]; |
236 | popupSlot = Slot.create(); | 219 | if (!popupSlot) { |
237 | popupSlot.element = slotEl; | 220 | popupSlot = self.popupSlots[type] = self._createPopupSlot(zIndex); |
238 | self.popupSlots[type] = popupSlot; | 221 | } |
222 | // use the new zIndex for custom popup | ||
223 | if(!isSystemPopup) { | ||
224 | popupSlot.element.style['z-index'] = zIndex; | ||
239 | } | 225 | } |
240 | 226 | ||
241 | popupSlot.content = content; | 227 | popupSlot.content = content; |
@@ -243,6 +229,38 @@ var Application = exports.Application = Montage.create(Montage, /** @lends monta | |||
243 | 229 | ||
244 | }); | 230 | }); |
245 | } | 231 | } |
232 | }, | ||
233 | |||
234 | returnPopupSlot: {value: function(type) { | ||
235 | var self = this; | ||
236 | if(self.popupSlots && self.popupSlots[type]) { | ||
237 | var popupSlot = self.popupSlots[type]; | ||
238 | popupSlot.content = null; | ||
239 | // is there a way to remove the Slot | ||
240 | // OR should we remove the slotEl from the DOM to clean up ? | ||
241 | } | ||
242 | |||
243 | }}, | ||
244 | |||
245 | // private | ||
246 | _getActivePopupSlots: { | ||
247 | value: function() { | ||
248 | var arr = []; | ||
249 | if(this.popupSlots) { | ||
250 | var keys = Object.keys(this.popupSlots); | ||
251 | if(keys && keys.length > 0) { | ||
252 | var i=0, len = keys.length, slot; | ||
253 | for(i=0; i< len; i++) { | ||
254 | slot = this.popupSlots[keys[i]]; | ||
255 | if(slot && slot.content !== null) { | ||
256 | arr.push(slot); | ||
257 | } | ||
258 | |||
259 | } | ||
260 | } | ||
261 | } | ||
262 | return arr; | ||
263 | } | ||
246 | } | 264 | } |
247 | 265 | ||
248 | }); | 266 | }); |