2021-11-18 10:50:17 +00:00
|
|
|
var ResizingDragBar = require( './ResizingDragBar.js' );
|
|
|
|
var TwoPaneLayout = require( './TwoPaneLayout.js' );
|
2022-03-23 03:28:12 +00:00
|
|
|
var ErrorLayout = require( './ErrorLayout.js' );
|
2022-04-06 02:48:31 +00:00
|
|
|
var ManualWidget = require( './ManualWidget.js' );
|
2023-03-17 07:22:32 +00:00
|
|
|
var localStorage = require( 'mediawiki.storage' ).local;
|
2021-11-18 10:50:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
function RealtimePreview() {
|
2022-03-18 18:08:32 +00:00
|
|
|
this.configData = mw.loader.moduleRegistry[ 'ext.wikiEditor' ].script.files[ 'data.json' ];
|
2022-03-31 05:03:18 +00:00
|
|
|
// Preference name, must match what's in extension.json and Hooks.php.
|
|
|
|
this.prefName = 'wikieditor-realtimepreview';
|
2022-04-19 23:34:14 +00:00
|
|
|
this.userPref = this.getUserPref();
|
|
|
|
this.enabled = this.userPref;
|
2021-11-18 10:50:17 +00:00
|
|
|
this.twoPaneLayout = new TwoPaneLayout();
|
|
|
|
this.pagePreview = require( 'mediawiki.page.preview' );
|
|
|
|
// @todo This shouldn't be required, but the preview element is added in PHP
|
2022-09-12 06:29:10 +00:00
|
|
|
// and can have attributes with values (such as `dir`) that aren't easily accessible from here,
|
2021-11-18 10:50:17 +00:00
|
|
|
// and we need to duplicate here what Live Preview does in core.
|
2022-09-12 06:29:10 +00:00
|
|
|
var $previewContent = $( '#wikiPreview .mw-content-ltr, #wikiPreview .mw-content-rtl' ).first().clone();
|
2021-11-18 10:50:17 +00:00
|
|
|
this.$previewNode = $( '<div>' )
|
|
|
|
.addClass( 'ext-WikiEditor-realtimepreview-preview' )
|
2023-07-12 12:36:31 +00:00
|
|
|
.attr( 'tabindex', '1' ) // T317108
|
2021-11-18 10:50:17 +00:00
|
|
|
.append( $previewContent );
|
2022-04-07 08:36:33 +00:00
|
|
|
|
|
|
|
// Loading bar.
|
2022-04-06 02:48:31 +00:00
|
|
|
this.$loadingBar = $( '<div>' ).addClass( 'ext-WikiEditor-realtimepreview-loadingbar' ).append( '<div>' );
|
2022-04-07 08:36:33 +00:00
|
|
|
this.$loadingBar.hide();
|
|
|
|
|
|
|
|
// Error layout.
|
2022-03-23 03:28:12 +00:00
|
|
|
this.errorLayout = new ErrorLayout();
|
|
|
|
this.errorLayout.getReloadButton().connect( this, {
|
2022-04-06 02:48:31 +00:00
|
|
|
click: function () {
|
2022-07-28 11:16:54 +00:00
|
|
|
this.doRealtimePreview( true );
|
2022-07-25 23:10:44 +00:00
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.reloadError' ).fire( this );
|
2022-04-06 02:48:31 +00:00
|
|
|
}.bind( this )
|
2022-03-23 03:28:12 +00:00
|
|
|
} );
|
2022-04-07 08:36:33 +00:00
|
|
|
|
2022-04-08 03:45:34 +00:00
|
|
|
// Manual reload button (visible on hover).
|
2022-04-21 03:16:13 +00:00
|
|
|
this.reloadButton = new OO.ui.ButtonWidget( {
|
2022-04-08 03:45:34 +00:00
|
|
|
classes: [ 'ext-WikiEditor-reloadButton' ],
|
|
|
|
icon: 'reload',
|
|
|
|
label: mw.msg( 'wikieditor-realtimepreview-reload' ),
|
|
|
|
accessKey: mw.msg( 'accesskey-wikieditor-realtimepreview' ),
|
|
|
|
title: mw.msg( 'wikieditor-realtimepreview-reload-title' )
|
|
|
|
} );
|
2022-04-21 03:16:13 +00:00
|
|
|
this.reloadButton.connect( this, {
|
2022-04-08 03:45:34 +00:00
|
|
|
click: function () {
|
2022-05-06 16:21:34 +00:00
|
|
|
// Only refresh the preview if we're enabled.
|
|
|
|
if ( this.enabled ) {
|
2022-06-27 12:58:27 +00:00
|
|
|
this.doRealtimePreview( true );
|
2022-04-08 03:45:34 +00:00
|
|
|
}
|
2022-07-25 23:10:44 +00:00
|
|
|
// Let other things happen after refreshing.
|
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.reloadHover' ).fire( this );
|
2022-04-08 03:45:34 +00:00
|
|
|
}.bind( this )
|
|
|
|
} );
|
|
|
|
|
2022-04-06 02:48:31 +00:00
|
|
|
// Manual mode widget.
|
2022-04-21 03:16:13 +00:00
|
|
|
this.manualWidget = new ManualWidget( this, this.reloadButton );
|
2022-08-12 21:49:14 +00:00
|
|
|
// Set up a property for reducedMotion — useful for customising the UI message.
|
|
|
|
this.reducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches;
|
|
|
|
// If the user has "prefers-reduced-motion" set, force us into manual mode.
|
|
|
|
this.inManualMode = this.reducedMotion;
|
2022-04-06 02:48:31 +00:00
|
|
|
|
2022-04-21 03:16:13 +00:00
|
|
|
this.twoPaneLayout.getPane2().append( this.manualWidget.$element, this.reloadButton.$element, this.$loadingBar, this.$previewNode, this.errorLayout.$element );
|
2021-11-18 10:50:17 +00:00
|
|
|
this.eventNames = 'change.realtimepreview input.realtimepreview cut.realtimepreview paste.realtimepreview';
|
2022-03-15 01:01:01 +00:00
|
|
|
// Used to ensure we wait for a response before making new requests.
|
|
|
|
this.isPreviewing = false;
|
|
|
|
this.previewPending = false;
|
2022-06-27 12:58:27 +00:00
|
|
|
this.lastWikitext = null;
|
2022-03-25 00:19:30 +00:00
|
|
|
// Used to average response times and automatically disable realtime preview if it's very slow.
|
|
|
|
this.responseTimes = [];
|
2021-11-18 10:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
* @param {Object} context The WikiEditor context.
|
2022-05-25 07:10:35 +00:00
|
|
|
* @return {jQuery}
|
2021-11-18 10:50:17 +00:00
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.getToolbarButton = function ( context ) {
|
|
|
|
this.context = context;
|
|
|
|
var $uiText = context.$ui.find( '.wikiEditor-ui-text' );
|
|
|
|
|
|
|
|
// Fix the height of the textarea, before adding a resizing bar below it.
|
|
|
|
var height = context.$textarea.height();
|
|
|
|
$uiText.css( 'height', height + 'px' );
|
|
|
|
context.$textarea.removeAttr( 'rows cols' );
|
2022-06-09 09:27:24 +00:00
|
|
|
context.$textarea.addClass( 'ext-WikiEditor-realtimepreview-textbox' );
|
2021-11-18 10:50:17 +00:00
|
|
|
|
|
|
|
// Add the resizing bar.
|
|
|
|
var bottomDragBar = new ResizingDragBar( { isEW: false } );
|
|
|
|
$uiText.after( bottomDragBar.$element );
|
|
|
|
|
|
|
|
// Create and configure the toolbar button.
|
|
|
|
this.button = new OO.ui.ToggleButtonWidget( {
|
|
|
|
label: mw.msg( 'wikieditor-realtimepreview-preview' ),
|
|
|
|
icon: 'article',
|
|
|
|
value: this.enabled,
|
2022-04-14 22:38:04 +00:00
|
|
|
framed: false,
|
2022-04-19 07:08:24 +00:00
|
|
|
// T305953; So we can find usage of this class later: .tool
|
|
|
|
classes: [ 'tool', 'ext-WikiEditor-realtimepreview-button' ]
|
2021-11-18 10:50:17 +00:00
|
|
|
} );
|
2022-04-19 23:34:14 +00:00
|
|
|
this.button.connect( this, { change: [ this.toggle, true ] } );
|
|
|
|
if ( !this.isScreenWideEnough() ) {
|
2022-09-16 00:04:40 +00:00
|
|
|
this.enabled = false;
|
2022-04-19 23:34:14 +00:00
|
|
|
this.button.toggle( false );
|
|
|
|
}
|
2022-05-25 07:10:35 +00:00
|
|
|
|
2022-07-07 05:04:28 +00:00
|
|
|
// Hide or show the preview and toolbar button when the window is resized.
|
|
|
|
$( window ).on( 'resize', this.enableFeatureWhenScreenIsWideEnough.bind( this ) );
|
|
|
|
|
2023-03-17 07:22:32 +00:00
|
|
|
// Remove the old onboarding-status storage that was discontinued in March 2023.
|
|
|
|
localStorage.remove( 'WikiEditor-RealtimePreview-onboarding-dismissed' );
|
2022-05-25 07:10:35 +00:00
|
|
|
|
2023-03-17 07:22:32 +00:00
|
|
|
return $( '<div>' ).append( this.button.$element );
|
2021-11-18 10:50:17 +00:00
|
|
|
};
|
|
|
|
|
2022-03-31 05:03:18 +00:00
|
|
|
/**
|
|
|
|
* Get the user preference for Realtime Preview.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.getUserPref = function () {
|
2022-04-19 23:34:14 +00:00
|
|
|
return ( typeof this.userPref !== 'undefined' ) ? this.userPref : mw.user.options.get( this.prefName ) > 0;
|
2022-03-31 05:03:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2022-05-03 05:18:05 +00:00
|
|
|
* Enable or disable Realtime Preview.
|
2022-03-31 05:03:18 +00:00
|
|
|
*
|
2022-05-03 05:18:05 +00:00
|
|
|
* @param {boolean} [enable=true] Whether to enable or disable.
|
|
|
|
* @param {boolean} [saveUserPref=true] Whether to save the user preference.
|
2022-03-31 05:03:18 +00:00
|
|
|
* @public
|
|
|
|
*/
|
2022-04-19 23:34:14 +00:00
|
|
|
RealtimePreview.prototype.setEnabled = function ( enable, saveUserPref ) {
|
2022-05-03 05:18:05 +00:00
|
|
|
// Set this.enabled to the opposite of what we want, and then toggle it to the desired state.
|
|
|
|
this.enabled = ( typeof enable === 'boolean' ) ? !enable : false;
|
2022-04-19 23:34:14 +00:00
|
|
|
this.toggle( saveUserPref );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the user preference for Realtime Preview.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.saveUserPref = function () {
|
|
|
|
this.userPref = this.enabled ? 1 : 0;
|
|
|
|
( new mw.Api() ).saveOption( this.prefName, this.userPref );
|
2022-03-31 05:03:18 +00:00
|
|
|
};
|
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
/**
|
|
|
|
* Toggle the two-pane preview display.
|
|
|
|
*
|
2022-05-03 05:18:05 +00:00
|
|
|
* @param {boolean} [saveUserPref=true] Whether to save the user preference.
|
2021-11-18 10:50:17 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2022-04-19 23:34:14 +00:00
|
|
|
RealtimePreview.prototype.toggle = function ( saveUserPref ) {
|
2021-11-18 10:50:17 +00:00
|
|
|
var $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
|
|
|
|
var $textarea = this.context.$textarea;
|
2022-06-28 12:15:54 +00:00
|
|
|
|
2022-07-19 19:00:21 +00:00
|
|
|
// Save the current cursor selection and focused element.
|
2022-06-28 12:15:54 +00:00
|
|
|
var cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
2022-07-19 19:00:21 +00:00
|
|
|
var focusedElement = document.activeElement;
|
2022-06-28 12:15:54 +00:00
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
// Remove or add the layout to the DOM.
|
|
|
|
if ( this.enabled ) {
|
|
|
|
// Move height from the TwoPaneLayout to the text UI div.
|
|
|
|
$uiText.css( 'height', this.twoPaneLayout.$element.height() + 'px' );
|
|
|
|
|
|
|
|
// Put the text div back to being after the layout, and then hide the layout.
|
|
|
|
this.twoPaneLayout.$element.after( $uiText );
|
|
|
|
this.twoPaneLayout.$element.hide();
|
|
|
|
|
|
|
|
// Remove the keyup handler.
|
|
|
|
$textarea.off( this.eventNames );
|
|
|
|
|
|
|
|
// Let other things happen after disabling.
|
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.disable' ).fire( this );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Add the layout before the text div of the UI and then move the text div into it.
|
|
|
|
$uiText.before( this.twoPaneLayout.$element );
|
|
|
|
this.twoPaneLayout.setPane1( $uiText );
|
|
|
|
this.twoPaneLayout.$element.show();
|
|
|
|
|
|
|
|
// Move explicit height from text-ui (which may have been set via manual resizing), to panes.
|
|
|
|
this.twoPaneLayout.$element.css( 'height', $uiText.height() + 'px' );
|
|
|
|
$uiText.css( 'height', '100%' );
|
|
|
|
|
2022-04-04 05:30:05 +00:00
|
|
|
// Load the preview when enabling,
|
|
|
|
this.doRealtimePreview();
|
|
|
|
// and also on keyup, change, paste etc.
|
|
|
|
$textarea
|
|
|
|
.off( this.eventNames )
|
|
|
|
.on( this.eventNames, this.getEventHandler() );
|
2021-11-18 10:50:17 +00:00
|
|
|
|
2022-04-06 02:48:31 +00:00
|
|
|
// Hide or show the manual-reload message bar.
|
|
|
|
this.manualWidget.toggle( this.inManualMode );
|
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
// Let other things happen after enabling.
|
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.enable' ).fire( this );
|
|
|
|
}
|
|
|
|
|
2022-06-28 12:15:54 +00:00
|
|
|
// Restore current selection.
|
2022-07-19 19:00:21 +00:00
|
|
|
$textarea.textSelection( 'setSelection', { start: cursorPos[ 0 ], end: cursorPos[ 1 ] } );
|
2022-07-26 01:05:53 +00:00
|
|
|
$textarea.textSelection( 'scrollToCaretPosition' );
|
2022-07-19 19:00:21 +00:00
|
|
|
// Focus on whatever had focus before, in case it wasn't the textarea.
|
|
|
|
focusedElement.focus();
|
2022-06-28 12:15:54 +00:00
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
// Record the toggle state and update the button.
|
|
|
|
this.enabled = !this.enabled;
|
2022-04-14 22:38:04 +00:00
|
|
|
this.button.$element.toggleClass( 'tool-active', this.enabled ); // T305953
|
2021-11-18 10:50:17 +00:00
|
|
|
this.button.setFlags( { progressive: this.enabled } );
|
2022-04-19 23:34:14 +00:00
|
|
|
|
|
|
|
if ( typeof saveUserPref === 'undefined' || ( typeof saveUserPref === 'boolean' && saveUserPref ) ) {
|
|
|
|
this.saveUserPref();
|
|
|
|
}
|
2021-11-18 10:50:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
2022-04-04 05:30:05 +00:00
|
|
|
* @return {Function}
|
2021-11-18 10:50:17 +00:00
|
|
|
*/
|
2022-04-04 05:30:05 +00:00
|
|
|
RealtimePreview.prototype.getEventHandler = function () {
|
|
|
|
return mw.util.debounce(
|
2022-04-06 02:48:31 +00:00
|
|
|
function () {
|
|
|
|
// Only do preview if we're not in manual mode (as set in this.checkResponseTimes()).
|
|
|
|
if ( !this.inManualMode ) {
|
|
|
|
this.doRealtimePreview();
|
|
|
|
}
|
|
|
|
}.bind( this ),
|
2022-04-04 05:30:05 +00:00
|
|
|
this.configData.realtimeDebounce
|
|
|
|
);
|
2021-11-18 10:50:17 +00:00
|
|
|
};
|
|
|
|
|
2022-04-19 23:34:14 +00:00
|
|
|
/**
|
|
|
|
* Check if screen meets minimum width requirement for Realtime Preview.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.isScreenWideEnough = function () {
|
|
|
|
return this.context.$ui.width() > 600;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display feature (buttons and functionality) only when screen is wide enough
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.enableFeatureWhenScreenIsWideEnough = function () {
|
|
|
|
var previewButtonIsVisible = this.button.isVisible();
|
|
|
|
var isScreenWideEnough = this.isScreenWideEnough();
|
|
|
|
if ( !isScreenWideEnough && previewButtonIsVisible ) {
|
|
|
|
this.button.toggle( false );
|
|
|
|
this.reloadButton.setDisabled( true );
|
|
|
|
if ( this.enabled ) {
|
2022-05-03 05:18:05 +00:00
|
|
|
this.setEnabled( false, false );
|
2022-04-19 23:34:14 +00:00
|
|
|
}
|
|
|
|
} else if ( isScreenWideEnough && !previewButtonIsVisible ) {
|
|
|
|
this.button.toggle( true );
|
|
|
|
this.reloadButton.setDisabled( false );
|
|
|
|
// if user preference and realtime disable
|
|
|
|
if ( !this.enabled && this.getUserPref() ) {
|
2022-05-03 05:18:05 +00:00
|
|
|
this.setEnabled( true, false );
|
2022-04-19 23:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-23 03:28:12 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {jQuery} $msg
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.showError = function ( $msg ) {
|
|
|
|
this.$previewNode.hide();
|
2022-04-26 08:12:36 +00:00
|
|
|
this.reloadButton.toggle( false );
|
2022-07-21 06:13:03 +00:00
|
|
|
this.manualWidget.toggle( false );
|
2022-03-23 03:28:12 +00:00
|
|
|
// There is no need for a default message because mw.Api.getErrorMessage() will
|
|
|
|
// always provide something (even for no network connection, server-side fatal errors, etc.).
|
|
|
|
this.errorLayout.setMessage( $msg );
|
|
|
|
this.errorLayout.toggle( true );
|
|
|
|
};
|
|
|
|
|
2022-03-25 00:19:30 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {number} time
|
|
|
|
*/
|
|
|
|
RealtimePreview.prototype.checkResponseTimes = function ( time ) {
|
2022-07-21 06:13:03 +00:00
|
|
|
// Don't track response times if we're already in manual mode or an error is shown.
|
|
|
|
if ( this.inManualMode || this.errorLayout.isVisible() ) {
|
2022-04-06 02:48:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-25 00:19:30 +00:00
|
|
|
this.responseTimes.push( Date.now() - time );
|
|
|
|
if ( this.responseTimes.length < 3 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var totalResponseTime = this.responseTimes.reduce( function ( a, b ) {
|
|
|
|
return a + b;
|
|
|
|
}, 0 );
|
|
|
|
|
|
|
|
if ( ( totalResponseTime / this.responseTimes.length ) > this.configData.realtimeDisableDuration ) {
|
2022-04-06 02:48:31 +00:00
|
|
|
this.inManualMode = true;
|
|
|
|
this.manualWidget.toggle( true );
|
2022-07-25 23:10:44 +00:00
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.stop' ).fire( this );
|
2022-03-25 00:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.responseTimes.shift();
|
|
|
|
};
|
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
/**
|
|
|
|
* @private
|
2022-06-27 12:58:27 +00:00
|
|
|
* @param {boolean} forceUpdate For the preview to update, even if the wikitext is unchanged,
|
|
|
|
* e.g. when the user presses the 'reload' button.
|
2021-11-18 10:50:17 +00:00
|
|
|
*/
|
2022-06-27 12:58:27 +00:00
|
|
|
RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
2022-03-15 01:01:01 +00:00
|
|
|
// Wait for a response before making any new requests.
|
|
|
|
if ( this.isPreviewing ) {
|
|
|
|
// Queue up one final preview once this one finishes.
|
|
|
|
this.previewPending = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-27 12:58:27 +00:00
|
|
|
var $textareaNode = $( '#wpTextbox1' );
|
|
|
|
var wikitext = $textareaNode.textSelection( 'getContents' );
|
|
|
|
if ( !forceUpdate && wikitext === this.lastWikitext ) {
|
|
|
|
// Wikitext unchanged, no update necessary
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.lastWikitext = wikitext;
|
|
|
|
|
2022-03-15 01:01:01 +00:00
|
|
|
this.isPreviewing = true;
|
2022-04-07 08:36:33 +00:00
|
|
|
this.$loadingBar.show();
|
2022-04-29 13:15:10 +00:00
|
|
|
this.$previewNode.show();
|
2022-04-21 03:16:13 +00:00
|
|
|
this.reloadButton.setDisabled( true );
|
2022-04-21 08:00:03 +00:00
|
|
|
this.manualWidget.setDisabled( true );
|
2022-04-29 13:15:10 +00:00
|
|
|
this.errorLayout.toggle( false );
|
2023-09-13 09:09:42 +00:00
|
|
|
var loadingSelectors = this.pagePreview.getLoadingSelectors()
|
|
|
|
// config.$previewNode below is a clone of #wikiPreview with a different selector!
|
|
|
|
// config.$diffNode defaults to #wikiDiff but is disabled below and never updated.
|
|
|
|
.filter( function ( selector ) {
|
|
|
|
return selector.indexOf( '#wiki' ) !== 0;
|
|
|
|
} );
|
2021-11-18 10:50:17 +00:00
|
|
|
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-preview' );
|
2022-04-29 13:15:10 +00:00
|
|
|
loadingSelectors.push( '.ext-WikiEditor-ManualWidget' );
|
|
|
|
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-ErrorLayout' );
|
2022-03-25 00:19:30 +00:00
|
|
|
var time = Date.now();
|
|
|
|
|
2021-11-18 10:50:17 +00:00
|
|
|
this.pagePreview.doPreview( {
|
2022-06-27 12:58:27 +00:00
|
|
|
$textareaNode: $textareaNode,
|
2021-11-18 10:50:17 +00:00
|
|
|
$previewNode: this.$previewNode,
|
|
|
|
$spinnerNode: false,
|
2022-07-06 20:34:52 +00:00
|
|
|
loadingSelectors: loadingSelectors,
|
|
|
|
// Don't hide the diff view, if visible.
|
|
|
|
$diffNode: null
|
2022-04-29 13:15:10 +00:00
|
|
|
} ).done( function () {
|
|
|
|
this.errorLayout.toggle( false );
|
|
|
|
}.bind( this ) ).fail( function ( code, result ) {
|
2022-03-23 03:28:12 +00:00
|
|
|
this.showError( ( new mw.Api() ).getErrorMessage( result ) );
|
2022-03-21 06:25:31 +00:00
|
|
|
mw.log.error( 'WikiEditor realtime preview error', result );
|
2021-11-18 10:50:17 +00:00
|
|
|
}.bind( this ) ).always( function () {
|
2022-04-07 08:36:33 +00:00
|
|
|
this.$loadingBar.hide();
|
2022-04-21 03:16:13 +00:00
|
|
|
this.reloadButton.setDisabled( false );
|
2022-04-26 08:12:36 +00:00
|
|
|
if ( !this.errorLayout.isVisible() ) {
|
|
|
|
// Only re-show the reload button if no error message is currently showing.
|
|
|
|
this.reloadButton.toggle( true );
|
|
|
|
}
|
2022-07-28 02:35:26 +00:00
|
|
|
// Show the manual mode if applicable (but not if an error is displayed).
|
|
|
|
this.manualWidget.toggle( this.inManualMode && !this.errorLayout.isVisible() );
|
2022-04-21 08:00:03 +00:00
|
|
|
this.manualWidget.setDisabled( false );
|
2022-03-15 01:01:01 +00:00
|
|
|
this.isPreviewing = false;
|
2022-03-25 00:19:30 +00:00
|
|
|
this.checkResponseTimes( time );
|
2022-03-15 01:01:01 +00:00
|
|
|
|
|
|
|
if ( this.previewPending ) {
|
|
|
|
this.previewPending = false;
|
|
|
|
this.doRealtimePreview();
|
|
|
|
}
|
2022-08-03 23:02:17 +00:00
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.loaded' ).fire( this );
|
2021-11-18 10:50:17 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RealtimePreview;
|