|
271 | 271 | this._trackHighlight( 'clear', filterName ); |
272 | 272 | }; |
273 | 273 |
|
| 274 | +/** |
| 275 | + * Enable or disable live updates. |
| 276 | + * @param {boolean} enable True to enable, false to disable |
| 277 | + */ |
| 278 | +mw.rcfilters.Controller.prototype.toggleLiveUpdate = function ( enable ) { |
| 279 | +if ( enable && !this.liveUpdateTimeout ) { |
| 280 | +this._scheduleLiveUpdate(); |
| 281 | +} else if ( !enable && this.liveUpdateTimeout ) { |
| 282 | +clearTimeout( this.liveUpdateTimeout ); |
| 283 | +this.liveUpdateTimeout = null; |
| 284 | +} |
| 285 | +}; |
| 286 | + |
| 287 | +/** |
| 288 | + * Set a timeout for the next live update. |
| 289 | + * @private |
| 290 | + */ |
| 291 | +mw.rcfilters.Controller.prototype._scheduleLiveUpdate = function () { |
| 292 | +this.liveUpdateTimeout = setTimeout( this._doLiveUpdate.bind( this ), 3000 ); |
| 293 | +}; |
| 294 | + |
| 295 | +/** |
| 296 | + * Perform a live update. |
| 297 | + * @private |
| 298 | + */ |
| 299 | +mw.rcfilters.Controller.prototype._doLiveUpdate = function () { |
| 300 | +var controller = this; |
| 301 | +this.updateChangesList( {}, true ) |
| 302 | +.always( function () { |
| 303 | +if ( controller.liveUpdateTimeout ) { |
| 304 | +// Live update was not disabled in the meantime |
| 305 | +controller._scheduleLiveUpdate(); |
| 306 | +} |
| 307 | +} ); |
| 308 | +}; |
| 309 | + |
274 | 310 | /** |
275 | 311 | * Save the current model state as a saved query |
276 | 312 | * |
|
555 | 591 | * Update the list of changes and notify the model |
556 | 592 | * |
557 | 593 | * @param {Object} [params] Extra parameters to add to the API call |
| 594 | + * @param {boolean} [isLiveUpdate] Don't update the URL or invalidate the changes list |
| 595 | + * @return {jQuery.Promise} Promise that is resolved when the update is complete |
558 | 596 | */ |
559 | | -mw.rcfilters.Controller.prototype.updateChangesList = function ( params ) { |
560 | | -this._updateURL( params ); |
561 | | -this.changesListModel.invalidate(); |
562 | | -this._fetchChangesList() |
| 597 | +mw.rcfilters.Controller.prototype.updateChangesList = function ( params, isLiveUpdate ) { |
| 598 | +if ( !isLiveUpdate ) { |
| 599 | +this._updateURL( params ); |
| 600 | +this.changesListModel.invalidate(); |
| 601 | +} |
| 602 | +return this._fetchChangesList() |
563 | 603 | .then( |
564 | 604 | // Success |
565 | 605 | function ( pieces ) { |
|
0 commit comments