Debian Codegraph @

extensions/WikiEditor/modules/realtimepreview/ManualWidget.js

raw symbols SCIP
1 /* global RealtimePreview */
2 /**
3 * @class
4 * @constructor
5 * @param {RealtimePreview} realtimePreview
6 * @param {OO.ui.ButtonWidget} reloadHoverButton
7 */
8 function ManualWidget( realtimePreview, reloadHoverButton ) {
9 var config = {
10 classes: [ 'ext-WikiEditor-ManualWidget' ],
11 $element: $( '<a>' )
12 };
13 ManualWidget.super.call( this, config );
14
15 // Mixins.
16 OO.ui.mixin.AccessKeyedElement.call( this, {} );
17 OO.ui.mixin.ButtonElement.call( this, Object.assign( {
18 $button: this.$element
19 }, config ) );
20 OO.ui.mixin.IconElement.call( this, { icon: 'reload' } );
21 OO.ui.mixin.TitledElement.call( this, {
22 title: mw.msg( 'wikieditor-realtimepreview-reload-title' )
23 } );
24
25 this.reloadHoverButton = reloadHoverButton;
26
27 // UI elements.
28 var $reloadLabel = $( '<span>' )
29 .text( mw.msg( 'wikieditor-realtimepreview-manual' ) );
30 var $reloadButton = $( '<span>' )
31 .addClass( 'ext-WikiEditor-realtimepreview-manual-reload' )
32 .text( mw.msg( 'wikieditor-realtimepreview-reload' ) );
33 this.connect( realtimePreview, {
34 click: function () {
35 if ( !this.isScreenWideEnough() ) {
36 // Do nothing if realtime preview is not visible.
37 return;
38 }
39 // Only refresh the preview if we're enabled.
40 if ( this.enabled ) {
41 this.doRealtimePreview();
42 }
43 mw.hook( 'ext.WikiEditor.realtimepreview.reloadManual' ).fire( this );
44 }.bind( realtimePreview )
45 } );
46 this.$element.append( this.$icon, $reloadLabel, $reloadButton );
47 }
48
49 OO.inheritClass( ManualWidget, OO.ui.Widget );
50 OO.mixinClass( ManualWidget, OO.ui.mixin.AccessKeyedElement );
51 OO.mixinClass( ManualWidget, OO.ui.mixin.ButtonElement );
52 OO.mixinClass( ManualWidget, OO.ui.mixin.IconElement );
53 OO.mixinClass( ManualWidget, OO.ui.mixin.TitledElement );
54
55 ManualWidget.prototype.toggle = function ( show ) {
56 ManualWidget.super.prototype.toggle.call( this, show );
57 if ( show ) {
58 this.reloadHoverButton.$element.remove();
59 // Use the same access key as the hover reload button, because this won't ever be displayed at the same time as that.
60 this.setAccessKey( mw.msg( 'accesskey-wikieditor-realtimepreview' ) );
61 }
62 };
63
64 module.exports = ManualWidget;