author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 18 Mar 2010 11:10:35 -0700 | |
changeset 275 | 12c2ea2194c7 |
parent 273 | b1f63c2c240c |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
11 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
* Contributors: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
13 |
* |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
14 |
* Description: |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
15 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
16 |
*/ |
73 | 17 |
|
18 |
/////////////////////////////////////////////////////////////////////////////// |
|
19 |
// The UIElement class is the base class for all user interface elements. |
|
20 |
||
21 |
// Constructor. |
|
22 |
function UIElement(id) { |
|
23 |
if (id != UI_NO_INIT_ID) { |
|
24 |
this.init(id); |
|
25 |
} |
|
26 |
} |
|
27 |
||
28 |
// UI element identifier. |
|
29 |
UIElement.prototype.id = null; |
|
30 |
||
31 |
// Root HTML element in the UI element. |
|
32 |
UIElement.prototype.rootElement = null; |
|
33 |
||
34 |
// Initializer for UIElement. |
|
35 |
UIElement.prototype.init = function(id) { |
|
36 |
uiLogger.debug("UIElement.init(" + id + ")"); |
|
37 |
||
38 |
// copy identifier |
|
39 |
this.id = id; |
|
40 |
||
41 |
// init event listener array |
|
42 |
this.eventListeners = []; |
|
43 |
||
44 |
// create the root element |
|
45 |
this.rootElement = document.createElement("div"); |
|
46 |
if (id != null) { |
|
47 |
this.rootElement.id = id; |
|
48 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
49 |
}; |
73 | 50 |
|
51 |
// Returns an array containing the current event listeners. |
|
52 |
UIElement.prototype.getEventListeners = function() { |
|
53 |
return this.eventListeners; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
54 |
}; |
73 | 55 |
|
56 |
// Adds an event listener. |
|
57 |
UIElement.prototype.addEventListener = function(eventType, listener) { |
|
58 |
var listenerDef = { type: eventType, listener: listener }; |
|
59 |
this.eventListeners.push(listenerDef); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
60 |
}; |
73 | 61 |
|
62 |
// Removes an event listener. |
|
63 |
UIElement.prototype.removeEventListener = function(eventType, listener) { |
|
64 |
// iterate through current listeners and remove the specified |
|
65 |
// listener when its found |
|
66 |
for (var i = 0; i < this.eventListeners.length; i++) { |
|
67 |
var listenerDef = this.eventListeners[i]; |
|
68 |
if ((listenerDef.type == eventType) && |
|
69 |
(listenerDef.listener == listener)) { |
|
70 |
this.eventListeners.splice(i, 1); |
|
71 |
return; |
|
72 |
} |
|
73 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
74 |
}; |
73 | 75 |
|
76 |
// Factory method for an event object where this object is the source object. |
|
77 |
UIElement.prototype.createEvent = function(type, value) { |
|
78 |
return { source: this, type: type, value: value }; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
79 |
}; |
73 | 80 |
|
81 |
// Fires an event to all listeners. |
|
82 |
UIElement.prototype.fireEvent = function(event) { |
|
83 |
// iterate through all event listeners and notify them of the event |
|
84 |
for (var i = 0; i < this.eventListeners.length; i++) { |
|
85 |
var listenerDef = this.eventListeners[i]; |
|
86 |
if (listenerDef.type == null || listenerDef.type == event.type) { |
|
87 |
listenerDef.listener.call(this, event); |
|
88 |
} |
|
89 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
90 |
}; |