From 3158cbf9153f517682e9a0bb5ffb0249c7e8eba0 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 11 Feb 2014 20:59:07 +0000 Subject: [PATCH] Only trigger immediate refresh if the tab has been hidden longer than refresh time, prevents refresh when clicking around between tabs. --- etemplate/js/et2_extension_nextmatch.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index a4c8ec601f..f7a1ebf36d 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -1299,15 +1299,24 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], // Bind to tab show/hide events, so that we don't bother refreshing in the background $j(this.getInstanceManager().DOMContainer.parentNode).on('hide.et2_nextmatch', jQuery.proxy(function(e) { + // Stop window.clearInterval(this._autorefresh_timer); - delete this._autorefresh_timer; $j(e.target).off(e); + + // If the autorefresh time is up, bind once to trigger a refresh + // (if needed) when tab is activated again + this._autorefresh_timer = setTimeout(jQuery.proxy(function() { + $j(this.getInstanceManager().DOMContainer.parentNode).one('show.et2_nextmatch', + // Important to use anonymous function instead of just 'this.refresh' because + // of the parameters passed + jQuery.proxy(function() {this.refresh();},this) + ); + },this), time*1000); },this)); $j(this.getInstanceManager().DOMContainer.parentNode).on('show.et2_nextmatch', jQuery.proxy(function(e) { + // Start normal autorefresh timer again this._set_autorefresh(this._get_autorefresh()); $j(e.target).off(e); - // Trigger an immediate refresh - this.refresh(); },this)); } },