aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/application.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /node_modules/montage/ui/application.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/application.js')
-rwxr-xr-xnode_modules/montage/ui/application.js248
1 files changed, 248 insertions, 0 deletions
diff --git a/node_modules/montage/ui/application.js b/node_modules/montage/ui/application.js
new file mode 100755
index 00000000..21449b8d
--- /dev/null
+++ b/node_modules/montage/ui/application.js
@@ -0,0 +1,248 @@
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
7/**
8 @module montage/ui/application
9 @require montage/core/event/event-manager
10 @require montage/ui/template
11*/
12
13var Montage = require("core/core").Montage,
14 EventManager = require("core/event/event-manager").EventManager,
15 Template = require("ui/template").Template,
16 Component = require("ui/component").Component,
17 Slot;
18
19 require("ui/dom");
20
21/**
22 This module defines the {@link module:ui/application.Application} prototype.
23 @module ui/application
24 @requires event/event-manager
25 @requires template
26 @requires ui/popup/popup
27 @requires ui/popup/alert
28 @requires ui/popup/confirm
29 @requires ui/loading
30 @requires ui/popup/growl
31 @requires ui/slot
32 */
33
34/**
35 The Application object is responsible for loading its component tree. TODO finish description
36 @class module:montage/ui/application.Application
37 @extends module:montage/core/core.Montage
38 */
39var Application = exports.Application = Montage.create(Montage, /** @lends montage/ui/application.Application# */ {
40
41 /**
42 Provides a reference to the Montage event manager used in the application.
43 @type {module:montage/core/event/event-manager.EventManager}
44 */
45 eventManager: {
46 value: null
47 },
48
49 /**
50 Returns the event manager for the specified window object.
51 @function
52 @param {Property} aWindow The browser window whose event manager object should be returned.
53 @returns aWindow.defaultEventMananger
54 */
55 eventManagerForWindow: {
56 value: function(aWindow) {
57 return aWindow.defaultEventMananger;
58 }
59 },
60
61 /**
62 Contains the window associated with the document.
63 @type {Property}
64 @default document.defaultView
65 */
66 focusWindow: {
67 value: document.defaultView
68 },
69
70 /**
71 An array of the windows associated with the application.
72 @type {Array}
73 @default {Array} []
74 */
75 attachedWindows: {
76 value: []
77 },
78
79 /**
80 Opens a URL in a new browser window, and registers the window with the Montage event manager.<br>
81 The document URL must be in the same domain as the calling script.
82 @function
83 @param {URL} url The URL to open in the new window.
84 @returns newWindow
85 @example
86 var app = document.application;
87 app.openWindow("docs/help.html");
88 */
89 openWindow: {
90 value: function(url) {
91 var newWindow = window.open(url);
92
93 // Make the required modules available to the new window
94 newWindow.require = require;
95 newWindow.document.application = this;
96
97 this.eventManager.registerWindow(newWindow);
98 this.attachedWindows.push(newWindow);
99 return newWindow;
100 }
101 },
102
103 /**
104 Registers an event listener on the application instance.
105 @function
106 @param {Property} type The event type to listen for.
107 @param {Object} listener A listener object that defines an event handler function, or a function to handle the event.
108 @param {Function} useCapture If <code>true</code>, the listener will only be notified during the event's capture phase.<br>
109 If <code>false</code> (the default) the listener will be notified during the event's bubble phase.
110 */
111 addEventListener: {
112 value: function(type, listener, useCapture) {
113 Object.getPrototypeOf(Application)["addEventListener"].call(this, type, listener, useCapture);
114 }
115 },
116
117 /**
118 Removes a previously registered event listener on the application instance.
119 @function
120 @param {Property} type The event type that was originally registered.
121 @param {Object} listener The listener object or function that was registered to handle the event.
122 @param {Function} useCapture TODO
123 */
124 removeEventListener: {
125 value: function(type, listener, useCapture) {
126 Object.getPrototypeOf(Application)["addEventListener"].call(this, type, listener, useCapture);
127 }
128 },
129
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>
141 The application delegate is notified of events during the application's life cycle.
142 @type {Object}
143 @default null
144 */
145 delegate: {
146 value: null
147 },
148
149 /**
150 @private
151 */
152 _template: {
153 value: null
154 },
155
156 /**
157 Description TODO
158 @function
159 @param {Function} callback A function to invoke after the method has completed.
160 */
161 load: {
162 value: function(callback) {
163 var template = Template.create().initWithDocument(window.document),
164 components, component,
165 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
184 self._template = template;
185 components = self.components || [];
186 for (var i = 0; (component = components[i]); i++) {
187 component.needsDraw = true;
188 }
189
190 if (callback) {
191 callback(self);
192 }
193 });
194 }
195 },
196
197 // @private
198 _alertPopup: {value: null, enumerable: false},
199 _confirmPopup: {value: null, enumerable: false},
200 _notifyPopup: {value: null, enumerable: false},
201
202
203 getPopupSlot: {
204 value: function(type, content, callback) {
205
206 var self = this;
207 require.async("ui/slot.reel/slot", function(exports) {
208 Slot = Slot || exports.Slot;
209
210 type = type || "custom";
211 // type = custom|alert|confirm
212 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
219 switch (type) {
220 case "alert":
221 zIndex = 9004;
222 break;
223 case "confirm":
224 zIndex = 9003;
225 break;
226 case "loading":
227 zIndex = 9002;