2022-04-06 02:48:31 +00:00
|
|
|
/* global RealtimePreview */
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @param {RealtimePreview} realtimePreview
|
|
|
|
* @param {OO.ui.ButtonWidget} reloadHoverButton
|
|
|
|
*/
|
|
|
|
function ManualWidget( realtimePreview, reloadHoverButton ) {
|
|
|
|
var config = {
|
|
|
|
classes: [ 'ext-WikiEditor-ManualWidget' ],
|
2022-04-21 08:00:03 +00:00
|
|
|
$element: $( '<a>' )
|
2022-04-06 02:48:31 +00:00
|
|
|
};
|
|
|
|
ManualWidget.super.call( this, config );
|
|
|
|
|
2022-04-21 08:00:03 +00:00
|
|
|
// Mixins.
|
|
|
|
OO.ui.mixin.AccessKeyedElement.call( this, {} );
|
|
|
|
OO.ui.mixin.ButtonElement.call( this, $.extend( {
|
|
|
|
$button: this.$element
|
|
|
|
}, config ) );
|
|
|
|
OO.ui.mixin.IconElement.call( this, { icon: 'reload' } );
|
|
|
|
OO.ui.mixin.TitledElement.call( this, {
|
|
|
|
title: mw.msg( 'wikieditor-realtimepreview-reload-title' )
|
|
|
|
} );
|
|
|
|
|
2022-04-06 02:48:31 +00:00
|
|
|
this.reloadHoverButton = reloadHoverButton;
|
|
|
|
|
|
|
|
// UI elements.
|
|
|
|
var $reloadLabel = $( '<span>' )
|
|
|
|
.text( mw.msg( 'wikieditor-realtimepreview-manual' ) );
|
2022-04-21 08:00:03 +00:00
|
|
|
var $reloadButton = $( '<span>' )
|
|
|
|
.addClass( 'ext-WikiEditor-realtimepreview-manual-reload' )
|
|
|
|
.text( mw.msg( 'wikieditor-realtimepreview-reload' ) );
|
|
|
|
this.connect( realtimePreview, {
|
|
|
|
click: function () {
|
|
|
|
if ( !this.isScreenWideEnough() ) {
|
|
|
|
// Do nothing if realtime preview is not visible.
|
|
|
|
return;
|
|
|
|
}
|
2022-05-06 16:21:34 +00:00
|
|
|
// Only refresh the preview if we're enabled.
|
|
|
|
if ( this.enabled ) {
|
|
|
|
this.doRealtimePreview();
|
2022-04-21 08:00:03 +00:00
|
|
|
}
|
2022-07-25 23:10:44 +00:00
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.reloadManual' ).fire( this );
|
2022-04-21 08:00:03 +00:00
|
|
|
}.bind( realtimePreview )
|
2022-04-06 02:48:31 +00:00
|
|
|
} );
|
2022-04-21 08:00:03 +00:00
|
|
|
this.$element.append( this.$icon, $reloadLabel, $reloadButton );
|
2022-04-06 02:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OO.inheritClass( ManualWidget, OO.ui.Widget );
|
2022-04-21 08:00:03 +00:00
|
|
|
OO.mixinClass( ManualWidget, OO.ui.mixin.AccessKeyedElement );
|
|
|
|
OO.mixinClass( ManualWidget, OO.ui.mixin.ButtonElement );
|
|
|
|
OO.mixinClass( ManualWidget, OO.ui.mixin.IconElement );
|
|
|
|
OO.mixinClass( ManualWidget, OO.ui.mixin.TitledElement );
|
2022-04-06 02:48:31 +00:00
|
|
|
|
|
|
|
ManualWidget.prototype.toggle = function ( show ) {
|
|
|
|
ManualWidget.parent.prototype.toggle.call( this, show );
|
|
|
|
if ( show ) {
|
|
|
|
this.reloadHoverButton.$element.remove();
|
|
|
|
// Use the same access key as the hover reload button, because this won't ever be displayed at the same time as that.
|
2022-04-21 08:00:03 +00:00
|
|
|
this.setAccessKey( mw.msg( 'accesskey-wikieditor-realtimepreview' ) );
|
2022-04-06 02:48:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ManualWidget;
|