Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/97995
Change subject: Add OO.ui.GroupButtonWidget ...................................................................... Add OO.ui.GroupButtonWidget Adding a group button widget that displays multiple buttons and sends a click event with the stored value of whatever one of the buttons that is pressed. Change-Id: I480acb5a9d7ee751e2ee10941cddc11f829aeb57 --- A src/widgets/OO.ui.GroupButtonWidget.js 1 file changed, 75 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/95/97995/1 diff --git a/src/widgets/OO.ui.GroupButtonWidget.js b/src/widgets/OO.ui.GroupButtonWidget.js new file mode 100644 index 0000000..8157fd9 --- /dev/null +++ b/src/widgets/OO.ui.GroupButtonWidget.js @@ -0,0 +1,75 @@ +/** + * Creates an OO.ui.GroupButtonWidget object. + * + * @class + * @extends OO.ui.Widget + * + * @param {Object} [config] Configuration options + * @cfg {Object} [group] Button group parameters organized by { 'label': returnValue } + * where 'returnValue' is the value returned upon click + */ +OO.ui.GroupButtonWidget = function OoUiGroupButtonWidget( config ) { + var item, + counter = 0; + + // Configuration initialization + config = $.extend( { 'target': '_blank' }, config ); + + // Parent constructor + OO.ui.Widget.call( this, config ); + + // Initialization + this.$element.addClass( 've-ui-groupButtonWidget' ); + + this.value = null; + this.group = config.group; + this.buttons = {}; + // Set up the buttons + for ( item in this.group ) { + this.buttons[item] = new OO.ui.PushButtonWidget( { + 'label': item, + } ); + // bind to master click event + this.buttons[item].on( 'click', OO.ui.bind( this.onClick, this, { 'returnValue': this.group[item] } ) ); + // add button DOM + this.$element.append( this.buttons[item].$element ); + // separate lines if needed + // TODO: separate into lines through CSS instead + if ( ++counter >= 8 ) { + this.$element.append( $( '<br />' ) ); + counter = 0; + } + } + +}; + +/* Inheritance */ + +OO.inheritClass( OO.ui.GroupButtonWidget, OO.ui.Widget ); + +/* Events */ + +/** + * @event click + */ + +/** + * Handle onClick event to any of the buttons in the group + * + * @method + * @param {jQuery.Event} e Mouse click event + * @fires click + */ +OO.ui.GroupButtonWidget.prototype.onClick = function ( config ) { + this.value = config.returnValue; + this.emit( 'click' ); +}; + +/** + * Get the value of the pushed button from the group + * + * @returns {string} value of the selected button from the group + */ +OO.ui.GroupButtonWidget.prototype.getValue = function () { + return this.value; +}; -- To view, visit https://gerrit.wikimedia.org/r/97995 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I480acb5a9d7ee751e2ee10941cddc11f829aeb57 Gerrit-PatchSet: 1 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits