2013-10-02 00:00:57 +00:00
|
|
|
/*!
|
|
|
|
* 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
|
2013-10-17 17:21:03 +00:00
|
|
|
* @mixins ve.ui.PopuppableElement
|
2013-10-02 00:00:57 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.PopupButtonWidget = function VeUiPopupButtonWidget( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.IconButtonWidget.call( this, config );
|
|
|
|
|
2013-10-17 17:21:03 +00:00
|
|
|
// Mixin constructors
|
|
|
|
ve.ui.PopuppableElement.call( this, config );
|
2013-10-02 00:00:57 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-10-17 17:21:03 +00:00
|
|
|
this.$
|
|
|
|
.addClass( 've-ui-popupButtonWidget' )
|
|
|
|
.append( this.popup.$ );
|
2013-10-02 00:00:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.PopupButtonWidget, ve.ui.IconButtonWidget );
|
|
|
|
|
2013-10-17 17:21:03 +00:00
|
|
|
ve.mixinClass( ve.ui.PopupButtonWidget, ve.ui.PopuppableElement );
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
/* 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;
|
|
|
|
};
|