Changed zouba directory heirarchy.
[ptas] / zouba / misc / rss / WRTKit / UI / UIElement.js
diff --git a/zouba/misc/rss/WRTKit/UI/UIElement.js b/zouba/misc/rss/WRTKit/UI/UIElement.js
new file mode 100644 (file)
index 0000000..c6d77b8
--- /dev/null
@@ -0,0 +1,114 @@
+/*\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 UIElement class is the base class for all user interface elements.\r
+\r
+// Constructor.\r
+function UIElement(id) {\r
+    if (id != UI_NO_INIT_ID) {\r
+        this.init(id);\r
+    }\r
+}\r
+\r
+// UI element identifier.\r
+UIElement.prototype.id = null;\r
+\r
+// Root HTML element in the UI element.\r
+UIElement.prototype.rootElement = null;\r
+\r
+// Initializer for UIElement.\r
+UIElement.prototype.init = function(id) {\r
+    uiLogger.debug("UIElement.init(" + id + ")");\r
+    \r
+    // copy identifier\r
+    this.id = id;\r
+    \r
+    // init event listener array\r
+    this.eventListeners = [];\r
+    \r
+    // create the root element\r
+    this.rootElement = document.createElement("div");\r
+    if (id != null) {\r
+        this.rootElement.id = id;\r
+    }\r
+}\r
+\r
+// Returns an array containing the current event listeners.\r
+UIElement.prototype.getEventListeners = function() {\r
+    return this.eventListeners;\r
+}\r
+\r
+// Adds an event listener.\r
+UIElement.prototype.addEventListener = function(eventType, listener) {\r
+    var listenerDef = { type: eventType, listener: listener };\r
+    this.eventListeners.push(listenerDef);\r
+}\r
+\r
+// Removes an event listener.\r
+UIElement.prototype.removeEventListener = function(eventType, listener) {\r
+    // iterate through current listeners and remove the specified\r
+    // listener when its found\r
+    for (var i = 0; i < this.eventListeners.length; i++) {\r
+        var listenerDef = this.eventListeners[i];\r
+        if ((listenerDef.type == eventType) &&\r
+                (listenerDef.listener == listener)) {\r
+            this.eventListeners.splice(i, 1);\r
+            return;\r
+        }\r
+    }\r
+}\r
+\r
+// Factory method for an event object where this object is the source object.\r
+UIElement.prototype.createEvent = function(type, value) {\r
+    return { source: this, type: type, value: value };\r
+}\r
+\r
+// Fires an event to all listeners.\r
+UIElement.prototype.fireEvent = function(event) {\r
+    // iterate through all event listeners and notify them of the event\r
+    for (var i = 0; i < this.eventListeners.length; i++) {\r
+        var listenerDef = this.eventListeners[i];\r
+        if (listenerDef.type == null || listenerDef.type == event.type) {\r
+            listenerDef.listener.call(this, event);\r
+        }\r
+    }\r
+}\r