aboutsummaryrefslogtreecommitdiff
path: root/js/ui/menu/menu.reel/menu.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/ui/menu/menu.reel/menu.js')
-rwxr-xr-xjs/ui/menu/menu.reel/menu.js183
1 files changed, 183 insertions, 0 deletions
diff --git a/js/ui/menu/menu.reel/menu.js b/js/ui/menu/menu.reel/menu.js
new file mode 100755
index 00000000..62534d0e
--- /dev/null
+++ b/js/ui/menu/menu.reel/menu.js
@@ -0,0 +1,183 @@
1/* <copyright>
2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11* Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14
15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29POSSIBILITY OF SUCH DAMAGE.
30</copyright> */
31
32var Montage = require("montage/core/core").Montage,
33 Component = require("montage/ui/component").Component;
34
35exports.Menu = Montage.create(Component, {
36
37 _currentDocument: {
38 value : null
39 },
40
41 currentDocument : {
42 get : function() {
43 return this._currentDocument;
44 },
45 set : function(value) {
46 if (value === this._currentDocument) {
47 return;
48 }
49
50 this._currentDocument = value;
51 }
52 },
53
54 menudata: {
55 value: null
56 },
57
58 _active: {
59 value: false
60 },
61
62 active: {
63 get: function() {
64 return this._active;
65 },
66 set: function(value) {
67 if(this._active !== value) {
68 this._active = value;
69 }
70
71 if(this._active) {
72 document.addEventListener("mousedown", this, false);
73 document.addEventListener("keydown", this, true);
74 } else {
75 document.removeEventListener("mousedown", this, false);
76 document.removeEventListener("keydown", this, true);
77 this.activeEntry = null;
78 }
79
80 }
81 },
82
83 _activeEntry: {
84 value: null
85 },
86
87 activeEntry: {
88 get: function() {
89 return this._activeEntry;
90 },
91 set: function(value) {
92 if(this._activeEntry === value) return;
93
94 if(this._activeEntry) {
95 this._activeEntry.element.classList.remove("selected");
96 }
97
98 this._activeEntry = value;
99
100 if(this._activeEntry) {
101 this._activeEntry.element.classList.add("selected");
102 }
103 }
104 },
105
106 prepareForDraw: {
107 value: function() {
108 this.addEventListener("headermousedown", this, false);
109 this.addEventListener("headermouseover", this, false);
110
111 this.addEventListener("menuItemClick", this, false);
112 }
113 },
114
115 handleHeadermousedown: {
116 value: function(evt) {
117 if(!this.active) {
118 this.active = true;
119 }
120
121 this.activeEntry = evt.detail;
122 }
123 },
124
125 handleHeadermouseover: {
126 value: function(evt) {
127 if(this.active) {
128 this.activeEntry = evt.detail;
129 }
130 }
131 },
132
133 handleMenuItemClick: {
134 value: function(evt) {
135 if(evt.detail.indexOf("-") > 0) {
136 this.menudata.toggleItem(evt.detail.slice(evt.detail.indexOf("-") + 1));
137 } else {
138 NJevent(evt.detail);
139 }
140 this.active = false;
141 }
142 },
143
144 captureKeydown: {
145 value: function(evt) {
146 if(evt.keyCode === 27) {
147 this.active = false;
148 }
149 }
150 },
151
152 handleMousedown: {
153 value: function(evt) {
154 if(this.active && (this.getZIndex(evt.target) < 9000 || evt.target.id === "topMenu")) {
155 this.active = false;
156 }
157 }
158 },
159
160 getZIndex: {
161 value: function(elem) {
162
163 var position, value, zIndex;
164 while (elem && elem !== document) {
165// position = elem.style.position;
166 position = document.defaultView.getComputedStyle(elem, "").getPropertyValue("position");
167
168 if (position === "absolute" || position === "relative" || position === "fixed") {
169 // webkit returns a string for zindex value and "" if zindex is not available
170// zIndex = elem.style['z-index'];
171 zIndex = document.defaultView.getComputedStyle(elem, "").getPropertyValue("z-index");
172 value = parseInt(zIndex, 10);
173 if (!isNaN(value) && value !== 0) {
174 return value;
175 }
176 }
177 elem = elem.parentNode;
178 }
179 return 0;
180 }
181 }
182
183});