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;
|
|
|
|
}
|
|
|
|
// Make sure the preview pane is visible.
|
|
|
|
if ( !this.enabled ) {
|
|
|
|
this.setEnabled();
|
|
|
|
}
|
|
|
|
this.doRealtimePreview();
|
|
|
|
}.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;
|