2021-07-13 09:00:57 +00:00
|
|
|
/**
|
2022-07-12 09:55:54 +00:00
|
|
|
* Generic button-like widget for top-level parts in the template dialog
|
|
|
|
* sidebar. See {@see OO.ui.ButtonWidget} for inspiration.
|
2021-07-13 10:15:47 +00:00
|
|
|
*
|
2021-07-13 09:00:57 +00:00
|
|
|
* @class
|
2021-08-27 16:22:37 +00:00
|
|
|
* @extends OO.ui.OptionWidget
|
2024-04-29 17:51:41 +00:00
|
|
|
* @mixes OO.ui.mixin.ButtonElement
|
|
|
|
* @mixes OO.ui.mixin.IconElement
|
|
|
|
* @mixes OO.ui.mixin.TabIndexedElement
|
|
|
|
* @mixes ve.ui.MWAriaDescribe
|
2021-07-13 09:00:57 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {string} [config.icon=''] Symbolic name of an icon, e.g. "puzzle" or "wikiText"
|
|
|
|
* @param {string} config.label
|
2021-07-13 09:00:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget = function VeUiMWTransclusionOutlineButtonWidget( config ) {
|
|
|
|
// Parent constructor
|
2021-09-10 19:18:59 +00:00
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.super.call( this, ve.extendObject( config, {
|
|
|
|
classes: [ 've-ui-mwTransclusionOutlineButtonWidget' ]
|
|
|
|
} ) );
|
2021-07-13 09:00:57 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
2021-07-13 10:15:47 +00:00
|
|
|
OO.ui.mixin.ButtonElement.call( this, {
|
2021-10-22 14:00:19 +00:00
|
|
|
// FIXME semantically this could be a <legend> and the surrounding OutlinePartWidget a <fieldset>
|
|
|
|
$button: $( '<span>' ),
|
2021-07-13 10:15:47 +00:00
|
|
|
framed: false
|
|
|
|
} );
|
2021-07-13 09:00:57 +00:00
|
|
|
OO.ui.mixin.IconElement.call( this, config );
|
2021-07-13 19:01:30 +00:00
|
|
|
OO.ui.mixin.TabIndexedElement.call( this, ve.extendObject( {
|
|
|
|
$tabIndexed: this.$button
|
|
|
|
}, config ) );
|
2021-11-16 11:00:12 +00:00
|
|
|
ve.ui.MWAriaDescribe.call( this, {
|
|
|
|
ariaLabel: config.label,
|
|
|
|
$describedElement: this.$button
|
|
|
|
} );
|
2021-07-13 09:00:57 +00:00
|
|
|
|
2021-10-27 09:58:51 +00:00
|
|
|
// FIXME hack for screen readers to understand the selection state
|
|
|
|
this.$button.attr( {
|
|
|
|
role: 'gridcell',
|
|
|
|
'aria-selected': 'false'
|
|
|
|
} );
|
|
|
|
|
2021-07-13 09:00:57 +00:00
|
|
|
this.$element
|
2021-07-13 10:15:47 +00:00
|
|
|
.append( this.$button.append( this.$icon, this.$label ) );
|
2021-07-13 09:00:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2021-08-27 16:22:37 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.OptionWidget );
|
2021-07-13 10:15:47 +00:00
|
|
|
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.ButtonElement );
|
2021-07-13 09:00:57 +00:00
|
|
|
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.IconElement );
|
2021-07-13 19:01:30 +00:00
|
|
|
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.TabIndexedElement );
|
2021-11-16 11:00:12 +00:00
|
|
|
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, ve.ui.MWAriaDescribe );
|
2021-08-27 16:22:37 +00:00
|
|
|
|
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.static.highlightable = false;
|
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.static.pressable = false;
|
2021-09-02 16:09:30 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.ui.MWTransclusionOutlineButtonWidget#keyPressed
|
2021-09-22 09:49:44 +00:00
|
|
|
* @param {number} key Typically one of the {@see OO.ui.Keys} constants
|
2021-09-02 16:09:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc OO.ui.mixin.ButtonElement
|
2021-09-22 09:49:44 +00:00
|
|
|
* @param {jQuery.Event} e
|
2024-04-29 18:14:26 +00:00
|
|
|
* @fires ve.ui.MWTransclusionOutlineButtonWidget#keyPressed
|
2021-09-02 16:09:30 +00:00
|
|
|
*/
|
2021-09-22 09:49:44 +00:00
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.prototype.onKeyDown = function ( e ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const isMac = ve.getSystemPlatform() === 'mac';
|
|
|
|
const withMetaKey = isMac ? e.metaKey : e.ctrlKey;
|
2021-09-22 09:49:44 +00:00
|
|
|
|
|
|
|
if ( e.which === OO.ui.Keys.SPACE &&
|
|
|
|
!withMetaKey && !e.shiftKey && !e.altKey
|
|
|
|
) {
|
2021-09-02 16:09:30 +00:00
|
|
|
// We know we can only select another part, so don't even try to unselect this one
|
|
|
|
if ( !this.isSelected() ) {
|
2021-09-22 09:49:44 +00:00
|
|
|
this.emit( 'keyPressed', e.which );
|
2021-09-02 16:09:30 +00:00
|
|
|
}
|
2021-09-22 09:49:44 +00:00
|
|
|
// The default behavior of pressing space is to scroll down
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
2021-09-02 16:09:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 09:49:44 +00:00
|
|
|
return OO.ui.mixin.ButtonElement.prototype.onKeyDown.call( this, e );
|
2021-09-02 16:09:30 +00:00
|
|
|
};
|
2021-10-27 09:58:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.prototype.setSelected = function ( state ) {
|
|
|
|
if ( this.$button ) {
|
|
|
|
this.$button.attr( 'aria-selected', state.toString() );
|
|
|
|
}
|
|
|
|
return ve.ui.MWTransclusionOutlineButtonWidget.super.prototype.setSelected.call( this, state );
|
|
|
|
};
|