| author | hgs |
| Fri, 15 Oct 2010 17:30:59 -0400 | |
| changeset 16 | 3c88a81ff781 |
| parent 3 | 0954f5dd2cd0 |
| permissions | -rw-r--r-- |
| 3 | 1 |
var cm_TheContextMenu; |
2 |
||
3 |
// Return true if the given element's className includes the given class. |
|
4 |
function hasClass(ele,cls) {
|
|
5 |
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
|
|
6 |
} |
|
7 |
||
8 |
// Remove a class from an element's className. |
|
9 |
function removeClass(ele,cls) {
|
|
10 |
if (hasClass(ele,cls)) {
|
|
11 |
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
|
|
12 |
ele.className=ele.className.replace(reg,' '); |
|
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
} |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
} |
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
|
| 3 | 16 |
function ContextMenu(snippetId, contentView) {
|
17 |
this.snippetId = snippetId; |
|
18 |
this.mainDiv = undefined; |
|
19 |
this.tailEl = undefined; |
|
20 |
this.contentView = contentView; |
|
21 |
this.showTimeoutId = 0; |
|
| 16 | 22 |
this.editingSnippet = undefined; |
| 3 | 23 |
// Width of a tab with no text, just the icon. Icons must all be the same width. |
24 |
// Update this if icon size or tab border width etc. changes -- or better yet, determine it dynamically. |
|
25 |
this.normalTabWidth = 64; |
|
26 |
// Height of the menu is the max possible height to be used when positioning the snippet |
|
27 |
this.menuHeight = 272; |
|
| 16 | 28 |
this.snippetWidth = 0; |
29 |
// Width of the menu when it has no tab |
|
30 |
this.menuWidth = 130; |
|
| 3 | 31 |
// ContextMenu is a singleton to avoid problems with scope-chaining in some of the |
32 |
// callbacks that it uses. See handleTabActivate. |
|
33 |
if (cm_TheContextMenu != undefined) app.debug("ERROR: cm_TheContextMenu must be a singleton");
|
|
34 |
cm_TheContextMenu = this; |
|
35 |
||
36 |
// Create tabs and their corresponding menus based on JSON data. |
|
37 |
this.createTabsElement = function(data) {
|
|
38 |
this.mainDiv = document.createElement("div");
|
|
39 |
this.mainDiv.setAttribute("class", "ContextMenuDiv");
|
|
40 |
this.mainDiv.setAttribute("id", "cm_mainDivId");
|
|
41 |
||
42 |
var tabsDiv = document.createElement("div");
|
|
43 |
tabsDiv.setAttribute("class", "TabsDiv");
|
|
44 |
tabsDiv.setAttribute("id", "cm_tabsDivId");
|
|
45 |
||
46 |
var menuDiv = document.createElement("div");
|
|
47 |
menuDiv.setAttribute("class", "MenuDiv");
|
|
48 |
menuDiv.setAttribute("id", "cm_menuDivId");
|
|
49 |
||
50 |
var tabsUl = document.createElement("ul");
|
|
51 |
tabsUl.setAttribute("class", "TabsUl");
|
|
52 |
tabsUl.setAttribute("id", "cm_tabsUlId");
|
|
53 |
tabsDiv.appendChild(tabsUl); |
|
54 |
||
55 |
var currentTabFound = false; |
|
| 16 | 56 |
if (data.tabs == undefined) {
|
57 |
var menuEl = this.createMenuElement(data.menus[0], true); |
|
58 |
menuDiv.appendChild(menuEl); |
|
59 |
document.getElementById(this.snippetId).style.width = this.menuWidth; |
|
60 |
this.mainDiv.appendChild(menuDiv); |
|
61 |
return this.mainDiv; |
|
62 |
} |
|
| 3 | 63 |
|
64 |
// Iterate through the list of tabs. |
|
65 |
for (var i=0; i < data.tabs.length; i++) {
|
|
66 |
var tab = data.tabs[i]; |
|
67 |
if (tab.visible != undefined) {
|
|
68 |
if (!tab.visible()) {
|
|
69 |
continue; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
// Create the tab. |
|
74 |
var tabEl = document.createElement("li");
|
|
75 |
tabsUl.appendChild(tabEl); |
|
76 |
||
77 |
var tabDiv = document.createElement("div");
|
|
78 |
tabEl.appendChild(tabDiv); |
|
79 |
||
80 |
var iconEl = undefined; |
|
81 |
var iconHighlightedEl = undefined; |
|
82 |
||
83 |
// Create the tab's icons. |
|
84 |
if (tab.icon != undefined) {
|
|
85 |
iconEl = document.createElement("img");
|
|
86 |
iconEl.setAttribute("id", "icon");
|
|
87 |
iconEl.setAttribute("src", tab.icon);
|
|
88 |
tabDiv.appendChild(iconEl); |
|
89 |
} |
|
90 |
if (tab.iconHighlighted != undefined) {
|
|
91 |
iconHighlightedEl = document.createElement("img");
|
|
92 |
iconHighlightedEl.setAttribute("id", "iconHighlighted");
|
|
93 |
iconHighlightedEl.setAttribute("src", tab.iconHighlighted);
|
|
94 |
tabDiv.appendChild(iconHighlightedEl); |
|
95 |
} |
|
96 |
||
97 |
// Create the tab's text. |
|
98 |
if (tab.text != undefined) {
|
|
99 |
var anchorEl = document.createElement("a");
|
|
100 |
tabDiv.appendChild(anchorEl); |
|
101 |
var textEl = document.createTextNode(tab.text); |
|
102 |
anchorEl.appendChild(textEl); |
|
103 |
} |
|
104 |
||
105 |
// Create the menu for this tab. |
|
106 |
var menuEl = this.createMenuElement(tab); |
|
107 |
menuDiv.appendChild(menuEl); |
|
108 |
||
109 |
var tabClassName; |
|
110 |
if (tab.current == "true") {
|
|
111 |
// This is the current, or selected, tab. |
|
112 |
tabClassName = "ViewContext_HighlightedTab"; |
|
113 |
tabDiv.className = "ViewContext_HighlightedTabDiv"; |
|
114 |
if(iconEl != undefined) {
|
|
115 |
iconEl.setAttribute("style", "display: none;");
|
|
116 |
} |
|
117 |
currentTabFound = true; |
|
118 |
} |
|
119 |
else {
|
|
120 |
// Not selected. |
|
121 |
tabClassName = "ViewContext_NormalTab"; |
|
122 |
tabDiv.className = "ViewContext_NormalTabDiv"; |
|
123 |
if(iconHighlightedEl != undefined) {
|
|
124 |
iconHighlightedEl.setAttribute("style", "display: none;");
|
|
125 |
} |
|
126 |
||
127 |
// Hide its menu. |
|
128 |
menuEl.style.display = "none"; |
|
129 |
} |
|
130 |
||
131 |
if (tab.disabled == "true") {
|
|
132 |
// The tab is disabled, add the appropriate CSS class to it. |
|
133 |
tabClassName += " ViewContext_DisabledTab"; |
|
134 |
} |
|
135 |
||
136 |
tabEl.className = tabClassName; |
|
137 |
||
138 |
// Set up callback to show the menu that corresponds to this tab. |
|
139 |
tabEl.onmouseup = this.handleTabActivate; |
|
140 |
tabEl.cm_menu = menuEl; |
|
141 |
||
142 |
// Remember that this tab is disabled. |
|
143 |
tabEl.cm_disabled = tab.disabled == "true"; |
|
144 |
} |
|
145 |
||
146 |
// If a "current" tab was not specified, highlight the first tab and display its menu. |
|
147 |
if (!currentTabFound) {
|
|
148 |
var firstTabEl = tabsUl.firstChild; |
|
149 |
firstTabEl.className = "ViewContext_HighlightedTab"; |
|
150 |
firstTabEl.firstChild.className = "ViewContext_HighlightedTabDiv"; |
|
151 |
firstTabEl.cm_menu.style.display = ""; |
|
152 |
} |
|
153 |
||
154 |
// this.tailEl = document.createElement("img");
|
|
155 |
// this.mainDiv.appendChild(this.tailEl); |
|
156 |
// this.tailEl.setAttribute("id", "cm_tailId");
|
|
| 16 | 157 |
// this.tailEl.setAttribute("src", "/contextmenu/menu_tail.png");
|
| 3 | 158 |
|
159 |
this.mainDiv.appendChild(tabsDiv); |
|
160 |
this.mainDiv.appendChild(menuDiv); |
|
161 |
return this.mainDiv; |
|
162 |
} |
|
163 |
||
164 |
// Create a single menu based on the given data structure. |
|
| 16 | 165 |
this.createMenuElement = function(data, noTab) {
|
| 3 | 166 |
// Create menu list. |
167 |
var menuUl = document.createElement("ul");
|
|
168 |
menuUl.setAttribute("class", "MenuUl");
|
|
169 |
||
170 |
for (var i=0; i < data.menuItems.length; i++) {
|
|
171 |
var menuItem = data.menuItems[i]; |
|
172 |
||
173 |
// Create the item. |
|
174 |
var itemLi = document.createElement("li");
|
|
| 16 | 175 |
if(noTab == true) |
176 |
itemLi.setAttribute("class", "SpMenuLi");
|
|
177 |
else |
|
178 |
itemLi.setAttribute("class", "MenuLi");
|
|
| 3 | 179 |
var itemSpan = document.createElement("div");
|
180 |
||
181 |
// Is it a row if items? enumerate that as a ul inside of this outer li |
|
182 |
if(menuItem.menuRow != undefined) {
|
|
183 |
var menuRowUl = document.createElement("ul");
|
|
184 |
menuRowUl.setAttribute("class", "MenuRowUl");
|
|
185 |
itemSpan.appendChild(menuRowUl); |
|
186 |
||
187 |
for(var j=0; j < menuItem.menuRow.length; j++) |
|
188 |
{
|
|
189 |
var menuRowItem = menuItem.menuRow[j]; |
|
190 |
||
191 |
var rowItemLi = document.createElement("li");
|
|
192 |
rowItemLi.setAttribute("class", "MenuRowLi");
|
|
193 |
menuRowUl.appendChild(rowItemLi); |
|
194 |
||
195 |
// bind to mouseup |
|
196 |
rowItemLi.onmouseup = (function(handler) {
|
|
197 |
return function() {
|
|
198 |
if (handler != undefined) |
|
199 |
handler(); |
|
200 |
this.hide(); |
|
201 |
}.bind(this) |
|
202 |
}.bind(this))(menuRowItem.onclick); |
|
203 |
||
204 |
if (menuRowItem.text != undefined) {
|
|
205 |
var textEl = document.createTextNode(menuRowItem.text); |
|
206 |
rowItemLi.appendChild(textEl); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
else {
|
|
211 |
itemLi.className += " RegularMenuLi"; |
|
212 |
if (menuItem.disabled == "true" || data.disabled == "true") {
|
|
213 |
// Disabled item. |
|
| 16 | 214 |
if (noTab == "true") |
215 |
itemLi.setAttribute("color", "#888");
|
|
216 |
else |
|
217 |
itemLi.className += " ViewContext_DisabledMenuItem"; |
|
| 3 | 218 |
} |
219 |
else {
|
|
220 |
// Enabled item. Set up the onmouseup handler. |
|
221 |
itemLi.onmouseup = (function(handler) {
|
|
222 |
return function() {
|
|
223 |
if (handler != undefined) |
|
224 |
handler(); |
|
225 |
this.hide(); |
|
226 |
}.bind(this) |
|
227 |
}.bind(this))(menuItem.onclick); |
|
228 |
} |
|
229 |
||
230 |
itemLi.onmouseover = function() {
|
|
231 |
this.className += " MouseOverItem"; |
|
232 |
}.bind(itemLi) |
|
233 |
||
234 |
itemLi.onmouseout = function() {
|
|
235 |
removeClass(this, "MouseOverItem"); |
|
236 |
}.bind(itemLi) |
|
237 |
||
238 |
// Create the item's icon. |
|
239 |
if (menuItem.icon != undefined) {
|
|
240 |
var iconEl = document.createElement("img");
|
|
241 |
itemSpan.appendChild(iconEl); |
|
242 |
iconEl.setAttribute("src", menuItem.icon);
|
|
243 |
} |
|
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
244 |
|
| 3 | 245 |
// Create the item's text. |
246 |
if (menuItem.text != undefined) {
|
|
247 |
var anchorEl = document.createElement("a");
|
|
248 |
itemSpan.appendChild(anchorEl); |
|
249 |
var textEl = document.createTextNode(menuItem.text); |
|
250 |
anchorEl.appendChild(textEl); |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
menuUl.appendChild(itemLi); |
|
255 |
itemLi.appendChild(itemSpan); |
|
256 |
} |
|
257 |
return menuUl; |
|
258 |
} |
|
259 |
||
260 |
// Handle mouse clicks on tab elements. |
|
261 |
// Note: "this" refers to the element that was clicked on, ie. the tab item. |
|
262 |
this.handleTabActivate = function() {
|
|
263 |
var tabsDivChildren = document.getElementById("cm_tabsUlId").childNodes;
|
|
264 |
var otherTabsWidth = 0; |
|
265 |
// Set the class for each tab. |
|
266 |
for (var i = 0; i < tabsDivChildren.length; i++) {
|
|
267 |
var tabEl = tabsDivChildren[i]; |
|
268 |
var iconHighlighted = getChildById(tabEl, "iconHighlighted"); |
|
269 |
var icon = getChildById(tabEl, "icon"); |
|
270 |
if (tabEl == this) {
|
|
271 |
// Activate the tab. |
|
272 |
tabEl.className = "ViewContext_HighlightedTab"; |
|
273 |
//tabEl.firstChild.className = "ViewContext_HighlightedTabDiv"; |
|
274 |
||
275 |
// Show the highlighted icon, if one exists. |
|
276 |
if(iconHighlighted != undefined) {
|
|
277 |
iconHighlighted.style.display = ""; |
|
278 |
||
279 |
// Hide the normal icon. |
|
280 |
if (icon != undefined) {
|
|
281 |
icon.style.display = "none"; |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
else {
|
|
286 |
// Deactivate the tab. |
|
287 |
tabEl.className = "ViewContext_NormalTab"; |
|
288 |
//tabEl.firstChildclassName = "ViewContext_NormalTabDiv"; |
|
289 |
||
290 |
// If a highlighted icon exists, switch to the normal one, otherwise leave |
|
291 |
// the normal one alone. |
|
292 |
if(iconHighlighted != undefined) {
|
|
293 |
iconHighlighted.style.display = "none"; |
|
294 |
if (icon != undefined) {
|
|
295 |
icon.style.display = ""; |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
if (tabEl.cm_disabled) {
|
|
300 |
tabEl.className += " ViewContext_DisabledTab"; |
|
301 |
//tabEl.firstClassName += " ViewContext_DisabledTabDiv"; |
|
302 |
} |
|
303 |
} |
|
304 |
||
305 |
// Show the menu of the tab that was just clicked. |
|
306 |
var menuDivChildren = document.getElementById("cm_menuDivId").childNodes;
|
|
307 |
for (var i = 0; i < menuDivChildren.length; i++) {
|
|
308 |
var menuEl = menuDivChildren[i]; |
|
309 |
if (menuEl == this.cm_menu) {
|
|
310 |
menuDivChildren[i].style.display = ""; |
|
311 |
} |
|
312 |
else {
|
|
313 |
menuDivChildren[i].style.display = "none"; |
|
314 |
} |
|
315 |
} |
|
316 |
//cm_TheContextMenu.positionTail(); |
|
317 |
//document.getElementById(this.snippetId).clientHeight = this.mainDiv.clientHeight; |
|
318 |
//document.getElementById("ContextMenuId").setAttribute("style", "height: " + document.getElementById("cm_mainDivId").clientHeight + "px;")
|
|
319 |
||
320 |
cm_TheContextMenu.updateTabSizes(); |
|
321 |
snippets[cm_TheContextMenu.snippetId].updateOwnerArea(); |
|
322 |
} |
|
323 |
||
324 |
// Return the width of the "non-content" part of the element box, ie. thickness of |
|
325 |
// the padding, the border and the margin. |
|
326 |
this.getNonContentWidth = function(element) {
|
|
327 |
var tabStyle = document.defaultView.getComputedStyle(element, null); |
|
328 |
return parseInt(tabStyle["margin-left"]) + parseInt(tabStyle["margin-right"]) + |
|
329 |
parseInt(tabStyle["padding-left"]) + parseInt(tabStyle["padding-right"]) + |
|
330 |
parseInt(tabStyle["border-left-width"]) + parseInt(tabStyle["border-right-width"]); |
|
331 |
} |
|
332 |
||
333 |
// Update the tab widths. Expand the highlighted tab to its maximum width and shrink the |
|
334 |
// normal tabs to their minimum widths. Note: it would be preferable to have this done |
|
335 |
// by CSS. |
|
336 |
this.updateTabSizes = function() {
|
|
337 |
var tabsUl = document.getElementById("cm_tabsUlId");
|
|
338 |
var tabsDivChildren = tabsUl.childNodes; |
|
339 |
var otherTabsWidth = 0; |
|
340 |
var highlightedTab; |
|
341 |
for (var i = 0; i < tabsDivChildren.length; i++) {
|
|
342 |
var tabEl = tabsDivChildren[i]; |
|
343 |
if (tabEl.className.indexOf("ViewContext_HighlightedTab") != -1) {
|
|
344 |
highlightedTab = tabEl; |
|
345 |
} |
|
346 |
else {
|
|
347 |
var newTabWidth = cm_TheContextMenu.normalTabWidth - cm_TheContextMenu.getNonContentWidth(tabEl); |
|
348 |
tabEl.style.width = newTabWidth; |
|
349 |
otherTabsWidth += tabEl.offsetWidth; |
|
350 |
} |
|
351 |
} |
|
352 |
if (highlightedTab != undefined) {
|
|
353 |
var newWidth = tabsUl.offsetWidth - otherTabsWidth; |
|
354 |
newWidth -= cm_TheContextMenu.getNonContentWidth(highlightedTab) + 2; |
|
355 |
highlightedTab.style.width = newWidth; |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
this.positionTail = function() {
|
|
360 |
// Move the "tail" into position. |
|
361 |
var tailEl = document.getElementById("cm_tailId");
|
|
362 |
if (tailEl != undefined) {
|
|
363 |
//var mainDiv = document.getElementById("cm_mainDivId");
|
|
364 |
var tailX = (this.mainDiv.clientWidth - tailEl.clientWidth) / 2; |
|
365 |
var tailY = this.mainDiv.clientHeight; |
|
366 |
tailEl.setAttribute("style", "position:absolute; top: " + tailY + "px; left: " + tailX);
|
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
// Create all the DOM elements of the window. |
|
371 |
this.create = function(menuData) {
|
|
372 |
var snippetEl = document.getElementById(this.snippetId); |
|
373 |
var el = this.createTabsElement(menuData); |
|
374 |
snippetEl.appendChild(el); |
|
| 16 | 375 |
snippetEl.insertAdjacentHTML('beforeEnd', '<div class="hiddenLoadImages"></div>');
|
| 3 | 376 |
} |
377 |
||
378 |
// Show the content menu. The menuData must contain an object tree describing the structure of the |
|
379 |
// tabs and sub-menus. |
|
380 |
// |
|
381 |
// Example menu data in JSON format: |
|
382 |
// var MenuData = {
|
|
383 |
// "tabs": [ {
|
|
384 |
// "text": "Tab 1", |
|
385 |
// "icon": "tab1.png", |
|
386 |
// "current": "true", |
|
387 |
// "menuItems": [ {
|
|
388 |
// "text": Menu item 1, |
|
389 |
// "onclick": handleMenu1, |
|
390 |
// "icon": "menu1.png", |
|
391 |
// }, |
|
392 |
// {
|
|
393 |
// "text": Menu item 2, |
|
394 |
// "onclick": function() { alert("hello"); },
|
|
395 |
// "icon": "menu2.png", |
|
396 |
// }, |
|
397 |
// ], |
|
398 |
// }, |
|
399 |
// {
|
|
400 |
// "text": "Tab 2", |
|
401 |
// "icon": "tab2.png", |
|
402 |
// "menuItems": [ {
|
|
403 |
// "text": Menu item 1, |
|
404 |
// "onclick": handleMenu21, |
|
405 |
// }, |
|
406 |
// {
|
|
407 |
// "text": Menu item 2, |
|
408 |
// "onclick": handleMenu22, |
|
409 |
// }, |
|
410 |
// ], |
|
411 |
// }, |
|
412 |
// ] |
|
413 |
// }; |
|
414 |
// |
|
415 |
||
416 |
this.cancel = function() {
|
|
417 |
//app.debug("CM: cancel " + this.showTimeoutId);
|
|
418 |
clearTimeout(this.showTimeoutId); |
|
419 |
this.showTimeoutId = 0; |
|
420 |
this.cleanUp(); |
|
421 |
} |
|
422 |
||
423 |
this.cleanUp = function() {
|
|
424 |
// Remove elements from DOM to save memory. |
|
425 |
var oldEl = document.getElementById("cm_mainDivId");
|
|
426 |
if (oldEl) {
|
|
427 |
var snippetEl = document.getElementById(cm_TheContextMenu.snippetId); |
|
428 |
snippetEl.removeChild(oldEl); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
// Hide this window. |
|
433 |
this.hide = function() {
|
|
434 |
snippets[cm_TheContextMenu.snippetId].hide(); |
|
| 16 | 435 |
if (this.editingSnippet != undefined) |
436 |
this.editingSnippet.setContextMenuStatus(false); |
|
| 3 | 437 |
} |
438 |
||
439 |
this.onHide = function() {
|
|
440 |
this.cleanUp(); |
|
441 |
} |
|
442 |
||
443 |
this.show = function(menuData) {
|
|
| 16 | 444 |
if (this.editingSnippet != undefined) |
445 |
this.editingSnippet.setContextMenuStatus(true); |
|
446 |
||
447 |
document.getElementById(this.snippetId).style.width = this.snippetWidth; |
|
| 3 | 448 |
this.cleanUp(); |
449 |
this.create(menuData); |
|
| 16 | 450 |
if (menuData.tabs != undefined) |
451 |
cm_TheContextMenu.updateTabSizes(); |
|
| 3 | 452 |
// Use a timer to actually show the window to allow the page re-layout |
453 |
// to finish. We don't know when this really happens but 50ms seems to |
|
454 |
// be enough on the N97. Without this delay the bottom of the window |
|
455 |
// often gets clipped. |
|
456 |
setTimeout("cm_TheContextMenu.showIt2()", 50);
|
|
457 |
} |
|
458 |
||
459 |
this.showIt2 = function() {
|
|
460 |
||
461 |
var snippet = snippets[cm_TheContextMenu.snippetId]; |
|
462 |
snippet.updateOwnerArea(); |
|
463 |
snippet.setZValue(2); |
|
464 |
||
465 |
this.centerSnippet(); |
|
466 |
||
467 |
// if (showTail) {
|
|
468 |
// cm_TheContextMenu.positionTail(); |
|
469 |
// } |
|
470 |
||
471 |
snippet.show(); |
|
472 |
} |
|
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
473 |
|
|
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
474 |
|
| 3 | 475 |
this.centerSnippet = function() {
|
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
476 |
|
| 3 | 477 |
|
| 16 | 478 |
var statusBarHeight = snippets.StatusBarChromeId.visible ? snippets.StatusBarChromeId.geometry.height : 0; |
| 3 | 479 |
|
480 |
var snippet = snippets[cm_TheContextMenu.snippetId]; |
|
481 |
var x = (chrome.displaySize.width - snippet.geometry.width) / 2; |
|
482 |
||
483 |
// Center the menu in the space between status bar and tool bar |
|
484 |
var y = (chrome.displaySize.height - statusBarHeight - snippets.WebViewToolbarId.geometry.height - cm_TheContextMenu.menuHeight)/2; |
|
485 |
snippet.setPosition(x, (y+statusBarHeight)); |
|
486 |
||
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
487 |
} |
| 3 | 488 |
chrome.chromeComplete.connect(createDelegate(this, |
489 |
function() {
|
|
490 |
var snippet = snippets[cm_TheContextMenu.snippetId]; |
|
| 16 | 491 |
this.snippetWidth = document.getElementById(cm_TheContextMenu.snippetId).style.width; |
| 3 | 492 |
chrome.aspectChanged.connect(createDelegate(this, |
493 |
function(a) {
|
|
494 |
this.centerSnippet(); |
|
495 |
})); |
|
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
496 |
|
| 3 | 497 |
snippet.hidden.connect(createDelegate(this, this.onHide)); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
498 |
|
| 3 | 499 |
})); |
500 |
} // End ContextMenu class |