Only trigger immediate refresh if the tab has been hidden longer than refresh time, prevents refresh when clicking around between tabs.

This commit is contained in:
Nathan Gray 2014-02-11 20:59:07 +00:00
parent 5dec559f11
commit 3158cbf915

View File

@ -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 // 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) { $j(this.getInstanceManager().DOMContainer.parentNode).on('hide.et2_nextmatch', jQuery.proxy(function(e) {
// Stop
window.clearInterval(this._autorefresh_timer); window.clearInterval(this._autorefresh_timer);
delete this._autorefresh_timer;
$j(e.target).off(e); $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)); },this));
$j(this.getInstanceManager().DOMContainer.parentNode).on('show.et2_nextmatch', jQuery.proxy(function(e) { $j(this.getInstanceManager().DOMContainer.parentNode).on('show.et2_nextmatch', jQuery.proxy(function(e) {
// Start normal autorefresh timer again
this._set_autorefresh(this._get_autorefresh()); this._set_autorefresh(this._get_autorefresh());
$j(e.target).off(e); $j(e.target).off(e);
// Trigger an immediate refresh
this.refresh();
},this)); },this));
} }
}, },