From 9cd9f2202654dbaad8d75e079456e27547d98c66 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 10 Feb 2014 18:47:51 +0000 Subject: [PATCH] Use framework events to stop and start autorefresh if tab is hidden or shown --- etemplate/js/et2_extension_nextmatch.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index 2309bb2c76..a4c8ec601f 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -175,6 +175,12 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], * Destroys all */ destroy: function() { + // Stop autorefresh + if(this._autorefresh_timer) + { + window.clearInterval(this._autorefresh_timer); + } + // Free the grid components this.dataview.free(); this.rowProvider.free(); @@ -422,7 +428,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], */ refresh: function(_row_ids, _type) { // Framework trying to refresh, but nextmatch not fully initialized - if(this.controller === null) + if(this.controller === null || !this.div.is(':visible')) { return; } @@ -1290,6 +1296,19 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], if(time > 0) { this._autorefresh_timer = setInterval(jQuery.proxy(this.refresh, this), time * 1000); + + // 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) { + window.clearInterval(this._autorefresh_timer); + delete this._autorefresh_timer; + $j(e.target).off(e); + },this)); + $j(this.getInstanceManager().DOMContainer.parentNode).on('show.et2_nextmatch', jQuery.proxy(function(e) { + this._set_autorefresh(this._get_autorefresh()); + $j(e.target).off(e); + // Trigger an immediate refresh + this.refresh(); + },this)); } },