author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 11 Mar 2010 13:41:06 -0800 | |
changeset 254 | 78b83bc27fa2 |
parent 211 | 7b148352159e |
child 273 | b1f63c2c240c |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
11 |
* Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
*/ |
73 | 13 |
/* |
211 | 14 |
© Copyright 2008 Nokia Corporation. All rights reserved. |
73 | 15 |
|
16 |
IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia |
|
211 | 17 |
Corporation ("Nokia") in consideration of your agreement to the following terms. Your use, installation |
73 | 18 |
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If |
19 |
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example |
|
20 |
Widget files. |
|
21 |
||
22 |
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia |
|
211 | 23 |
grants you a personal, non-exclusive license, under Nokia's copyrights in the WRTKit and Example |
73 | 24 |
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML, |
25 |
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60 |
|
26 |
Widgets. |
|
27 |
||
28 |
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such |
|
29 |
redistributions of the WRTKit and Example files. |
|
30 |
||
31 |
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products |
|
32 |
that include the WRTKit and Example files without the prior written explicit agreement with Nokia. |
|
33 |
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by |
|
34 |
Nokia herein, including but not limited to any patent rights that may be infringed by your products that |
|
35 |
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files |
|
36 |
may be incorporated. |
|
37 |
||
38 |
The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO |
|
39 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|
40 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
|
41 |
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION |
|
42 |
ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
|
43 |
||
44 |
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|
45 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
46 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
47 |
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR |
|
48 |
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY |
|
49 |
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, |
|
50 |
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
51 |
||
52 |
*/ |
|
53 |
||
54 |
/////////////////////////////////////////////////////////////////////////////// |
|
55 |
// The NotificationPopup class handles the display of notifications such as |
|
56 |
// warnings, information messages and progress indication. |
|
57 |
||
58 |
// Constructor. |
|
59 |
function NotificationPopup() { |
|
60 |
// create notification popup |
|
61 |
this.containerElement = document.createElement("div"); |
|
62 |
this.containerElement.className = "NotificationPopupContainer"; |
|
63 |
this.popupElement = document.createElement("div"); |
|
64 |
this.popupElement.className = "NotificationPopup"; |
|
65 |
this.typeIndicatorElement = document.createElement("div"); |
|
66 |
this.typeIndicatorElement.className = "NotificationPopupTypeIndicator"; |
|
67 |
this.textElement = document.createElement("div"); |
|
68 |
this.textElement.className = "NotificationPopupText"; |
|
69 |
this.progressBarElement = document.createElement("div"); |
|
70 |
this.progressBarElement.className = "NotificationPopupProgressBar"; |
|
71 |
||
72 |
// assemble popup |
|
73 |
this.popupElement.appendChild(this.typeIndicatorElement); |
|
74 |
this.popupElement.appendChild(this.textElement); |
|
75 |
this.popupElement.appendChild(this.progressBarElement); |
|
76 |
this.containerElement.appendChild(this.popupElement); |
|
77 |
||
78 |
// create progress bar image element and initialize it |
|
79 |
this.progressBarImageElement = document.createElement("img"); |
|
80 |
var self = this; |
|
81 |
this.progressBarImageElement.addEventListener("load", function() { self.progressBarImageLoadingCompleted(); }, false); |
|
82 |
this.progressBarImageElement.setAttribute("alt", ""); |
|
83 |
this.progressBarImageURL = this.getProgressBarImage(0); |
|
84 |
this.progressBarImageElement.src = this.progressBarImageURL; |
|
85 |
this.progressBarElement.appendChild(this.progressBarImageElement); |
|
86 |
||
87 |
// init the popup to be fully down |
|
88 |
this.popupElement.style.top = "100%"; |
|
89 |
||
90 |
// set default popup contents |
|
91 |
this.setPopupContents(null, null, null); |
|
92 |
} |
|
93 |
||
94 |
// Notification container element. |
|
95 |
NotificationPopup.prototype.containerElement = null; |
|
96 |
||
97 |
// Notification popup element. |
|
98 |
NotificationPopup.prototype.popupElement = null; |
|
99 |
||
100 |
// Type indicator element. |
|
101 |
NotificationPopup.prototype.typeIndicatorElement = null; |
|
102 |
||
103 |
// Notification text element. |
|
104 |
NotificationPopup.prototype.textElement = null; |
|
105 |
||
106 |
// Progress bar element. |
|
107 |
NotificationPopup.prototype.progressBarElement = null; |
|
108 |
||
109 |
// Progress bar image element. |
|
110 |
NotificationPopup.prototype.progressBarImageElement = null; |
|
111 |
||
112 |
// Progress bar image URL. |
|
113 |
NotificationPopup.prototype.progressBarImageURL = null; |
|
114 |
||
115 |
// Has the progress bar image been loaded? |
|
116 |
NotificationPopup.prototype.progressBarImageLoaded = false; |
|
117 |
||
118 |
// Flag that tracks whether we're in the middle of starting to |
|
119 |
// show a notification popup. |
|
120 |
NotificationPopup.prototype.processingShowNotification = false; |
|
121 |
||
122 |
// Notification popup position (0 = hidden, 1 = showing). |
|
123 |
NotificationPopup.prototype.popupPosition = 0; |
|
124 |
||
125 |
// Interval for timer ticks (in milliseconds) |
|
126 |
NotificationPopup.prototype.ANIM_TIMER_INTERVAL = 25; |
|
127 |
||
128 |
// Animation timer identifier or null if no active timer. |
|
129 |
NotificationPopup.prototype.animTimerId = null; |
|
130 |
||
131 |
// Time in milliseconds for the popup animation to complete |
|
132 |
NotificationPopup.prototype.ANIM_TIME = 300; |
|
133 |
||
134 |
// Flag that determines the behavior of showNotification(). If set to true |
|
135 |
// the popup will snap open when showNotification() is called instead of |
|
136 |
// animation. |
|
137 |
NotificationPopup.prototype.SHOW_SNAPS_OPEN = true; |
|
138 |
||
139 |
// Animation direction (0 = no movement, -1 hiding, +1 = showing). |
|
140 |
NotificationPopup.prototype.animDir = 0; |
|
141 |
||
142 |
// Auto-hide timer identifier or null if no active timer. |
|
143 |
NotificationPopup.prototype.autoHideTimerId = null; |
|
144 |
||
145 |
// The commanded display time. |
|
146 |
NotificationPopup.prototype.displayTime = -1; |
|
147 |
||
148 |
// Displays a notification. |
|
149 |
NotificationPopup.prototype.showNotification = function(displayTime, type, text, progress) { |
|
150 |
uiLogger.debug("NotificationPopup.showNotification(" + displayTime + ", " + type + ", " + text + ", " + progress + ")"); |
|
151 |
||
152 |
// mark that showNotification() has been called and that we are in |
|
153 |
// the middle of starting to show the notification popup |
|
154 |
this.processingShowNotification = true; |
|
155 |
||
156 |
// remember the display time |
|
157 |
this.displayTime = displayTime; |
|
158 |
||
159 |
// attach the popup to the document if not attached |
|
160 |
if (this.containerElement.parentNode == null) { |
|
161 |
document.body.appendChild(this.containerElement); |
|
162 |
uiLogger.debug("Notification popup attached to document"); |
|
163 |
} |
|
164 |
||
165 |
// set popup contents and update style |
|
166 |
this.setPopupContents(type, text, progress); |
|
167 |
||
168 |
// if the progress image is loaded then we can complete the showing |
|
169 |
// of the notification popup immediately - otherwise the image loaded |
|
170 |
// allback will complete the process. |
|
171 |
if (this.progressBarImageLoaded) { |
|
172 |
this.completeShowNotification(); |
|
173 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
174 |
}; |
73 | 175 |
|
176 |
// Completes displaying of a notification. |
|
177 |
// Note: Used internally - don't call this directly. |
|
178 |
NotificationPopup.prototype.completeShowNotification = function() { |
|
179 |
uiLogger.debug("NotificationPopup.completeShowNotification()"); |
|
180 |
||
181 |
// animation direction is +1 for showing the popup |
|
182 |
if (this.popupPosition != 1) { |
|
183 |
if (this.SHOW_SNAPS_OPEN) { |
|
184 |
if (this.popupPosition == 0) { |
|
185 |
this.popupPosition = 1; |
|
186 |
} |
|
187 |
} |
|
188 |
this.animatePopup(1); |
|
189 |
} |
|
190 |
||
191 |
// setup auto hiding if a display time is specified |
|
192 |
if (this.displayTime > 0) { |
|
193 |
// stop any existing timer |
|
194 |
if (this.autoHideTimerId != null) { |
|
195 |
clearTimeout(this.autoHideTimerId); |
|
196 |
uiLogger.debug("Auto hide timer stopped"); |
|
197 |
} |
|
198 |
// set timer to hide notification |
|
199 |
var self = this; |
|
200 |
this.autoHideTimerId = setTimeout(function() { |
|
201 |
if (self.displayTime > 0) { |
|
202 |
self.hideNotification(); |
|
203 |
} |
|
204 |
}, this.ANIM_TIME + this.displayTime); |
|
205 |
uiLogger.debug("Auto hide timer started"); |
|
206 |
} |
|
207 |
||
208 |
// mark us as no longer processing a show notification call |
|
209 |
this.processingShowNotification = false; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
210 |
}; |
73 | 211 |
|
212 |
// Hides the currently displayed notification. |
|
213 |
NotificationPopup.prototype.hideNotification = function() { |
|
214 |
uiLogger.debug("NotificationPopup.hideNotification()"); |
|
215 |
// mark us as no longer processing a show notification call |
|
216 |
this.processingShowNotification = false; |
|
217 |
||
218 |
// animation direction is -1 for hiding the popup |
|
219 |
if (this.popupPosition != 0) { |
|
220 |
this.animatePopup(-1); |
|
221 |
} |
|
222 |
||
223 |
// stop auto hide timer if one is set |
|
224 |
if (this.autoHideTimerId != null) { |
|
225 |
clearTimeout(this.autoHideTimerId); |
|
226 |
this.autoHideTimerId = null; |
|
227 |
uiLogger.debug("Auto hide timer stopped"); |
|
228 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
229 |
}; |
73 | 230 |
|
231 |
// Starts animation of the popup (1 to show, -1 to hide). |
|
232 |
NotificationPopup.prototype.animatePopup = function(direction) { |
|
233 |
uiLogger.debug("NotificationPopup.animatePopup(" + direction + ")"); |
|
234 |
// set the direction and star the animation timer |
|
235 |
this.animDir = direction; |
|
236 |
if (this.animTimerId == null) { |
|
237 |
var self = this; |
|
238 |
this.animTimerId = setInterval(function() { self.animate(); }, this.ANIM_TIMER_INTERVAL); |
|
239 |
uiLogger.debug("Notification popup animation started"); |
|
240 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
241 |
}; |
73 | 242 |
|
243 |
// Callback for animation timer. |
|
244 |
NotificationPopup.prototype.animate = function() { |
|
245 |
// calculate new popup position and clamp |
|
246 |
var animStep = (this.ANIM_TIMER_INTERVAL / this.ANIM_TIME) * this.animDir; |
|
247 |
var newPos = this.popupPosition + animStep; |
|
248 |
if (newPos < 0) { |
|
249 |
newPos = 0; |
|
250 |
} else if (newPos > 1) { |
|
251 |
newPos = 1; |
|
252 |
} |
|
253 |
||
254 |
// set the new position to the popup element |
|
255 |
this.popupPosition = newPos; |
|
256 |
this.popupElement.style.top = (100 - Math.round(this.popupPosition * 100)) + "%"; |
|
257 |
||
258 |
// have we reached the end of the animation? |
|
259 |
if (newPos == 0 || newPos == 1) { |
|
260 |
// reset animation direction |
|
261 |
this.animDir = 0; |
|
262 |
||
263 |
// remove the popup from the body if its hidden |
|
264 |
if (newPos == 0) { |
|
265 |
document.body.removeChild(this.containerElement); |
|
266 |
uiLogger.debug("Notification popup detached from document"); |
|
267 |
} |
|
268 |
||
269 |
// stop timer |
|
270 |
clearTimeout(this.animTimerId); |
|
271 |
this.animTimerId = null; |
|
272 |
uiLogger.debug("Notification popup animation stopped"); |
|
273 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
274 |
}; |
73 | 275 |
|
276 |
// Returns a URL for the progress bar image to use for the specified progress. |
|
277 |
NotificationPopup.prototype.getProgressBarImage = function(progress) { |
|
278 |
// path for progress bar images |
|
279 |
var progressBarImagePath = "WRTKit/Resources/"; |
|
280 |
||
281 |
if (progress < 0) { |
|
282 |
// unknown progress |
|
283 |
return progressBarImagePath + "ProgressBarUnknown.gif"; |
|
284 |
} else { |
|
285 |
// known progress (should be between 0 and 1) |
|
286 |
var progPct = Math.round(progress * 10) * 10; |
|
287 |
if (progPct < 0) { |
|
288 |
progPct = 0; |
|
289 |
} else if (progPct > 100) { |
|
290 |
progPct = 100; |
|
291 |
} |
|
292 |
return progressBarImagePath + "ProgressBar" + progPct + ".png"; |
|
293 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
294 |
}; |
73 | 295 |
|
296 |
// Sets the contents of the popup. |
|
297 |
NotificationPopup.prototype.setPopupContents = function(type, text, progress) { |
|
298 |
uiLogger.debug("NotificationPopup.setPopupContents(" + type + ", " + text + ", " + progress + ")"); |
|
299 |
||
300 |
// figure out notification type style name |
|
301 |
var typeName = (type == null) ? "none" : type.toLowerCase(); |
|
302 |
typeName = typeName.charAt(0).toUpperCase() + typeName.substring(1); |
|
303 |
||
304 |
// set type element class names |
|
305 |
this.typeIndicatorElement.className = "NotificationPopupTypeIndicator NotificationPopupTypeIndicator" + typeName; |
|
306 |
||
307 |
// set notification text |
|
308 |
this.textElement.innerHTML = (text == null) ? "" : text; |
|
309 |
||
310 |
// set progress |
|
311 |
this.progressBarElement.style.display = (progress == null) ? "none" : "block"; |
|
312 |
if (progress != null) { |
|
313 |
var imgURL = this.getProgressBarImage(progress); |
|
314 |
if (imgURL != this.progressBarImageURL) { |
|
315 |
// load new image |
|
316 |
this.progressBarImageLoaded = false; |
|
317 |
this.progressBarImageURL = imgURL; |
|
318 |
this.progressBarImageElement.src = imgURL; |
|
319 |
} else { |
|
320 |
// the correct image is already loaded |
|
321 |
this.progressBarImageLoaded = true; |
|
322 |
} |
|
323 |
} else { |
|
324 |
// there is no progress bar so there is no need |
|
325 |
// to load any progress bar image |
|
326 |
this.progressBarImageLoaded = true; |
|
327 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
328 |
}; |
73 | 329 |
|
330 |
// Callback for notifying the object that its progress bar image completed loading. |
|
331 |
NotificationPopup.prototype.progressBarImageLoadingCompleted = function() { |
|
332 |
uiLogger.debug("NotificationPopup.progressBarImageLoadingCompleted()"); |
|
333 |
||
334 |
// mark the progress bar image as loaded |
|
335 |
this.progressBarImageLoaded = true; |
|
336 |
||
337 |
// complete the process of displaying the notification popup |
|
338 |
// if it has been commanded but not yet completed |
|
339 |
if (this.processingShowNotification) { |
|
340 |
this.completeShowNotification(); |
|
341 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
342 |
}; |