From 0ada93ea75c78b96b24f3e9d0eb7e8e53b8ee3b3 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Sat, 23 Feb 2013 14:02:19 +0100 Subject: [PATCH] merge parts of #236 (by ShawnTuatara) --- code/hooks.js | 12 +++++++++++- code/map_data.js | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/code/hooks.js b/code/hooks.js index 43f4cc35..a2b81b68 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -11,7 +11,7 @@ // // Boot hook: booting is handled differently because IITC may not yet // be available. Have a look at the plugins in plugins/. All -// code before “// PLUGIN START” and after “// PLUGIN END” os +// code before “// PLUGIN START” and after “// PLUGIN END” is // required to successfully boot the plugin. // // Here’s more specific information about each event: @@ -36,6 +36,16 @@ // array [GUID, time, details]. Plugin can manipulate the // array to change order or add additional values to the // details of a portal. +// beforePortalReRender: the callback argument is +// {portal: ent[2], oldPortal : d, reRender : false}. +// The callback needs to update the value of reRender to +// true if the plugin has a reason to have the portal +// redrawn. It is called early on in the +// code/map_data.js#renderPortal as long as there was an +// old portal for the guid. + + + window._hooks = {} window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated', diff --git a/code/map_data.js b/code/map_data.js index 6729c0f0..a28af7b4 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -127,7 +127,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { // Preserve and restore "selectedPortal" between portal re-render if(portalUpdateAvailable) var oldSelectedPortal = selectedPortal; - + runHooks('portalDataLoaded', {portals : ppp}); $.each(ppp, function(ind, portal) { renderPortal(portal); }); @@ -231,8 +231,16 @@ window.renderPortal = function(ent) { var old = findEntityInLeaflet(layerGroup, window.portals, ent[0]); if(old) { var oo = old.options; + + // Default checks to see if a portal needs to be re-rendered var u = oo.team !== team; u = u || oo.level !== portalLevel; + + // Allow plugins to add additional conditions as to when a portal gets re-rendered + var hookData = {portal: ent[2], oldPortal: oo.details, reRender: false}; + runHooks('beforePortalReRender', hookData); + u = u || hookData.reRender; + // nothing changed that requires re-rendering the portal. if(!u) { // let resos handle themselves if they need to be redrawn