2021-07-13 09:00:57 +00:00
|
|
|
/**
|
2021-07-13 19:01:30 +00:00
|
|
|
* Generic button-like widget for items 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
|
2021-07-13 09:00:57 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
2021-09-11 08:05:31 +00:00
|
|
|
* @cfg {string} [icon=''] Symbolic name of an icon, e.g. "puzzle" or "wikiText"
|
2021-07-13 09:00:57 +00:00
|
|
|
* @cfg {string} label
|
|
|
|
*/
|
|
|
|
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, {
|
|
|
|
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-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-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 */
|
|
|
|
|
|
|
|
/**
|
2021-09-22 09:49:44 +00:00
|
|
|
* @event keyPressed
|
|
|
|
* @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
|
|
|
|
* @fires keyPressed
|
2021-09-02 16:09:30 +00:00
|
|
|
*/
|
2021-09-22 09:49:44 +00:00
|
|
|
ve.ui.MWTransclusionOutlineButtonWidget.prototype.onKeyDown = function ( e ) {
|
|
|
|
var withMetaKey = e.ctrlKey || e.metaKey;
|
|
|
|
|
|
|
|
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;
|
|
|
|
} else if ( ( e.which === OO.ui.Keys.UP || e.which === OO.ui.Keys.DOWN ) &&
|
|
|
|
withMetaKey && e.shiftKey &&
|
|
|
|
!e.altKey
|
|
|
|
) {
|
|
|
|
this.emit( 'keyPressed', e.which );
|
|
|
|
// TODO: Do we need e.preventDefault() and/or e.stopPropagation() here?
|
|
|
|
return;
|
|
|
|
} else if ( e.which === OO.ui.Keys.DELETE &&
|
|
|
|
withMetaKey &&
|
|
|
|
!e.shiftKey && !e.altKey
|
|
|
|
) {
|
|
|
|
this.emit( 'keyPressed', e.which );
|
|
|
|
// To not trigger the "clear cache" feature in Chrome we must do both
|
2021-09-02 16:09:30 +00:00
|
|
|
e.preventDefault();
|
2021-09-22 09:49:44 +00:00
|
|
|
e.stopPropagation();
|
2021-09-02 16:09:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|