aboutsummaryrefslogtreecommitdiff
path: root/js/components/radio.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/radio.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/radio.reel')
-rw-r--r--js/components/radio.reel/radio.html24
-rw-r--r--js/components/radio.reel/radio.js178
2 files changed, 202 insertions, 0 deletions
diff --git a/js/components/radio.reel/radio.html b/js/components/radio.reel/radio.html
new file mode 100644
index 00000000..3736ded3
--- /dev/null
+++ b/js/components/radio.reel/radio.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/radio.reel",
13 "name": "Radio",
14 "properties": {
15 "element": {"#": "ch_comp"}
16 }
17 }
18 }
19 </script>
20</head>
21<body>
22 <input id="ch_comp" class="nj-skinned" type="radio">
23</body>
24</html> \ No newline at end of file
diff --git a/js/components/radio.reel/radio.js b/js/components/radio.reel/radio.js
new file mode 100644
index 00000000..954da3c4
--- /dev/null
+++ b/js/components/radio.reel/radio.js
@@ -0,0 +1,178 @@
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.RadioGroup = Montage.create(Component, {
11 radios: {
12 value: []
13 },
14
15 _selectedItem: {
16 value: null
17 },
18
19 selectedIndex: {
20 value: null
21 },
22
23 selectedItem: {
24 enumerable: true,
25 serializable: true,
26 get: function() {
27 return this._value;
28 },
29 set: function(value) {
30 var e,
31 i = 0,
32 len = this.radios.length;
33
34 for(i=0; i < len; i++)
35 {
36 if(this.radios[i] === value)
37 {
38 this.selectedIndex = i;
39 this._selectedItem = value;
40
41 e = document.createEvent("CustomEvent");
42 e.initEvent("change", true, true);
43 e.type = "change";
44 e._wasSetByCode = this._wasSetByCode;
45 e.selectedIndex = i;
46 e.selectedItem = value;
47 this.dispatchEvent(e);
48
49 this._wasSetByCode = false;
50
51 return;
52 }
53 }
54 }
55 },
56
57 name: {
58 value: "RadioGroup0"
59 },
60
61 addRadio:
62 {
63 value:function(radio)
64 {
65 radio.element.setAttribute("name", this.name);
66 radio.addEventListener("change", this, false);
67 this.radios.push(radio);
68 }
69 },
70
71 _wasSetByCode: {
72 enumerable: false,
73 value: true
74 },
75
76 handleChange:
77 {
78 value:function(event)
79 {
80 this._wasSetByCode = event._event._wasSetByCode;
81 this.selectedItem = event._event.value;
82 }
83 }
84
85});
86
87exports.Radio = Montage.create(Component, {
88
89 _valueSyncedWithInputField: {
90 enumerable: false,
91 value: false
92 },
93
94 _wasSetByCode: {
95 enumerable: false,
96 value: true
97 },
98
99 prependLabel: {
100 value: false
101 },
102
103 label: {
104 value: null
105 },
106
107 _checked: {
108 enumerable: false,
109 value: false
110 },
111
112 group: {
113 value: null
114 },
115
116 checked: {
117 enumerable: true,
118 serializable: true,
119 get: function() {
120 return this._checked;
121 },
122 set: function(value) {
123 this._checked = true;
124 this.needsDraw = true;
125
126 var e = document.createEvent("CustomEvent");
127 e.initEvent("change", true, true);
128 e.type = "change";
129 e._wasSetByCode = this._wasSetByCode;
130 e.value = this;
131 this.dispatchEvent(e);
132
133 this._wasSetByCode = false;
134 }
135 },
136
137 handleChange:
138 {
139 value:function(event)
140 {
141 this._valueSyncedWithInputField = true;
142 this._wasSetByCode = false;
143 this.checked = this.element.checked;
144 }
145 },
146 handleClick: {
147 value: function() {
148 this._wasSetByCode = false;
149 this.checked = !this.element.checked;
150 }
151 },
152
153 draw: {
154 value: function() {
155 if(!this._valueSyncedWithInputField)
156 {
157 this.element.checked = this._checked;
158 }
159 this._valueSyncedWithInputField = false;
160 }
161 },
162
163 prepareForDraw: {
164 value: function() {
165 if (this.label !== null) {
166 var b = document.createElement("label");
167 b.innerHTML = this.label;
168 this.element.appendChild(b);
169 b.addEventListener("click", this, false);
170 }
171 if (this.group !== null) {
172 this.group.addRadio(this);
173 }
174 this.element.addEventListener("change", this, false);
175 }
176 }
177
178}); \ No newline at end of file