diff options
author | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
---|---|---|
committer | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
commit | 10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e (patch) | |
tree | 12b31910a3c7c7fa2ee0b26d8aaa611710e139a5 /node_modules/montage/ui/radio-button.reel | |
parent | 7f8730c3add146f1ba107e6fc22d1f5a8348ed8b (diff) | |
parent | 668510892537eaaeb2e11520831d87b44b2489b7 (diff) | |
download | ninja-10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into text-tool
Conflicts:
_scss/compass_app_log.txt
css/ninja.css
Diffstat (limited to 'node_modules/montage/ui/radio-button.reel')
-rwxr-xr-x | node_modules/montage/ui/radio-button.reel/radio-button.js | 97 |
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> */ | ||
6 | var Montage = require("montage").Montage, | ||
7 | Component = require("ui/component").Component, | ||
8 | CheckInput = require("ui/check-input").CheckInput; | ||
9 | /** | ||
10 | * The Text input | ||
11 | */ | ||
12 | var 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 | }); | ||
82 | RadioButton.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 | }); | ||