diff -r 5e0dece09f96 -r 07ac2f6a36a9 Symbian.org/preview/script/lib/menu.js --- a/Symbian.org/preview/script/lib/menu.js Mon Jul 13 10:42:26 2009 +0100 +++ b/Symbian.org/preview/script/lib/menu.js Tue Jul 21 12:16:25 2009 +0100 @@ -1,492 +1,497 @@ -/* - Function : menu() - Argument : Void - Returns : Void - Description : Constructor Function creates a Menu object to the WINDOW -*/ +/** + * widget object constructor + * @param {void} + * widget() + * @return {void} + */ -function Menu() +if (typeof window.menu == "undefined" || !window.menu) { - this.items = Array(); - this.index = null; - this.isDimmed = false; - - // Event triggers - this.onShow = null; - this.onRightSoftKeySelect = null; - - // Flag for Menu softkeys disabled to show - this.is_sfk_disabled = false; -} - - -/* - Function : menu.append() - Argument : MenuItem Object - Returns : Void - Description : Function appends MenuItem to a Menu Object -*/ -Menu.prototype.append = function(MenuItem) -{ - if(this.allowedTypeOf(MenuItem)) + window.menu = { - var i; - var flag = true; - try{ - for(i=0; i a")[0].innerHTML = label; + _BRIDGE_REF.nokia.menu.rsk_label = label; + _BRIDGE_REF.nokia.menu.rsk_event = callback; + _BRIDGE_REF.nokia.menu.is_rsk_overridden = true; + } + else + this.setExitToRsk(); + + }catch(e){ + // alert(e); + } + } -/* - Function : Menu.getMenuItemById(id) - Argument : Integer - Returns : MenuItem Object - Description : Function get the MenuItem Object with the reference of id -*/ -Menu.prototype.getMenuItemById = function(id) -{ - var menuItemRef = menuItemExhistsById(this, id, 0); - if(this.allowedTypeOf(menuItemRef)) - return menuItemRef; - else - return undefined; -} + menu.setExitToRsk = function() + { + this.onRightSoftKeySelect = null; + + _BRIDGE_REF.nokia.menu.is_rsk_overridden = false; + _BRIDGE_REF.nokia.menu.rsk_label = ''; + _BRIDGE_REF.nokia.menu.rsk_event = null; + _BRIDGE_REF.parent.$("#RskLabel > a")[0].innerHTML = 'Exit'; + + _BRIDGE_REF.nokia.menu.setRsk(function(){ + _BRIDGE_REF.nokia.menu.exit(); + }); + } + + /* + Function : Menu.showSoftkeys() + Argument : Void + Returns : Void + Description : Makes the softkeys visible. By default the softkeys are not visible + + */ + menu.showSoftkeys = function() + { + /* + * Shows showSoftkeys + */ + _BRIDGE_REF.nokia.menu.softkeys_visibility = true; + _BRIDGE_REF.nokia.menu.showSoftKeys(); + } + + /* + Function : Menu.hideSoftkeys() + Argument : Void + Returns : Void + Description : Makes the softkeys invisible. By default the softkeys are not visible. + + */ + menu.hideSoftkeys = function() + { + /* + * Hide showSoftkeys + */ + _BRIDGE_REF.nokia.menu.softkeys_visibility = false; + _BRIDGE_REF.nokia.menu.hideSoftKeys(); + } + + + /* + * + * ---------------------------------------------------------------- + * Exta Functionalities which helps to make main functions to work + * ---------------------------------------------------------------- + * + */ + + menu.cancel = function() + { + _BRIDGE_REF.nokia.menu.cancel(); + } + + menu.exit = function() + { + _BRIDGE_REF.nokia.menu.exit(); + } + + + menu.triggeLSKEvent = function() + { + if(typeof(window.menu.onShow) == 'function') + { + window.menu.onShow(); + } + _BRIDGE_REF.parent.$('#softKeysPane').show(); + this.show(); + } + + menu.triggerEvent = function(MenuItemId) + { + try{ + var menuItemRef = this.menuItemExhistsById(this, MenuItemId, 0); + if(menuItemRef != null) + { + if(typeof menuItemRef.onSelect == 'function') + menuItemRef.onSelect(MenuItemId); + + if(_BRIDGE_REF.helper.getElementsLengthInObject(menuItemRef.items)) + this.show(MenuItemId); + else + this.cancel(); + + }else + { + this.show(); + } + } + catch(e) + { + alert('triggeEvent: '+MenuItemId+' >> '+e); + } + } + + menu.hasChild = function(parentId) + { + for(var i in this.items) + { + if(this.items[i].parentId == parentId) + { + return true; + } + } + return false; + } + + + menu.allowedTypeOf = function(MenuItem) + { + try + { + if( (typeof(MenuItem) == 'object') && (MenuItem.type == 'MenuItem')) + return true; + } + catch(e) + { + return false; + } + } + + menu.show = function(parentId) + { + try + { + var menuItemsPane = _BRIDGE_REF.parent.$('#MenuItemsArea') + menuItemsPane = menuItemsPane[0]; + + menuItemsPane.innerHTML = ''; + + var ul = document.createElement('ul'); + var ele = window.menu; + + if(typeof parentId != 'undefined' && typeof parentId == 'object') + { + if (typeof window.menu.onShow != null && typeof window.menu.onShow == 'function') { + window.menu.onShow(); + } + } + + if(typeof parentId == 'number') + { + var tempRef = menu.menuItemExhistsById(ele, parentId, 0); + + if(typeof parentId != 'undefined' && typeof tempRef != 'undefined') + ele = tempRef; + } + + if(_BRIDGE_REF.helper.getElementsLengthInObject(ele.items)) + { + for(var key in ele.items) + { + if(!ele.items[key].isDimmed){ + + try{ + ul.appendChild(menu.create_menuElement(ele.items[key])); + }catch(e){ } + } + } + if(typeof parentId == 'number' && _BRIDGE_REF.helper.getElementsLengthInObject(ele.items)) + { + if(ele.parent) + ul.appendChild(menu.create_normalMenuItem('Back', ele.parent.id)); + else + ul.appendChild(menu.create_normalMenuItem('Back', null)); + } + else + { + ul.appendChild(menu.create_exitMenuItem()); + } + + + if(_BRIDGE_REF.helper.getElementsLengthInObject(ele.items) > 5) + menuItemsPane.style.overflowY = 'scroll'; + else + menuItemsPane.style.overflowY = 'hidden'; + + } + else + { + menuItemsPane.style.overflowY = 'hidden'; + ul.appendChild(menu.create_exitMenuItem()); + } + menuItemsPane.innerHTML = ''; + + _BRIDGE_REF.nokia.menu.show(); + } + catch(e) + { + alert('menu.show: '+e); + } + } + /* - Function : Menu.getMenuItemByName(name) - Argument : String - Returns : MenuItem Object - Description : Function get the MenuItem Object with the reference of String name -*/ -Menu.prototype.getMenuItemByName = function(name) -{ - var menuItemRef = menuItemExhistsById(this, name, 1); - -// if(menuItemRef !=null) - if(this.allowedTypeOf(menuItemRef)) - return menuItemRef; - else - return undefined; -} - -/* - Function : Menu.setRightSoftkeyLabel() - Argument : String, Function - Returns : Void - Description : Set the label of the right soft key to str. This enables the default text - to be changed from �exit� and a new function assigned by setting a callbackfunction -*/ -Menu.prototype.setRightSoftkeyLabel = function(label, callbackfunction) -{ - window.menu = this; - - try - { - var rightSoftKey = childToParent_Reference.$('rightSoftKey'); - if(typeof(callbackfunction) == 'function') - { - rightSoftKey.innerHTML = label; - - this.onRightSoftKeySelect = callbackfunction; - rightSoftKey.setAttribute('onClick', 'javascript:Emulator.triggerChildRSK();'); - } - else - { - rightSoftKey.innerHTML = "Cancel"; - this.onRightSoftKeySelect = null; - rightSoftKey.setAttribute('onClick', 'javascript:Emulator.triggerChildRSK();'); - } - }catch(e){ } -} - -/* - Function : Menu.showSoftkeys() - Argument : Void - Returns : Void - Description : Makes the softkeys visible. By default the softkeys are not visible - -*/ -Menu.prototype.showSoftkeys = function() -{ - /* - * Shows showSoftkeys - */ - this.is_sfk_disabled = false; - childToParent_Reference.Emulator.showDeviceSoftKeys(); -} - -/* - Function : Menu.hideSoftkeys() - Argument : Void - Returns : Void - Description : Makes the softkeys invisible. By default the softkeys are not visible. - -*/ -Menu.prototype.hideSoftkeys = function() -{ - /* - * Hide showSoftkeys - */ - this.is_sfk_disabled = true; - childToParent_Reference.Emulator.hideDeviceSoftKeys(); -} - - -/* - * - * ---------------------------------------------------------------- - * Exta Functionalities which helps to make main functions to work - * ---------------------------------------------------------------- - * +* +* HELPER FUNCTIONS +* */ -Menu.prototype.cancel = function() -{ - /* - * Clear menu and Exit the widget - */ - - childToParent_Reference.$('menuItemsPane').innerHTML = ''; - childToParent_Reference.$('menuItemsPane').style.display = 'none'; - - if(this.is_sfk_disabled) - childToParent_Reference.Emulator.hideDeviceSoftKeys(); -} - -Menu.prototype.exit = function() -{ - /* - * Clear menu and Exit the widget - */ - - childToParent_Reference.$('menuItemsPane').innerHTML = ''; - childToParent_Reference.$('menuItemsPane').style.display = 'none'; - - if(childToParent_Reference.Emulator.showSoftKeys_disabled) - childToParent_Reference.$('menuPane').style.display = 'none'; - - // call the Parent function - childToParent_Reference.Emulator.triggerExit(); -} - - -Menu.prototype.showMenu = function(parentId) -{ - try{ - var menuItemsPane = childToParent_Reference.$('menuItemsPane') - menuItemsPane.innerHTML = ''; - - var menuPane = childToParent_Reference.$('menuPane'); - menuPane.style.display = 'block'; - - var ul = document.createElement('ul'); - var ele = this; - if(parentId) + menu.menuItemExhistsById = function(menuReference, value, argumentType) { - ele = menuItemExhistsById(ele, parentId, 0); - } - if(ele.items.length) - { - for(var i=0; i 1) - menuItemsPane.style.overflowY = 'scroll'; - else - menuItemsPane.style.overflowY = 'hidden'; - } - else - { - menuItemsPane.style.overflowY = 'hidden'; - ul.appendChild(createExitMenuElement()); + return null; } - menuItemsPane.innerHTML = ''; - /* - * Set the MenuKeys DIV style.top - */ - childToParent_Reference.Emulator.showDeviceSoftKeys(); - } - catch(e) + + menu.create_menuElement = function(MenuItem) { - alert('showMenu: '+e); - } -} - -Menu.prototype.triggeLeftSoftKeyEvent = function() -{ - if(typeof(window.menu.onShow) == 'function') - { - window.menu.onShow(); + var listitem = document.createElement('li'); + listitem.id = MenuItem.id; + listitem.setAttribute('onClick', 'javascript:NOKIA.emulator.child.menu.triggerEvent('+MenuItem.id+');'); + + var anchor = document.createElement('a'); + anchor.id = 'subMenuItem_'+MenuItem.id; + anchor.innerHTML = MenuItem.name; + if(_BRIDGE_REF.helper.getElementsLengthInObject(MenuItem.items)) + { + anchor.className = 'subMenuItem'; + anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.show('+MenuItem.id+');'); + } + listitem.appendChild(anchor); + return (listitem); } - childToParent_Reference.$('softKeysPane').style.display = 'block'; - this.showMenu(); -} - -Menu.prototype.triggeEvent = function(MenuItemId) -{ - try{ - var menuItemRef = menuItemExhistsById(this, MenuItemId, 0); - if(menuItemRef != null) - { - if(typeof menuItemRef.onSelect == 'function') - menuItemRef.onSelect(MenuItemId); + + menu.create_normalMenuItem = function(MenuTitle, index) + { + var listitem = document.createElement('li'); + + var anchor = document.createElement('a'); + anchor.id = 'subMenuItem_BACK'; + anchor.innerHTML = MenuTitle; + + if (MenuTitle == 'Back') { + listitem.className = 'exitOrBackBtn'; + anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.triggerEvent(' + index + ');'); + } + else + anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.triggerEvent(' + index + ');'); + + listitem.appendChild(anchor); + return (listitem); + } - if(menuItemRef.items.length) - this.showMenu(MenuItemId); - else - this.cancel(); - } - } - catch(e) + menu.create_exitMenuItem = function() { - alert('triggeEvent: '+MenuItemId+' >> '+e); + var listitem = document.createElement('li'); + listitem.className = 'exitOrBackBtn'; + var anchor = document.createElement('a'); + anchor.id = 'subMenuItem_EXIT'; + anchor.innerHTML = 'Exit'; + anchor.setAttribute('href', 'javascript:NOKIA.emulator.child.menu.exit();'); + listitem.setAttribute('onClick', 'javascript:NOKIA.emulator.child.menu.exit();'); + + listitem.appendChild(anchor); + return (listitem); } -} - -Menu.prototype.hasChild = function(parentId) -{ - for(var i=0; i