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