1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
var Montage = require("montage/core/core").Montage;
var Component = require("montage/ui/component").Component;
exports.MenuItem = Montage.create(Component, {
data: {
value: null
},
_enabled: {
value: false
},
enabled: {
get: function() {
return this._enabled;
},
set: function(value) {
if(value !== this._enabled) {
this._enabled = value;
this.needsDraw = true;
}
}
},
_checked: {
value: null
},
checked: {
get: function() {
return this._checked;
},
set: function(value) {
/*
if( Object.prototype.toString.call( value ) === '[object Array]' ) {
value = value.indexOf(this.data.displayText + "Panel") >= 0;
}
*/
if(this._checked !== value) {
this._checked = value;
this.needsDraw = true;
}
}
},
submenu: {
value: false
},
subentries: {
value: []
},
prepareForDraw: {
value: function() {
if(!this.data) return;
if(this.data.separator) {
this.element.classList.add("itemSeparator");
this.itemBackground.classList.remove("menubg");
this.itemBackground.classList.add("separator");
return;
}
// Binding the checked to the assigned bound property
if(this.data.checked) {
Object.defineBinding(this, "checked", {
boundObject: this.application.ninja.appModel,
boundObjectPropertyPath: this.data.checked.boundProperty
});
}
if(this.data.submenu) {
this.submenu = true;
this.subentries = this.data.entries;
this.subMenu.classList.add("subMenu");
this.element.addEventListener("mouseover", this, false);
this.element.addEventListener("mouseout", this, false);
}
this.itemText.innerHTML = this.data.displayText;
this.element.addEventListener("mousedown", this, true);
}
},
draw: {
value: function() {
if(this.enabled) {
this.element.classList.remove("disabled");
} else {
this.element.classList.add("disabled");
}
if(this.checked) {
this.itemBackground.classList.add("checked");
} else {
this.itemBackground.classList.remove("checked");
}
if(this.submenu) {
this.itemBackground.classList.add("submenu");
}
}
},
captureMousedown: {
value: function(event) {
if(this.data.radio && this.checked) return;
if( ( this.enabled === true || this.enabled > 0 ) && (this.submenu === false) ) {
if(this.data.action) {
NJevent ( this.data.action );
} else if(this.checked !== null) {
this.checked = !this.checked;
}
}
}
},
handleMouseover: {
value: function() {
if(this.enabled) this.subMenu.style.display = "block";
}
},
handleMouseout: {
value: function() {
this.subMenu.style.display = "none";
}
}
});
|