+++ /dev/null
-/*\r
-© Copyright 2008 Nokia Corporation. All rights reserved.\r
-\r
-IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia\r
-Corporation (ÒNokiaÓ) in consideration of your agreement to the following terms. Your use, installation\r
-and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If\r
-you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example\r
-Widget files.\r
-\r
-In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia\r
-grants you a personal, non-exclusive license, under NokiaÕs copyrights in the WRTKit and Example\r
-Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,\r
-CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60\r
-Widgets.\r
-\r
-If you redistribute the WRTKit and Example files, you must retain this entire notice in all such\r
-redistributions of the WRTKit and Example files.\r
-\r
-You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products\r
-that include the WRTKit and Example files without the prior written explicit agreement with Nokia.\r
-Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by\r
-Nokia herein, including but not limited to any patent rights that may be infringed by your products that\r
-incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files\r
-may be incorporated.\r
-\r
-The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO\r
-WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED\r
-WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A\r
-PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION\r
-ALONE OR IN COMBINATION WITH YOUR PRODUCTS.\r
-\r
-IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR\r
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
-INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR\r
-DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY\r
-OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,\r
-EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-*/\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-// The UI manager manages a set of views and other user interface elements.\r
-\r
-// Constructor.\r
-function UIManager(viewParentElement, scrollbarParentElement, enableScrollBar, delayInit) { \r
- uiLogger.debug("UIManager(" + viewParentElement + ", " + scrollbarParentElement + ")");\r
- if (delayInit == null) {\r
- this.init(viewParentElement, enableScrollBar, scrollbarParentElement);\r
- }\r
-}\r
-\r
-// Parent element for views.\r
-UIManager.prototype.viewParentElement = null;\r
-\r
-// Parent element for scrollbar.\r
-UIManager.prototype.scrollbarParentElement = null;\r
-\r
-// The currently displayed view.\r
-UIManager.prototype.currentView = null;\r
-\r
-// Reference to the scrollbar.\r
-UIManager.prototype.scrollbar = null;\r
-\r
-// Current scroll Y position.\r
-UIManager.prototype.scrollY = -1;\r
-\r
-// Current viewport height.\r
-UIManager.prototype.viewportHeight = -1;\r
-\r
-// Current document height.\r
-UIManager.prototype.documentHeight = -1;\r
-\r
-// Timer identifier or null if no active timer.\r
-UIManager.prototype.timerId = null;\r
-\r
-// Interval for timer ticks for the UI manager timer (in milliseconds)\r
-UIManager.prototype.TIMER_INTERVAL = 250;\r
-\r
-// Reference to the notification popup used to displays notifications.\r
-UIManager.prototype.notificationPopup = null;\r
-\r
-// is scrollbar enabled\r
-UIManager.prototype.enableScrollBar = null;\r
-\r
-// init function\r
-UIManager.prototype.init = function(viewParentElement, enableScrollBar, scrollbarParentElement) {\r
- this.enableScrollBar = enableScrollBar;\r
- \r
- // parent element for views\r
- if (viewParentElement == null) {\r
- // create a parent for views\r
- this.viewParentElement = document.createElement("div");\r
- this.viewParentElement.className = "ViewContainer";\r
- document.body.appendChild(this.viewParentElement);\r
- }\r
- else {\r
- this.viewParentElement = viewParentElement;\r
- }\r
- \r
- // parent element for scrollbar\r
- if (enableScrollBar) {\r
- if (scrollbarParentElement == null) {\r
- // create a parent for the scrollbar\r
- this.scrollbarParentElement = document.createElement("div");\r
- this.scrollbarParentElement.className = "DocumentScrollbarContainer";\r
- document.body.appendChild(this.scrollbarParentElement);\r
- }\r
- else {\r
- this.scrollbarParentElement = scrollbarParentElement;\r
- }\r
- }\r
- \r
- // currently selected view\r
- this.currentView = null;\r
- \r
- // create the notification popup\r
- // the notification popup adds itself as a child element to the document body\r
- this.notificationPopup = new NotificationPopup();\r
- \r
- // create scrollbar\r
- if (enableScrollBar) {\r
- this.scrollbar = new Scrollbar(this.scrollbarParentElement);\r
- }\r
- \r
- // setup scrollbar tracking\r
- var self = this;\r
- this.startTimer();\r
- if (enableScrollBar) {\r
- window.addEventListener("resize", function(){\r
- self.updateScrollbar();\r
- }, false);\r
- window.addEventListener("scroll", function(){\r
- self.updateScrollbar();\r
- }, false);\r
- }\r
-}\r
-\r
-// Returns the current view.\r
-UIManager.prototype.getView = function() {\r
- return this.currentView;\r
-}\r
-\r
-// Switches to the specified view.\r
-UIManager.prototype.setView = function(view) {\r
- uiLogger.debug("View set to " + view.id);\r
- \r
- // remove the current view from the parent element\r
- if (this.currentView != null) {\r
- this.viewParentElement.removeChild(this.currentView.rootElement);\r
- }\r
- \r
- // reset scroll\r
- window.scrollTo(0, 0);\r
- \r
- // add the new view to the parent element\r
- if (view != null) {\r
- this.currentView = view;\r
- this.currentView.resetControlFocusStates();\r
- this.viewParentElement.appendChild(this.currentView.rootElement);\r
- }\r
- \r
- // update scrollbar\r
- if (this.enableScrollBar) {\r
- this.updateScrollbar();\r
- }\r
- \r
- // focus the first focusable control\r
- // a timer is used to prevent unwanted focus shift\r
- setTimeout(function() { view.focusFirstControl(); }, 1);\r
-}\r
-\r
-// Updates the scrollbar.\r
-UIManager.prototype.updateScrollbar = function() {\r
- if (this.enableScrollBar) {\r
- // get current viewport and document position and dimensions\r
- var scrollY = window.scrollY;\r
- var viewportHeight = window.innerHeight;\r
- var documentHeight = Math.max(document.documentElement.scrollHeight, document.height);\r
- \r
- // check if the scroll position or view has changed\r
- if (this.scrollY != scrollY ||\r
- this.viewportHeight != viewportHeight ||\r
- this.documentHeight != documentHeight) {\r
- // scroll position or view has changed\r
- this.scrollY = scrollY;\r
- this.viewportHeight = viewportHeight;\r
- this.documentHeight = documentHeight;\r
- \r
- // update the scrollbar\r
- this.scrollbar.update(scrollY, viewportHeight, documentHeight);\r
- uiLogger.debug("Scrollbar updated");\r
- }\r
- }\r
-}\r
-\r
-// Starts the view manager timer.\r
-UIManager.prototype.startTimer = function() {\r
- if (this.timerId == null) {\r
- uiLogger.debug("UIManager timer started");\r
- var self = this;\r
- // setup the timer\r
- this.timerId = setInterval(function() { self.onTimer(); }, this.TIMER_INTERVAL);\r
- } else {\r
- uiLogger.warn("UIManager timer already running");\r
- }\r
-}\r
-\r
-// Stops the view manager timer.\r
-UIManager.prototype.stopTimer = function() {\r
- if (this.timerId != null) {\r
- // stop the timer\r
- clearTimeout(this.timerId);\r
- this.timerId = null;\r
- } else {\r
- uiLogger.warn("UIManager timer already stopped");\r
- }\r
-}\r
-\r
-// Timer callback function.\r
-UIManager.prototype.onTimer = function() {\r
- if (this.enableScrollBar) {\r
- // make sure the scrollbar is up to date\r
- this.updateScrollbar();\r
- }\r
-}\r
-\r
-// Displays a notification.\r
-UIManager.prototype.showNotification = function(displayTime, type, text, progress) {\r
- uiLogger.debug("UIManager.showNotification(" + displayTime + ", " + type + ", " + text + ", " + progress + ")");\r
- // use the notification popup to show the notification\r
- this.notificationPopup.showNotification(displayTime, type, text, progress);\r
-}\r
-\r
-// Hides the currently displayed notification.\r
-UIManager.prototype.hideNotification = function() {\r
- uiLogger.debug("UIManager.hideNotification()");\r
- // hide the notification popup\r
- this.notificationPopup.hideNotification();\r
-}\r