aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/radio-button.reel
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-02 00:11:51 -0800
committerValerio Virgillito2012-02-02 15:33:42 -0800
commita3024011a91d3941f81481dd4d600e9684eb0fd4 (patch)
tree084b4856910f1db53973dd11617f7ffa03a6dd46 /node_modules/montage/ui/radio-button.reel
parent97255032921178bdfbc25512ddf3e0867e353f7a (diff)
downloadninja-a3024011a91d3941f81481dd4d600e9684eb0fd4.tar.gz
upgrading to Montage v0.6
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/radio-button.reel')
-rwxr-xr-xnode_modules/montage/ui/radio-button.reel/radio-button.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/node_modules/montage/ui/radio-button.reel/radio-button.js b/node_modules/montage/ui/radio-button.reel/radio-button.js
new file mode 100755
index 00000000..8468ee21
--- /dev/null
+++ b/node_modules/montage/ui/radio-button.reel/radio-button.js
@@ -0,0 +1,97 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No 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> */
6var Montage = require("montage").Montage,
7 Component = require("ui/component").Component,
8 CheckInput = require("ui/check-input").CheckInput;
9/**
10 * The Text input
11 */
12var RadioButton = exports.RadioButton = Montage.create(CheckInput, {
13 _checkedSyncedWithInputField: {
14 enumerable: false,
15 value: false
16 },
17
18 _checked: {
19 enumerable: false,
20 value: null
21 },
22 checked: {
23 get: function() {
24 // If we haven't synced with the input field then our value is
25 // more up to date than the element and so we don't get it from the
26 // element. If we have synced then the user could have changed
27 // the focus to another radio button, so we *do* retrieve it from
28 // the element.
29 if (this._checkedSyncedWithInputField === true) {
30 this._checked = this._element.checked;
31 }
32
33 return this._checked;
34 },
35 set: function(value, fromInput) {
36 this._checked = value;
37 if (fromInput) {
38 this._valueSyncedWithInputField = true;
39 } else {
40 this._valueSyncedWithInputField = false;
41 this.needsDraw = true;
42 }
43
44 if(this._checked === true) {
45 if(this.name && this.name !== null) {
46 // dispatch an event to all other radiobuttons with the same name
47 var anEvent = document.createEvent("CustomEvent");
48 anEvent.initCustomEvent("checked", true, true, {
49 name: this.name
50 });
51 anEvent.type = "checked";
52 RadioButton.dispatchEvent(anEvent);
53 RadioButton.addEventListener('checked', this);
54 }
55 }
56 }
57 },
58
59
60 handleChecked:{
61 value: function(evt) {
62 // if we receive this event, it means that some other radiobutton with the same name
63 // has been checked. So, mark this as unchecked.
64 if(this.name === evt.detail.name) {
65 this.checked = false;
66 RadioButton.removeEventListener('checked', this);
67 }
68 }
69 },
70
71 draw: {
72 value: function() {
73 if (!this._valueSyncedWithInputField) {
74 this._element.checked = this._checked;
75 }
76
77 // Call super
78 var fn = Object.getPrototypeOf(RadioButton).draw.call(this);
79 }
80 }
81});
82RadioButton.addAttributes({
83 autofocus: 'off', // on/off
84 disabled: {value: false, dataType: 'boolean'},
85 checked: {value: false, dataType: 'boolean'},
86 form: null,
87 name: null,
88 readonly: {value: false, dataType: 'boolean'},
89 title: null,
90 /*
91 "On getting, if the element has a value attribute, it must return that
92 attribute's value; otherwise, it must return the string "on". On setting,
93 it must set the element's value attribute to the new value."
94 http://www.w3.org/TR/html5/common-input-element-attributes.html#dom-input-value-default-on
95 */
96 value: {value: 'on'}
97});