ULS actions menu buttons: Add support for href
Currently, actions menu button only support an event handler to be called upon button click. However, when the desired result of a button click is just a redirection, "href" attributes are preferable, due to their accessibility support. To better handle such cases, this patch also adds support for "href" attributes inside action item buttons. When "href" property exists for an actions menu item, it is used and the event handler is ignored. Bug: T289840 Change-Id: I776680c19564f032acd550206c7d1306407420e0
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
( function () {
|
||||
var ActionsMenuItem = function ( icon, text, handler ) {
|
||||
var ActionsMenuItem = function ( icon, text, handler, href ) {
|
||||
this.icon = icon;
|
||||
this.text = text;
|
||||
this.handler = handler;
|
||||
this.href = href;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {OO.ui.ButtonWidget}
|
||||
*/
|
||||
ActionsMenuItem.prototype.render = function () {
|
||||
return new OO.ui.ButtonWidget( {
|
||||
var actionButtonOptions = {
|
||||
framed: false,
|
||||
icon: this.icon,
|
||||
label: this.text,
|
||||
classes: [ 'uls-language-action' ],
|
||||
flags: [ 'progressive' ]
|
||||
} );
|
||||
};
|
||||
|
||||
if ( this.href ) {
|
||||
actionButtonOptions.href = this.href;
|
||||
}
|
||||
|
||||
var actionButton = new OO.ui.ButtonWidget( actionButtonOptions );
|
||||
|
||||
if ( !this.href ) {
|
||||
actionButton.$element.one( 'click', this.handler );
|
||||
}
|
||||
|
||||
return actionButton;
|
||||
};
|
||||
|
||||
module.exports = ActionsMenuItem;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
this.options = options;
|
||||
this.$template = $( ActionsMenu.template );
|
||||
this.actionItems = options.actions.map( function ( action ) {
|
||||
return new ActionsMenuItem( action.icon, action.text, action.handler );
|
||||
return new ActionsMenuItem( action.icon, action.text, action.handler, action.href );
|
||||
} );
|
||||
this.rendered = false;
|
||||
this.shown = false;
|
||||
@@ -65,14 +65,14 @@
|
||||
actionItem = new ActionsMenuItem(
|
||||
actionItem.icon,
|
||||
actionItem.text,
|
||||
actionItem.handler
|
||||
actionItem.handler,
|
||||
actionItem.href
|
||||
);
|
||||
}
|
||||
var actionButton = actionItem.render();
|
||||
this.$template.find( '.uls-language-action-items' ).prepend(
|
||||
actionButton.$element
|
||||
);
|
||||
actionButton.$element.one( 'click', actionItem.handler );
|
||||
},
|
||||
|
||||
i18n: function () {
|
||||
|
||||
Reference in New Issue
Block a user