mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.ButtonWidget.js
Trevor Parscal d0ff691f9e Add user interface widgets
* New! Button and InputLabel widgets
* Using new buttons in the demo
* Moved styles around to generalize input styles

Change-Id: Ic42e133f8fe0fffcb61374c09dd5668db82a4799
TODO: Use these buttons other places! (like ve.init)
2013-02-13 18:04:04 -08:00

57 lines
1.3 KiB
JavaScript

/*!
* VisualEditor user interface ButtonWidget class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.ButtonWidget object.
*
* CSS classes will be added to the button for each flag, each prefixed with 've-ui-buttonWidget-'
*
* @abstract
* @class
* @constructor
* @extends ve.ui.Widget
* @param {Function} $$ jQuery for the frame the widget is in
* @param {string} label Button label
* @param {string[]} [flags] List of styling flags, e.g. 'primary', 'destructive' or 'constructive'
*/
ve.ui.ButtonWidget = function VeUiButtonWidget( $$, label, flags ) {
// Parent constructor
ve.ui.Widget.call( this, $$, $( '<a>' ) );
// Properties
this.$label = this.$$( '<span>' );
// Events
this.$.on(
'click',
ve.bind( function ( e ) {
this.emit( 'click' );
e.preventDefault();
return false;
}, this )
);
// Initialization
this.$label
.addClass( 've-ui-buttonWidget-label' )
.text( label );
this.$
.addClass( 've-ui-buttonWidget' )
.append( this.$label );
if ( ve.isArray( flags ) ) {
this.$.addClass( 've-ui-buttonWidget-' + flags.join( ' ve-ui-buttonWidget-' ) );
}
};
/* Inheritance */
ve.inheritClass( ve.ui.ButtonWidget, ve.ui.Widget );
/**
* @event click
*/