Module: nagvis Branch: nagvis-1.4 Commit: fa5a68feeb375068c9440dbc76617f50535f60f3 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/nagvis;a=commit;h=fa5a68feeb375068c9440dbc76617f50535f60f3
Author: Lars Michelsen <[email protected]> Date: Thu Sep 24 18:15:10 2009 +0200 #121 Fixed ticket by removing the context menu explicit on object remove from map and only creating a new context div when there is no one existing --- nagvis/nagvis/includes/js/NagVisObject.js | 15 ++++++++++----- nagvis/nagvis/includes/js/NagVisStatefulObject.js | 16 ++++++++++++---- nagvis/nagvis/includes/js/frontend.js | 4 ++-- nagvis/nagvis/includes/js/frontendContext.js | 7 +++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/nagvis/nagvis/includes/js/NagVisObject.js b/nagvis/nagvis/includes/js/NagVisObject.js index 89b866b..d5b9159 100644 --- a/nagvis/nagvis/includes/js/NagVisObject.js +++ b/nagvis/nagvis/includes/js/NagVisObject.js @@ -70,7 +70,7 @@ var NagVisObject = Base.extend({ * * @author Lars Michelsen <[email protected]> */ - getContextMenu: function (sContainerId, sObjId) { + getContextMenu: function (sObjId) { // Only enable context menu when configured if(this.conf.context_menu && this.conf.context_menu == '1') { // Writes template code to "this.context_template_code" @@ -80,11 +80,16 @@ var NagVisObject = Base.extend({ this.replaceContextTemplateMacros(); var oObj = document.getElementById(sObjId); - var oContainer = document.getElementById(sContainerId); + var oContainer = document.getElementById(this.conf.object_id); + + // Only create a new div when the context menu does not exist + var contextMenu = document.getElementById(this.conf.object_id+'-context'); + if(!contextMenu) { + // Create context menu div + var contextMenu = document.createElement('div'); + contextMenu.setAttribute('id', this.conf.object_id+'-context'); + } - // Create context menu div - var contextMenu = document.createElement('div'); - contextMenu.setAttribute('id', sObjId+'-context'); contextMenu.setAttribute('class', 'context'); contextMenu.setAttribute('className', 'context'); contextMenu.style.zIndex = '1000'; diff --git a/nagvis/nagvis/includes/js/NagVisStatefulObject.js b/nagvis/nagvis/includes/js/NagVisStatefulObject.js index 2d8cff5..70425d3 100644 --- a/nagvis/nagvis/includes/js/NagVisStatefulObject.js +++ b/nagvis/nagvis/includes/js/NagVisStatefulObject.js @@ -193,8 +193,7 @@ var NagVisStatefulObject = NagVisObject.extend({ remove: function () { if(this.parsedObject) { var oMap = document.getElementById('map'); - - // Remove event listeners + var oObj; if(this.conf.view_type && this.conf.view_type === 'line') { oObj = document.getElementById(this.conf.object_id+'-linediv'); @@ -203,12 +202,21 @@ var NagVisStatefulObject = NagVisObject.extend({ } if(oObj) { + // Remove event listeners oObj.onmousedown = null; oObj.oncontextmenu = null; oObj.onmouseover = null; oObj.onmouseout = null; oObj = null; } + + var oContext = document.getElementById(this.conf.object_id+'-context'); + // Remove context menu + // Needs to be removed after unsetting the eventhandlers + if(oContext) { + this.parsedObject.removeChild(oContext); + oContext = null; + } // Remove object from DOM oMap.removeChild(this.parsedObject); @@ -258,9 +266,9 @@ var NagVisStatefulObject = NagVisObject.extend({ // Add a context menu to the object when enabled if(this.conf.context_menu && this.conf.context_menu == '1') { if(this.conf.view_type && this.conf.view_type == 'line') { - this.getContextMenu(this.conf.object_id, this.conf.object_id+'-link'); + this.getContextMenu(this.conf.object_id+'-link'); } else { - this.getContextMenu(this.conf.object_id, this.conf.object_id+'-icon'); + this.getContextMenu(this.conf.object_id+'-icon'); } } }, diff --git a/nagvis/nagvis/includes/js/frontend.js b/nagvis/nagvis/includes/js/frontend.js index d3783c8..eb4f3df 100644 --- a/nagvis/nagvis/includes/js/frontend.js +++ b/nagvis/nagvis/includes/js/frontend.js @@ -537,7 +537,8 @@ function updateObjects(aMapObjectInformations, aObjs, sType) { aObjs[intIndex].parseHoverMenu(); // Reparse the context menu - // FIXME: Context menu is not available on the overview page + // The context menu only needs to be reparsed when the + // icon object has been reparsed if(sType === 'map') { aObjs[intIndex].parseContextMenu(); } else if(sType === 'overview') { @@ -1022,7 +1023,6 @@ function reparseMap(iMapCfgAge) { // Assign the hover templates to the objects and parse them parseHoverMenus(aMapObjects); - // Bulk get all context templates which are needed on the map getContextTemplates(aMapObjects); diff --git a/nagvis/nagvis/includes/js/frontendContext.js b/nagvis/nagvis/includes/js/frontendContext.js index fb6c35b..7cbed1a 100644 --- a/nagvis/nagvis/includes/js/frontendContext.js +++ b/nagvis/nagvis/includes/js/frontendContext.js @@ -132,6 +132,13 @@ function contextShow(event) { id = target.id; } + // Only the object id is interesing so remove the other contents + // like -icon or -line. Simply split the string by - and take the + // first element + var aId = id.split("-"); + id = aId[0]; + aId = null; + var contextMenu = document.getElementById(id+'-context'); // hide the menu first to avoid an "up-then-over" visual effect ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
