2013-10-17 17:35:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki UserInterface popup tool classes.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-10-17 17:35:16 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-04-30 13:02:36 +00:00
|
|
|
* MediaWiki UserInterface popup tool.
|
2013-10-17 17:35:16 +00:00
|
|
|
*
|
|
|
|
* @class
|
2015-04-30 13:02:36 +00:00
|
|
|
* @abstract
|
2013-10-17 17:35:16 +00:00
|
|
|
* @extends OO.ui.PopupTool
|
|
|
|
* @constructor
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {string} title
|
2015-04-30 13:02:36 +00:00
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config]
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {number} [config.width] Popup width. Upstream default is 320.
|
2015-04-30 13:02:36 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWPopupTool = function VeUiMWPopupTool( title, toolGroup, config ) {
|
|
|
|
// Configuration initialization
|
2018-03-27 11:41:39 +00:00
|
|
|
config = ve.extendObject( { popup: { head: true, label: title, width: config && config.width } }, config );
|
2015-04-30 13:02:36 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWPopupTool.super.call( this, toolGroup, config );
|
|
|
|
|
2020-04-02 08:24:16 +00:00
|
|
|
this.popup.connect( this, {
|
|
|
|
ready: 'onPopupOpened',
|
|
|
|
closing: 'onPopupClosing'
|
|
|
|
} );
|
|
|
|
|
2015-04-30 13:02:36 +00:00
|
|
|
this.$element.addClass( 've-ui-mwPopupTool' );
|
2018-10-24 17:18:21 +00:00
|
|
|
|
|
|
|
this.$link.on( 'click', this.onToolLinkClick.bind( this ) );
|
2015-04-30 13:02:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWPopupTool, OO.ui.PopupTool );
|
|
|
|
|
2020-04-02 08:24:16 +00:00
|
|
|
/**
|
|
|
|
* Handle to call when popup is opened.
|
|
|
|
*/
|
|
|
|
ve.ui.MWPopupTool.prototype.onPopupOpened = function () {
|
|
|
|
this.popup.closeButton.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle to call when popup is closing
|
|
|
|
*/
|
|
|
|
ve.ui.MWPopupTool.prototype.onPopupClosing = function () {
|
|
|
|
this.$link.trigger( 'focus' );
|
|
|
|
};
|
|
|
|
|
2018-10-24 17:18:21 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the main tool button.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e Click event
|
|
|
|
*/
|
|
|
|
ve.ui.MWPopupTool.prototype.onToolLinkClick = function () {
|
|
|
|
if ( this.popup.isVisible() ) {
|
|
|
|
// Popup will be visible if this just opened, thanks to sequencing.
|
|
|
|
// Can't just track this with toggle, because the notices popup is auto-opened and we
|
|
|
|
// want to know about deliberate interactions.
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name + 'Popup', { action: 'show' } );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 13:02:36 +00:00
|
|
|
/**
|
|
|
|
* MediaWiki UserInterface notices popup tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.MWPopupTool
|
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config]
|
2013-10-17 17:35:16 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool = function VeUiMWNoticesPopupTool( toolGroup, config ) {
|
2016-11-22 05:42:31 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWNoticesPopupTool.super.call(
|
|
|
|
this,
|
|
|
|
ve.msg( 'visualeditor-editnotices-tooltip' ),
|
|
|
|
toolGroup,
|
2018-03-27 11:41:39 +00:00
|
|
|
ve.extendObject( config, { width: 380 } )
|
2016-11-22 05:42:31 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWNoticesPopupTool, ve.ui.MWPopupTool );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWNoticesPopupTool.static.name = 'notices';
|
2023-06-07 14:48:43 +00:00
|
|
|
ve.ui.MWNoticesPopupTool.static.group = 'notices';
|
2016-11-22 05:42:31 +00:00
|
|
|
ve.ui.MWNoticesPopupTool.static.icon = 'alert';
|
|
|
|
ve.ui.MWNoticesPopupTool.static.title = OO.ui.deferMsg( 'visualeditor-editnotices-tooltip' );
|
|
|
|
ve.ui.MWNoticesPopupTool.static.autoAddToCatchall = false;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2017-04-20 17:47:51 +00:00
|
|
|
* Set notices to display
|
2016-11-22 05:42:31 +00:00
|
|
|
*
|
2017-04-20 17:47:51 +00:00
|
|
|
* @param {string[]} notices A (non-empty) list of notices
|
2016-11-22 05:42:31 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool.prototype.setNotices = function ( notices ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const count = notices.length;
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2016-11-22 05:42:31 +00:00
|
|
|
this.popup.setLabel( ve.msg(
|
|
|
|
'visualeditor-editnotices-tool',
|
|
|
|
mw.language.convertNumber( count )
|
|
|
|
) );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2017-03-16 17:13:36 +00:00
|
|
|
if ( this.$items ) {
|
|
|
|
this.$items.remove();
|
|
|
|
}
|
|
|
|
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$items = $( '<div>' ).addClass( 've-ui-mwNoticesPopupTool-items' );
|
2018-11-16 18:47:54 +00:00
|
|
|
this.noticeItems = [];
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2024-04-30 16:44:25 +00:00
|
|
|
notices.forEach( ( item ) => {
|
2021-11-15 17:03:35 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-html
|
2024-05-21 14:22:56 +00:00
|
|
|
const $element = $( '<div>' )
|
2013-10-17 17:35:16 +00:00
|
|
|
.addClass( 've-ui-mwNoticesPopupTool-item' )
|
2018-11-28 22:42:19 +00:00
|
|
|
.html( typeof item === 'string' ? item : item.message );
|
|
|
|
ve.targetLinksToNewWindow( $element[ 0 ] );
|
2018-11-16 18:47:54 +00:00
|
|
|
|
2024-05-01 12:32:49 +00:00
|
|
|
this.noticeItems.push( {
|
2018-11-16 18:47:54 +00:00
|
|
|
$element: $element,
|
|
|
|
type: item.type
|
|
|
|
} );
|
2014-03-12 22:09:47 +00:00
|
|
|
|
2024-05-01 12:32:49 +00:00
|
|
|
this.$items.append( $element );
|
2015-03-30 19:35:38 +00:00
|
|
|
} );
|
2014-03-12 22:09:47 +00:00
|
|
|
|
2013-10-17 17:35:16 +00:00
|
|
|
this.popup.$body.append( this.$items );
|
2017-10-30 22:21:50 +00:00
|
|
|
// Fire content hook
|
|
|
|
mw.hook( 'wikipage.content' ).fire( this.popup.$body );
|
2023-08-24 19:03:42 +00:00
|
|
|
|
|
|
|
ve.track( 'activity.notices', { action: 'show' } );
|
2013-10-17 17:35:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tool title.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWNoticesPopupTool.prototype.getTitle = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const items = this.toolbar.getTarget().getEditNotices();
|
2013-10-17 17:35:16 +00:00
|
|
|
|
2019-11-01 16:20:22 +00:00
|
|
|
// eslint-disable-next-line mediawiki/msg-doc
|
2015-03-30 19:35:38 +00:00
|
|
|
return ve.msg( this.constructor.static.title, items.length );
|
2013-10-17 17:35:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.toolFactory.register( ve.ui.MWNoticesPopupTool );
|