2021-11-04 17:48:36 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWFloatingHelpElement class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Element
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
|
|
|
* @cfg {string} label
|
|
|
|
* @cfg {jQuery} $message
|
|
|
|
*/
|
|
|
|
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() ) {
|
|
|
|
$( document.body ).append( this.windowManager.$element );
|
|
|
|
} 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' ) ) {
|
2022-02-11 15:58:02 +00:00
|
|
|
var 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 } );
|
|
|
|
};
|