mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.MWCategoryPopupWidget.js
Trevor Parscal 3a99b99876 ve.ui.PopupWidget visibility fixes
Objective:

* Context popup would stop opening sometimes "mysteriously" which ended
  up having to do with the automatic closing on blur functionality
  added to popups for use in the category popup widget
* Mousedown event canceling was being applied a little too widely, and
  was causing popup widgets to not allow child elements to be focused
  (unless they contained an iframe, like an inspector)

Changes:

ve.ui.Context.js
* Make use of the popup's show and hide methods within the inspector

ve.ui.MWCategoryPopupWidget.js
* Override autoClose option for category popup widgets

ve.ui.PopupWidget.js
* Add autoClose option to popup widgets
* Move event handler to the top of the methods (convention)
* Only bind blur event if autoClose is enabled
* Inline the getFocusedChild method

Change-Id: I22aedb5fbd51b327ea7ce2ecdd6123e79cbebb9c
2013-05-17 05:49:16 +00:00

118 lines
3.2 KiB
JavaScript

/*!
* VisualEditor UserInterface MWCategoryPopupWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.MWCategoryPopupWidget object.
*
* @class
* @extends ve.ui.PopupWidget
*
* @constructor
* @param {Object} [config] Config options
*/
ve.ui.MWCategoryPopupWidget = function VeUiMwCategoryPopupWidget ( config ) {
// Configuration initialization
config = ve.extendObject( {}, config, { 'autoClose': true } );
// Parent constructor
ve.ui.PopupWidget.call( this, config );
// Properties
this.category = null;
this.$title = this.$$( '<label>' );
this.$menu = this.$$( '<div>' );
this.removeButton = new ve.ui.IconButtonWidget( {
'$$': this.$$, 'icon': 'remove', 'title': ve.msg( 'visualeditor-inspector-remove-tooltip' )
} );
this.sortKeyInput = new ve.ui.TextInputWidget( { '$$': this.$$ } );
this.sortKeyLabel = new ve.ui.InputLabelWidget(
{ '$$': this.$$, '$input': this.sortKeyInput, 'label': 'Page name in category' }
);
this.$sortKeyForm = this.$$( '<form>' ).addClass( 've-ui-mwCategorySortkeyForm' )
.append( this.sortKeyLabel.$, this.sortKeyInput.$ );
// Events
this.removeButton.connect( this, { 'click': 'onRemoveCategory' } );
this.$sortKeyForm.on( 'submit', ve.bind( this.onSortKeySubmit, this ) );
// Initialization
this.$.addClass( 've-ui-mwCategoryPopupMenu' ).hide();
this.$title
.addClass( 've-ui-mwCategoryPopupTitle ve-ui-icon-tag' )
.text( ve.msg( 'visualeditor-category-settings-label' ) );
this.$menu.append(
this.$title,
this.removeButton.$.addClass( 've-ui-mwCategoryRemoveButton' ),
this.$sortKeyForm
);
this.$body.append( this.$menu );
config.$overlay.append( this.$ );
};
/**
* @private
* @cfg {boolean} [autoClose=true] Overridden in this subclass
*/
/* Inheritance */
ve.inheritClass( ve.ui.MWCategoryPopupWidget, ve.ui.PopupWidget );
/* Events */
/**
* @event removeCategory
*/
/**
* @event updateSortkey
*/
/* Methods */
ve.ui.MWCategoryPopupWidget.prototype.onRemoveCategory = function () {
this.emit( 'removeCategory', this.category );
this.closePopup();
};
ve.ui.MWCategoryPopupWidget.prototype.onSortKeySubmit = function () {
this.emit( 'updateSortkey', this.category, this.sortKeyInput.$input.val() );
this.closePopup();
return false;
};
ve.ui.MWCategoryPopupWidget.prototype.openPopup = function ( item ) {
this.show();
this.popupOpen = true;
this.category = item.value;
this.loadCategoryIntoPopup( item );
this.setPopup( item );
};
ve.ui.MWCategoryPopupWidget.prototype.loadCategoryIntoPopup = function ( item ) {
this.sortKeyInput.$input.val( item.sortKey );
};
ve.ui.MWCategoryPopupWidget.prototype.closePopup = function () {
this.hide();
this.popupOpen = false;
};
ve.ui.MWCategoryPopupWidget.prototype.setDefaultSortKey = function ( value ) {
this.sortKeyInput.$input.attr( 'placeholder', value );
};
ve.ui.MWCategoryPopupWidget.prototype.setPopup = function ( item ) {
var left = item.$.offset().left + ( item.$.width() - 17 ),
top = item.$.offset().top + item.$.height(),
width = this.$menu.outerWidth( true ),
height = this.$menu.outerHeight( true );
this.$.css( { 'left': left, 'top': top } );
this.display( left, top, width, height );
};