mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-14 19:31:55 +00:00
RealtimePreview: Don't update when wikitext is unmodified
Bug: T311406 Change-Id: I29afb5b7740ec26f3ba9c435729d9df0df46bf8b
This commit is contained in:
parent
06035ab6b9
commit
7f768f748a
|
@ -51,7 +51,7 @@ function RealtimePreview() {
|
|||
click: function () {
|
||||
// Only refresh the preview if we're enabled.
|
||||
if ( this.enabled ) {
|
||||
this.doRealtimePreview();
|
||||
this.doRealtimePreview( true );
|
||||
}
|
||||
}.bind( this )
|
||||
} );
|
||||
|
@ -65,6 +65,7 @@ function RealtimePreview() {
|
|||
// Used to ensure we wait for a response before making new requests.
|
||||
this.isPreviewing = false;
|
||||
this.previewPending = false;
|
||||
this.lastWikitext = null;
|
||||
// Used to average response times and automatically disable realtime preview if it's very slow.
|
||||
this.responseTimes = [];
|
||||
|
||||
|
@ -293,8 +294,10 @@ RealtimePreview.prototype.checkResponseTimes = function ( time ) {
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @param {boolean} forceUpdate For the preview to update, even if the wikitext is unchanged,
|
||||
* e.g. when the user presses the 'reload' button.
|
||||
*/
|
||||
RealtimePreview.prototype.doRealtimePreview = function () {
|
||||
RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
||||
// Wait for a response before making any new requests.
|
||||
if ( this.isPreviewing ) {
|
||||
// Queue up one final preview once this one finishes.
|
||||
|
@ -302,6 +305,14 @@ RealtimePreview.prototype.doRealtimePreview = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
var $textareaNode = $( '#wpTextbox1' );
|
||||
var wikitext = $textareaNode.textSelection( 'getContents' );
|
||||
if ( !forceUpdate && wikitext === this.lastWikitext ) {
|
||||
// Wikitext unchanged, no update necessary
|
||||
return;
|
||||
}
|
||||
this.lastWikitext = wikitext;
|
||||
|
||||
this.isPreviewing = true;
|
||||
this.$loadingBar.show();
|
||||
this.$previewNode.show();
|
||||
|
@ -315,6 +326,7 @@ RealtimePreview.prototype.doRealtimePreview = function () {
|
|||
var time = Date.now();
|
||||
|
||||
this.pagePreview.doPreview( {
|
||||
$textareaNode: $textareaNode,
|
||||
$previewNode: this.$previewNode,
|
||||
$spinnerNode: false,
|
||||
loadingSelectors: loadingSelectors
|
||||
|
|
Loading…
Reference in a new issue