aboutsummaryrefslogtreecommitdiff
path: root/js/components/combobox.reel
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/components/combobox.reel
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/components/combobox.reel')
-rw-r--r--js/components/combobox.reel/combobox.html24
-rw-r--r--js/components/combobox.reel/combobox.js140
2 files changed, 164 insertions, 0 deletions
diff --git a/js/components/combobox.reel/combobox.html b/js/components/combobox.reel/combobox.html
new file mode 100644
index 00000000..d78cc9c1
--- /dev/null
+++ b/js/components/combobox.reel/combobox.html
@@ -0,0 +1,24 @@
1<!DOCTYPE html>
2<!-- <copyright>
3 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
4 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
5 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
6 </copyright> -->
7<html>
8<head>
9 <script type="text/montage-serialization">
10 {
11 "owner": {
12 "module": "js/components/combobox.reel",
13 "name": "Combobox",
14 "properties": {
15 "element": {"#": "cb_comp"}
16 }
17 }
18 }
19 </script>
20</head>
21<body>
22 <select id="cb_comp" class="nj-skinned" />
23</body>
24</html> \ No newline at end of file
diff --git a/js/components/combobox.reel/combobox.js b/js/components/combobox.reel/combobox.js
new file mode 100644
index 00000000..f262bb06
--- /dev/null
+++ b/js/components/combobox.reel/combobox.js
@@ -0,0 +1,140 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage;
8var Component = require("montage/ui/component").Component;
9
10exports.Combobox = Montage.create(Component, {
11
12 _valueSyncedWithInputField: {
13 enumerable: false,
14 value: false
15 },
16
17 _wasSetByCode: {
18 enumerable: false,
19 value: true
20 },
21
22 labelField: {
23 value: null
24 },
25
26 labelFunction: {
27 value: null
28 },
29
30 _items: {
31 value: []
32 },
33
34 items: {
35 enumerable: true,
36 serializable: true,
37 get: function() {
38 return this._items;
39 },
40 set: function(value) {
41 if (value !== this._items)
42 {
43 this._items = value;
44 this._valueSyncedWithInputField = false;
45 this.needsDraw = true;
46 }
47 }
48 },
49
50 _value: {
51 enumerable: false,
52 value: null
53 },
54
55 value: {
56 enumerable: true,
57 serializable: true,
58 get: function() {
59 return this._value;
60 },
61 set: function(value) {
62 if (value !== this._value)
63 {
64 this._value = value;
65 this.needsDraw = true;
66
67 var e = document.createEvent("CustomEvent");
68 e.initEvent("change", true, true);
69 e.type = "change";
70 e._wasSetByCode = this._wasSetByCode;
71 e.value = this._value;
72 this.dispatchEvent(e);
73
74 this._wasSetByCode = false;
75 }
76 }
77 },
78
79 handleChange:
80 {
81 value:function(event)
82 {
83 this._valueSyncedWithInputField = true;
84 this._wasSetByCode = false;
85 this.value = this.element.value;
86 this.needsDraw = true;
87 }
88 },
89
90 willDraw: {
91 value: function() {
92 if(!this._valueSyncedWithInputField)
93 {
94 this.element.innerHTML = "";
95
96 var optionItem = document.createElement("option");
97 var items = this._items;
98 var len = items.length;
99
100 var i;
101 for (i = 0; i < len; i++)
102 {
103 var current = items[i];
104 optionItem = document.createElement("option");
105 optionItem.value = current;
106 if(this.labelFunction)
107 {
108 optionItem.innerText = this.labelFunction(current);
109 }
110 else if(this.labelField)
111 {
112 optionItem.innerText = current[this.labelField];
113 }
114 else
115 {
116 optionItem.innerText = current;
117 }
118 this.element.appendChild(optionItem);
119 }
120 }
121 }
122 },
123
124 draw: {
125 value: function() {
126 if(!this._valueSyncedWithInputField)
127 {
128 this.element.value = this._value;
129 }
130 this._valueSyncedWithInputField = false;
131 }
132 },
133
134 prepareForDraw: {
135 value: function() {
136 this.element.addEventListener("change", this, false);
137 }
138 }
139
140}); \ No newline at end of file