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