2021-11-04 17:48:36 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWFloatingHelpElement class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2021-11-04 17:48:36 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-07-12 09:55:54 +00:00
|
|
|
* Question-mark button which floats over content, currently used in the
|
|
|
|
* template dialog. Clicking pops up a help screen.
|
|
|
|
*
|
2021-11-04 17:48:36 +00:00
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Element
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {string} config.label
|
|
|
|
* @param {jQuery} config.$message
|
2021-11-04 17:48:36 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWFloatingHelpElement = function VeUiMWFloatingHelpElement( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWFloatingHelpElement.super.call( this, config );
|
|
|
|
|
|
|
|
this.helpDialog = new ve.ui.MWFloatingHelpDialog( config );
|
|
|
|
this.helpButton = new OO.ui.ButtonWidget( {
|
2021-11-15 11:41:28 +00:00
|
|
|
icon: 'help',
|
2021-11-04 17:48:36 +00:00
|
|
|
label: config.label,
|
2022-01-21 10:04:41 +00:00
|
|
|
title: config.title,
|
2021-11-04 17:48:36 +00:00
|
|
|
invisibleLabel: true,
|
|
|
|
flags: 'progressive',
|
|
|
|
rel: 'help',
|
|
|
|
classes: [ 've-ui-mwFloatingHelpElement-toggle' ]
|
|
|
|
} ).connect(
|
|
|
|
this, { click: 'onClick' }
|
|
|
|
);
|
|
|
|
|
|
|
|
this.windowManager = new OO.ui.WindowManager();
|
|
|
|
this.windowManager.addWindows( [ this.helpDialog ] );
|
2021-11-09 16:47:43 +00:00
|
|
|
this.windowManager.$element.addClass( 've-ui-mwFloatingHelpElement-windowManager' );
|
|
|
|
|
|
|
|
if ( OO.ui.isMobile() ) {
|
2023-10-31 21:06:04 +00:00
|
|
|
$( OO.ui.getTeleportTarget() ).append( this.windowManager.$element );
|
2021-11-09 16:47:43 +00:00
|
|
|
} else {
|
|
|
|
this.$element.append( this.windowManager.$element );
|
|
|
|
}
|
2021-11-04 17:48:36 +00:00
|
|
|
|
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwFloatingHelpElement' )
|
2021-11-09 16:47:43 +00:00
|
|
|
.append( this.helpButton.$element );
|
2021-11-04 17:48:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWFloatingHelpElement, OO.ui.Element );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ui.MWFloatingHelpElement.prototype.onClick = function () {
|
|
|
|
if ( !this.helpButton.hasFlag( 'primary' ) ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const window = this.windowManager.openWindow( this.helpDialog );
|
2021-11-04 17:48:36 +00:00
|
|
|
|
2022-02-11 15:58:02 +00:00
|
|
|
window.opening.then( this.updateButton.bind( this, true ) );
|
|
|
|
window.closing.then( this.updateButton.bind( this, false ) );
|
2021-11-04 17:48:36 +00:00
|
|
|
} else {
|
|
|
|
this.windowManager.closeWindow( this.helpDialog );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWFloatingHelpElement.prototype.updateButton = function ( isOpen ) {
|
|
|
|
this.helpButton
|
2021-11-15 11:41:28 +00:00
|
|
|
.setIcon( isOpen ? 'expand' : 'help' )
|
2021-11-04 17:48:36 +00:00
|
|
|
.setFlags( { primary: isOpen } );
|
|
|
|
};
|