Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineButtonWidget.js

raw symbols SCIP
1 /**
2 * Generic button-like widget for top-level parts in the template dialog
3 * sidebar. See {@see OO.ui.ButtonWidget} for inspiration.
4 *
5 * @class
6 * @extends OO.ui.OptionWidget
7 * @mixes OO.ui.mixin.ButtonElement
8 * @mixes OO.ui.mixin.IconElement
9 * @mixes OO.ui.mixin.TabIndexedElement
10 * @mixes ve.ui.MWAriaDescribe
11 *
12 * @constructor
13 * @param {Object} config
14 * @param {string} [config.icon=''] Symbolic name of an icon, e.g. "puzzle" or "wikiText"
15 * @param {string} config.label
16 */
17 ve.ui.MWTransclusionOutlineButtonWidget = function VeUiMWTransclusionOutlineButtonWidget( config ) {
18 // Parent constructor
19 ve.ui.MWTransclusionOutlineButtonWidget.super.call( this, ve.extendObject( config, {
20 classes: [ 've-ui-mwTransclusionOutlineButtonWidget' ]
21 } ) );
22
23 // Mixin constructors
24 OO.ui.mixin.ButtonElement.call( this, {
25 // FIXME semantically this could be a <legend> and the surrounding OutlinePartWidget a <fieldset>
26 $button: $( '<span>' ),
27 framed: false
28 } );
29 OO.ui.mixin.IconElement.call( this, config );
30 OO.ui.mixin.TabIndexedElement.call( this, ve.extendObject( {
31 $tabIndexed: this.$button
32 }, config ) );
33 ve.ui.MWAriaDescribe.call( this, {
34 ariaLabel: config.label,
35 $describedElement: this.$button
36 } );
37
38 // FIXME hack for screen readers to understand the selection state
39 this.$button.attr( {
40 role: 'gridcell',
41 'aria-selected': 'false'
42 } );
43
44 this.$element
45 .append( this.$button.append( this.$icon, this.$label ) );
46 };
47
48 /* Inheritance */
49
50 OO.inheritClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.OptionWidget );
51 OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.ButtonElement );
52 OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.IconElement );
53 OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.TabIndexedElement );
54 OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, ve.ui.MWAriaDescribe );
55
56 ve.ui.MWTransclusionOutlineButtonWidget.static.highlightable = false;
57 ve.ui.MWTransclusionOutlineButtonWidget.static.pressable = false;
58
59 /* Events */
60
61 /**
62 * @event ve.ui.MWTransclusionOutlineButtonWidget#keyPressed
63 * @param {number} key Typically one of the {@see OO.ui.Keys} constants
64 */
65
66 /**
67 * @inheritDoc OO.ui.mixin.ButtonElement
68 * @param {jQuery.Event} e
69 * @fires ve.ui.MWTransclusionOutlineButtonWidget#keyPressed
70 */
71 ve.ui.MWTransclusionOutlineButtonWidget.prototype.onKeyDown = function ( e ) {
72 const isMac = ve.getSystemPlatform() === 'mac';
73 const withMetaKey = isMac ? e.metaKey : e.ctrlKey;
74
75 if ( e.which === OO.ui.Keys.SPACE &&
76 !withMetaKey && !e.shiftKey && !e.altKey
77 ) {
78 // We know we can only select another part, so don't even try to unselect this one
79 if ( !this.isSelected() ) {
80 this.emit( 'keyPressed', e.which );
81 }
82 // The default behavior of pressing space is to scroll down
83 e.preventDefault();
84 return;
85 }
86
87 return OO.ui.mixin.ButtonElement.prototype.onKeyDown.call( this, e );
88 };
89
90 /**
91 * @inheritDoc
92 */
93 ve.ui.MWTransclusionOutlineButtonWidget.prototype.setSelected = function ( state ) {
94 if ( this.$button ) {
95 this.$button.attr( 'aria-selected', state.toString() );
96 }
97 return ve.ui.MWTransclusionOutlineButtonWidget.super.prototype.setSelected.call( this, state );
98 };