aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/check-input.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/check-input.js')
-rw-r--r--node_modules/montage/ui/check-input.js93
1 files changed, 79 insertions, 14 deletions
diff --git a/node_modules/montage/ui/check-input.js b/node_modules/montage/ui/check-input.js
index 6338c42c..42538c02 100644
--- a/node_modules/montage/ui/check-input.js
+++ b/node_modules/montage/ui/check-input.js
@@ -3,10 +3,11 @@
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<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. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5 </copyright> */
6 6/*global require, exports */
7var Montage = require("montage").Montage, 7var Montage = require("montage").Montage,
8 Component = require("ui/component").Component, 8 Component = require("ui/component").Component,
9 NativeControl = require("ui/native-control").NativeControl; 9 NativeControl = require("ui/native-control").NativeControl,
10 PressComposer = require("ui/composer/press-composer").PressComposer;
10 11
11var CheckInput = exports.CheckInput = Montage.create(NativeControl, { 12var CheckInput = exports.CheckInput = Montage.create(NativeControl, {
12 13
@@ -14,33 +15,97 @@ var CheckInput = exports.CheckInput = Montage.create(NativeControl, {
14 draw: { 15 draw: {
15 value: function() { 16 value: function() {
16 // Call super 17 // Call super
17 Object.getPrototypeOf(CheckInput).draw.call(this); 18 NativeControl.draw.call(this);
18 this._element.setAttribute("aria-checked", this._checked); 19 this._element.setAttribute("aria-checked", this._checked);
19 } 20 }
20 }, 21 },
21 22
23 _pressComposer: {
24 enumerable: false,
25 value: null
26 },
27
28 prepareForActivationEvents: {
29 value: function() {
30 var pressComposer = this._pressComposer = PressComposer.create();
31 this.addComposer(pressComposer);
32 pressComposer.addEventListener("pressstart", this, false);
33 pressComposer.addEventListener("press", this, false);
34 }
35 },
36
37 prepareForDraw: {
38 enumerable: false,
39 value: function() {
40 this._element.addEventListener('change', this);
41 }
42 },
43
44
45
22 /** 46 /**
23 Description TODO 47 Fake the checking of the element.
24 @function 48
49 Changes the checked property of the element and dispatches a change event.
50 Radio button overrides this.
51
52 @private
25 */ 53 */
26 prepareForDraw: { 54 _fakeCheck: {
27 enumerable: false, 55 enumerable: false,
28 value: function() { 56 value: function() {
29 this.element.addEventListener('change', this); 57 var changeEvent;
58 // NOTE: this may be BAD, modifying the element outside of
59 // the draw loop, but it's what a click/touch would
60 // actually have done
61 this._element.checked = !this._element.checked;
62 changeEvent = document.createEvent("HTMLEvents");
63 changeEvent.initEvent("change", true, true);
64 this._element.dispatchEvent(changeEvent);
30 } 65 }
31 }, 66 },
32 67
33/** 68 /**
34 Description TODO 69 Stores if we need to fake checking.
35 @function 70
36 @param {Event Handler} event TODO 71 When preventDefault is called on touchstart and touchend events (e.g. by
72 the scrollview component) the checkbox doesn't check itself, so we need
73 to fake it later.
74
75 @default false
76 @private
37 */ 77 */
78 _shouldFakeCheck: {
79 enumerable: false,
80 value: false
81 },
82
83 // Handlers
84
85 handlePressstart: {
86 value: function(event) {
87 this._shouldFakeCheck = event.defaultPrevented;
88 }
89 },
90
91
92 handlePress: {
93 value: function(event) {
94 if (this._shouldFakeCheck) {
95 this._shouldFakeCheck = false;
96 this._fakeCheck();
97 }
98 }
99 },
100
38 handleChange: { 101 handleChange: {
39 enumerable: false, 102 enumerable: false,
40 value: function(event) { 103 value: function(event) {
41 Object.getPropertyDescriptor(this, "checked").set.call(this, 104 if (!this._pressComposer || this._pressComposer.state !== PressComposer.CANCELLED) {
42 this.element.checked, true); 105 Object.getPropertyDescriptor(this, "checked").set.call(this,
43 this._dispatchActionEvent(); 106 this.element.checked, true);
107 this._dispatchActionEvent();
108 }
44 } 109 }
45 } 110 }
46}); 111});