2 * widget object constructor
8 if (typeof window.menu == "undefined" || !window.menu)
12 author : 'Nokia WRT Emulation Library',
19 onRightSoftKeySelect : null,
24 Function : menu.append()
25 Argument : MenuItem Object
27 Description : Function appends MenuItem to a Menu Object
29 menu.append = function(MenuItem)
31 if(this.allowedTypeOf(MenuItem))
36 for(var key in this.items)
38 if(this.items[key].id == MenuItem.id)
46 // MenuItem.parent = this;
47 this.items[MenuItem.id] = MenuItem;
54 Function : menu.remove()
55 Argument : MenuItem Object
57 Description : Function Remove the menuItem and its children from the container options menu.
59 menu.remove = function(MenuItem)
61 if(!this.allowedTypeOf(MenuItem))
65 if (this.items.length) {
66 for (var key in this.items) {
67 if (this.items[key].id == MenuItem.id) {
75 this.items.splice(key, 1);
80 Function : menu.clear()
83 Description : Clears (deletes) all the menu items in the menupane.
85 menu.clear = function()
89 this.items.splice(0, this.items.length);
95 Function : Menu.getMenuItemById(id)
97 Returns : MenuItem Object
98 Description : Function get the MenuItem Object with the reference of id
100 menu.getMenuItemById = function(id)
102 var menuItemRef = menu.menuItemExhistsById(this, id, 0);
103 if(this.allowedTypeOf(menuItemRef))
111 Function : Menu.getMenuItemByName(name)
113 Returns : MenuItem Object
114 Description : Function get the MenuItem Object with the reference of String name
116 menu.getMenuItemByName = function(name)
118 var menuItemRef = menu.menuItemExhistsById(this, name, 1);
120 // if(menuItemRef !=null)
121 if(this.allowedTypeOf(menuItemRef))
128 Function : Menu.setRightSoftkeyLabel()
129 Argument : String, Function
131 Description : Set the label of the right soft key to str. This enables the default text
132 to be changed from exit and a new function assigned by setting a callbackfunction
135 menu.setRightSoftkeyLabel = function(label, callback)
140 if(typeof label != '' && !label)
143 else if(typeof callback != 'function' && !callback)
146 else if (_BRIDGE_REF.nokia.menu.setRsk(callback)) {
147 _BRIDGE_REF.parent.$("#RskLabel > a")[0].innerHTML = label;
148 _BRIDGE_REF.nokia.menu.rsk_label = label;
149 _BRIDGE_REF.nokia.menu.rsk_event = callback;
150 _BRIDGE_REF.nokia.menu.is_rsk_overridden = true;
161 menu.setExitToRsk = function()
163 this.onRightSoftKeySelect = null;
165 _BRIDGE_REF.nokia.menu.is_rsk_overridden = false;
166 _BRIDGE_REF.nokia.menu.rsk_label = '';
167 _BRIDGE_REF.nokia.menu.rsk_event = null;
168 _BRIDGE_REF.parent.$("#RskLabel > a")[0].innerHTML = 'Exit';
170 _BRIDGE_REF.nokia.menu.setRsk(function(){
171 _BRIDGE_REF.nokia.menu.exit();
176 Function : Menu.showSoftkeys()
179 Description : Makes the softkeys visible. By default the softkeys are not visible
182 menu.showSoftkeys = function()
187 _BRIDGE_REF.nokia.menu.softkeys_visibility = true;
188 _BRIDGE_REF.nokia.menu.showSoftKeys();
192 Function : Menu.hideSoftkeys()
195 Description : Makes the softkeys invisible. By default the softkeys are not visible.
198 menu.hideSoftkeys = function()
203 _BRIDGE_REF.nokia.menu.softkeys_visibility = false;
204 _BRIDGE_REF.nokia.menu.hideSoftKeys();
210 * ----------------------------------------------------------------
211 * Exta Functionalities which helps to make main functions to work
212 * ----------------------------------------------------------------
216 menu.cancel = function()
218 _BRIDGE_REF.nokia.menu.cancel();
221 menu.exit = function()
223 _BRIDGE_REF.nokia.menu.exit();
227 menu.triggeLSKEvent = function()
229 if(typeof(window.menu.onShow) == 'function')
231 window.menu.onShow();
233 _BRIDGE_REF.parent.$('#softKeysPane').show();
237 menu.triggerEvent = function(MenuItemId)
240 var menuItemRef = this.menuItemExhistsById(this, MenuItemId, 0);
241 if(menuItemRef != null)
243 if(typeof menuItemRef.onSelect == 'function')
244 menuItemRef.onSelect(MenuItemId);
246 if(_BRIDGE_REF.helper.getElementsLengthInObject(menuItemRef.items))
247 this.show(MenuItemId);
258 alert('triggeEvent: '+MenuItemId+' >> '+e);
262 menu.hasChild = function(parentId)
264 for(var i in this.items)
266 if(this.items[i].parentId == parentId)
275 menu.allowedTypeOf = function(MenuItem)
279 if( (typeof(MenuItem) == 'object') && (MenuItem.type == 'MenuItem'))
288 menu.show = function(parentId)
292 var menuItemsPane = _BRIDGE_REF.parent.$('#MenuItemsArea')
293 menuItemsPane = menuItemsPane[0];
295 menuItemsPane.innerHTML = '';
297 var ul = document.createElement('ul');
298 var ele = window.menu;
300 if(typeof parentId != 'undefined' && typeof parentId == 'object')
302 if (typeof window.menu.onShow != null && typeof window.menu.onShow == 'function') {
303 window.menu.onShow();
307 if(typeof parentId == 'number')
309 var tempRef = menu.menuItemExhistsById(ele, parentId, 0);
311 if(typeof parentId != 'undefined' && typeof tempRef != 'undefined')
315 if(_BRIDGE_REF.helper.getElementsLengthInObject(ele.items))
317 for(var key in ele.items)
319 if(!ele.items[key].isDimmed){
322 ul.appendChild(menu.create_menuElement(ele.items[key]));
326 if(typeof parentId == 'number' && _BRIDGE_REF.helper.getElementsLengthInObject(ele.items))
329 ul.appendChild(menu.create_normalMenuItem('Back', ele.parent.id));
331 ul.appendChild(menu.create_normalMenuItem('Back', null));
335 ul.appendChild(menu.create_exitMenuItem());
339 if(_BRIDGE_REF.helper.getElementsLengthInObject(ele.items) > 5)
340 menuItemsPane.style.overflowY = 'scroll';
342 menuItemsPane.style.overflowY = 'hidden';
347 menuItemsPane.style.overflowY = 'hidden';
348 ul.appendChild(menu.create_exitMenuItem());
350 menuItemsPane.innerHTML = '<ul>'+ul.innerHTML+'</ul>';
352 _BRIDGE_REF.nokia.menu.show();
356 alert('menu.show: '+e);
368 menu.menuItemExhistsById = function(menuReference, value, argumentType)
372 for(var key in menuReference.items)
376 if(menuReference.items[key].id == value)
384 if(menuReference.items[key].name == value)
391 if(menuReference.items[key].items != undefined && menuReference.items[key].items.length)
393 var temp = this.menuItemExhistsById(menuReference.items[key], value, argumentType);
400 // crate a package and send it
401 menuReference.items[key].index = key;
402 return menuReference.items[key];
408 menu.create_menuElement = function(MenuItem)
410 var listitem = document.createElement('li');
411 listitem.id = MenuItem.id;
412 listitem.setAttribute('onClick', 'javascript:NOKIA.emulator.child.menu.triggerEvent('+MenuItem.id+');');
414 var anchor = document.createElement('a');
415 anchor.id = 'subMenuItem_'+MenuItem.id;
416 anchor.innerHTML = MenuItem.name;
417 if(_BRIDGE_REF.helper.getElementsLengthInObject(MenuItem.items))
419 anchor.className = 'subMenuItem';
420 anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.show('+MenuItem.id+');');
422 listitem.appendChild(anchor);
426 menu.create_normalMenuItem = function(MenuTitle, index)
428 var listitem = document.createElement('li');
430 var anchor = document.createElement('a');
431 anchor.id = 'subMenuItem_BACK';
432 anchor.innerHTML = MenuTitle;
434 if (MenuTitle == 'Back') {
435 listitem.className = 'exitOrBackBtn';
436 anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.triggerEvent(' + index + ');');
439 anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.triggerEvent(' + index + ');');
441 listitem.appendChild(anchor);
445 menu.create_exitMenuItem = function()
447 var listitem = document.createElement('li');
448 listitem.className = 'exitOrBackBtn';
449 var anchor = document.createElement('a');
450 anchor.id = 'subMenuItem_EXIT';
451 anchor.innerHTML = 'Exit';
452 anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.exit();');
453 listitem.setAttribute('onClick', 'javascript:NOKIA.emulator.child.menu.exit();');
455 listitem.appendChild(anchor);
459 menu.triggeRSK = function()
463 if (childToParent_Reference.$('softKeysPane').style.display != 'none') {
464 if (window.menu.onRightSoftKeySelect != null) {
465 window.menu.onRightSoftKeySelect();
466 window.menu.cancel();
469 window.menu.cancel();
479 menu.triggeLSK = function()
484 if(typeof(window.menu.onShow) == 'function')
486 if(window.menu.onShow)
488 window.menu.onShow();
495 // make TRUE menu.js script loaded
496 window.parent.NOKIA.scriptsLoaded.menu = true;