aboutsummaryrefslogtreecommitdiff
path: root/js/components/menu/menu-item.reel/menu-item.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/components/menu/menu-item.reel/menu-item.js')
-rw-r--r--js/components/menu/menu-item.reel/menu-item.js160
1 files changed, 160 insertions, 0 deletions
diff --git a/js/components/menu/menu-item.reel/menu-item.js b/js/components/menu/menu-item.reel/menu-item.js
new file mode 100644
index 00000000..64a89a6a
--- /dev/null
+++ b/js/components/menu/menu-item.reel/menu-item.js
@@ -0,0 +1,160 @@
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.MenuItem = Montage.create(Component, {
11
12 data: {
13 value: null
14 },
15
16 _enabled: {
17 value: null
18 },
19
20 enabled: {
21 get: function() {
22 return this._enabled;
23 },
24 set: function(value) {
25 if(value !== this._enabled) {
26 this._enabled = value;
27 this.needsDraw = true;
28 }
29 }
30 },
31
32 _checked: {
33 value: null
34 },
35
36 checked: {
37 get: function() {
38 return this._checked;
39 },
40 set: function(value) {
41 /*
42 if( Object.prototype.toString.call( value ) === '[object Array]' ) {
43 value = value.indexOf(this.data.displayText + "Panel") >= 0;
44 }
45 */
46
47 if(this._checked !== value) {
48 this._checked = value;
49 this.needsDraw = true;
50 }
51 }
52 },
53
54 submenu: {
55 value: false
56 },
57
58 subentries: {
59 value: []
60 },
61
62 prepareForDraw: {
63 value: function() {
64 if(!this.data) return;
65
66 if(this.data.separator) {
67 this.element.classList.add("itemSeparator");
68 this.itemBackground.classList.remove("menubg");
69 this.itemBackground.classList.add("separator");
70
71 return;
72
73 }
74
75 // Binding the checked to the assigned bound property
76 if(this.data.checked) {
77 Object.defineBinding(this, "checked", {
78 boundObject: this.application.ninja.appModel,
79 boundObjectPropertyPath: this.data.checked.boundProperty
80 });
81
82 }
83
84 if(this.data.enabled.boundProperty) {
85 Object.defineBinding(this, "enabled", {
86 boundObject: this.application.ninja[this.data.enabled.boundObj],
87 boundObjectPropertyPath: this.data.enabled.boundProperty
88 });
89
90 } else {
91 this.enabled = this.data.enabled;
92 }
93
94 if(this.data.submenu) {
95 this.submenu = true;
96
97 this.subentries = this.data.entries;
98
99 this.subMenu.classList.add("subMenu");
100 this.element.addEventListener("mouseover", this, false);
101 this.element.addEventListener("mouseout", this, false);
102
103 }
104
105
106 this.itemText.innerHTML = this.data.displayText;
107 this.element.addEventListener("mousedown", this, true);
108 }
109 },
110
111 draw: {
112 value: function() {
113
114 if(this.enabled) {
115 this.element.classList.remove("disabled");
116 } else {
117 this.element.classList.add("disabled");
118 }
119
120 if(this.checked) {
121 this.itemBackground.classList.add("checked");
122 } else {
123 this.itemBackground.classList.remove("checked");
124 }
125
126 if(this.submenu) {
127 this.itemBackground.classList.add("submenu");
128 }
129 }
130 },
131
132 captureMousedown: {
133 value: function(event) {
134
135 if(this.data.radio && this.checked) return;
136
137 if(this.enabled || !this.submenu) {
138 if(this.data.action) {
139 NJevent ( this.data.action );
140 } else if(this.checked !== null) {
141 this.checked = !this.checked;
142 }
143 }
144
145 }
146 },
147
148 handleMouseover: {
149 value: function() {
150 if(this.enabled) this.subMenu.style.display = "block";
151 }
152 },
153
154 handleMouseout: {
155 value: function() {
156 this.subMenu.style.display = "none";
157 }
158 }
159
160}); \ No newline at end of file