Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/elements/ve.ui.MWFloatingHelpElement.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWFloatingHelpElement class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Question-mark button which floats over content, currently used in the
10 * template dialog. Clicking pops up a help screen.
11 *
12 * @class
13 * @extends OO.ui.Element
14 *
15 * @constructor
16 * @param {Object} config
17 * @param {string} config.label
18 * @param {jQuery} config.$message
19 */
20 ve.ui.MWFloatingHelpElement = function VeUiMWFloatingHelpElement( config ) {
21 // Parent constructor
22 ve.ui.MWFloatingHelpElement.super.call( this, config );
23
24 this.helpDialog = new ve.ui.MWFloatingHelpDialog( config );
25 this.helpButton = new OO.ui.ButtonWidget( {
26 icon: 'help',
27 label: config.label,
28 title: config.title,
29 invisibleLabel: true,
30 flags: 'progressive',
31 rel: 'help',
32 classes: [ 've-ui-mwFloatingHelpElement-toggle' ]
33 } ).connect(
34 this, { click: 'onClick' }
35 );
36
37 this.windowManager = new OO.ui.WindowManager();
38 this.windowManager.addWindows( [ this.helpDialog ] );
39 this.windowManager.$element.addClass( 've-ui-mwFloatingHelpElement-windowManager' );
40
41 if ( OO.ui.isMobile() ) {
42 $( OO.ui.getTeleportTarget() ).append( this.windowManager.$element );
43 } else {
44 this.$element.append( this.windowManager.$element );
45 }
46
47 this.$element
48 .addClass( 've-ui-mwFloatingHelpElement' )
49 .append( this.helpButton.$element );
50 };
51
52 /* Inheritance */
53
54 OO.inheritClass( ve.ui.MWFloatingHelpElement, OO.ui.Element );
55
56 /* Methods */
57
58 ve.ui.MWFloatingHelpElement.prototype.onClick = function () {
59 if ( !this.helpButton.hasFlag( 'primary' ) ) {
60 const window = this.windowManager.openWindow( this.helpDialog );
61
62 window.opening.then( this.updateButton.bind( this, true ) );
63 window.closing.then( this.updateButton.bind( this, false ) );
64 } else {
65 this.windowManager.closeWindow( this.helpDialog );
66 }
67 };
68
69 ve.ui.MWFloatingHelpElement.prototype.updateButton = function ( isOpen ) {
70 this.helpButton
71 .setIcon( isOpen ? 'expand' : 'help' )
72 .setFlags( { primary: isOpen } );
73 };