mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.PopupButtonWidget.js
Trevor Parscal 81bbba4932 Split out popup functionality from ve.ui.PopupButtonWidget to ve.ui.PopuppableElement
Change-Id: I522d852d81d9674723a3262da3f030417f4fc3be
2013-10-17 10:21:03 -07:00

61 lines
1.3 KiB
JavaScript

/*!
* VisualEditor UserInterface PopupButtonWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Button that shows and hides a popup.
*
* @class
* @extends ve.ui.IconButtonWidget
* @mixins ve.ui.PopuppableElement
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve.ui.PopupButtonWidget = function VeUiPopupButtonWidget( config ) {
// Parent constructor
ve.ui.IconButtonWidget.call( this, config );
// Mixin constructors
ve.ui.PopuppableElement.call( this, config );
// Initialization
this.$
.addClass( 've-ui-popupButtonWidget' )
.append( this.popup.$ );
};
/* Inheritance */
ve.inheritClass( ve.ui.PopupButtonWidget, ve.ui.IconButtonWidget );
ve.mixinClass( ve.ui.PopupButtonWidget, ve.ui.PopuppableElement );
/* Methods */
/**
* Handles mouse click events.
*
* @method
* @param {jQuery.Event} e Mouse click event
*/
ve.ui.PopupButtonWidget.prototype.onClick = function ( e ) {
// Skip clicks within the popup
if ( $.contains( this.popup.$[0], e.target ) ) {
return;
}
if ( !this.disabled ) {
if ( this.popup.isVisible() ) {
this.hidePopup();
} else {
this.showPopup();
}
ve.ui.IconButtonWidget.prototype.onClick.call( this );
}
return false;
};