From 063ae2d65b39b7571a008b83e0322d37a5b15150 Mon Sep 17 00:00:00 2001 From: Lisa Wagner Date: Tue, 10 Nov 2015 10:38:09 +0100 Subject: [PATCH] #33 adding check for repeated 'newResults' event --- SearchResultListVis/js/msgListeners.js | 38 ++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/SearchResultListVis/js/msgListeners.js b/SearchResultListVis/js/msgListeners.js index bdfa022..94a94d5 100644 --- a/SearchResultListVis/js/msgListeners.js +++ b/SearchResultListVis/js/msgListeners.js @@ -1,3 +1,5 @@ +var lastProcessedQueryID; + window.onmessage = function (msg) { if (msg.data.event) { if (msg.data.event === 'eexcess.queryTriggered') { @@ -5,29 +7,31 @@ window.onmessage = function (msg) { $(showLoadingBar()); } - else if (msg.data.event === 'eexcess.newResults') { + if (msg.data.event && msg.data.event === 'eexcess.newResults') { // new results are available in msg.data.data - - $(addIsotopeGrid(msg)); - $(logResultItemClicks(msg)); - - //make sure elements exist - var checkExist = setInterval(function() { - if ($('.eexcess-isotope-grid-item').length) { - clearInterval(checkExist); - $(addFilterCounter); - $(truncateTitles); - } - }, 10); + if (lastProcessedQueryID && lastProcessedQueryID === msg.data.data.queryID) { + // data already processed, do nothing + } else { + $(addIsotopeGrid(msg)); + $(logResultItemClicks(msg)); + + //make sure elements exist + var checkExist = setInterval(function () { + if ($('.eexcess-isotope-grid-item').length) { + clearInterval(checkExist); + $(addFilterCounter); + $(truncateTitles); + } + }, 10); + + lastProcessedQueryID = msg.data.data.queryID; + } } else if (msg.data.event === 'eexcess.error') { $(showError(msg.data.data)); } - } - - - + } }