aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/ui/application.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/ui/application.js')
-rwxr-xr-xnode_modules/montage-user/ui/application.js216
1 files changed, 216 insertions, 0 deletions
diff --git a/node_modules/montage-user/ui/application.js b/node_modules/montage-user/ui/application.js
new file mode 100755
index 00000000..8c3be76b
--- /dev/null
+++ b/node_modules/montage-user/ui/application.js
@@ -0,0 +1,216 @@
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 The application's delegate object.<br>
132 The application delegate is notified of events during the application's life cycle.
133 @type {Object}
134 @default null
135 */
136 delegate: {
137 value: null
138 },
139
140 /**
141 Description TODO
142 @function
143 @param {Function} callback A function to invoke after the method has completed.
144 */
145 load: {
146 value: function(callback) {
147 var template = Template.create().initWithDocument(window.document),
148 component,
149 self = this;
150
151 self = Application.isPrototypeOf(self) ? self : Application.create();
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;
158 if (callback) {
159 callback(self);
160 }
161 });
162 }
163 },
164
165 // @private
166 _alertPopup: {value: null, enumerable: false},
167 _confirmPopup: {value: null, enumerable: false},
168 _notifyPopup: {value: null, enumerable: false},
169
170
171 getPopupSlot: {
172 value: function(type, content, callback) {
173
174 var self = this;
175 require.async("ui/slot.reel/slot", function(exports) {
176 Slot = Slot || exports.Slot;
177
178 type = type || "custom";
179 // type = custom|alert|confirm
180 self.popupSlots = self.popupSlots || {};
181 var popupSlot = self.popupSlots[type];
182 // create a slot for this type of popup
183 if (!popupSlot) {
184 var slotEl = document.createElement('div'), zIndex;
185 slotEl.style.position = 'absolute';
186
187 switch (type) {
188 case "alert":
189 zIndex = 9004;
190 break;
191 case "confirm":
192 zIndex = 9003;
193 break;
194 case "loading":
195 zIndex = 9002;
196 break;
197 default:
198 zIndex = 9001;
199 break;
200 }
201 slotEl.style['z-index'] = zIndex;
202
203 document.body.appendChild(slotEl);
204 popupSlot = Slot.create();
205 popupSlot.element = slotEl;
206 self.popupSlots[type] = popupSlot;
207 }
208
209 popupSlot.content = content;
210 callback.call(this, popupSlot);
211
212 });
213 }
214 }
215
216});