2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* 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
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2013-08-07 09:45:48 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget = function VeUiMWCategoryPopupWidget ( config ) {
|
2013-05-16 19:34:18 +00:00
|
|
|
// Configuration initialization
|
2013-09-20 07:09:06 +00:00
|
|
|
config = ve.extendObject( { 'autoClose': true }, config );
|
2013-05-16 19:34:18 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.PopupWidget.call( this, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.category = null;
|
2013-06-10 22:48:01 +00:00
|
|
|
this.origSortkey = null;
|
|
|
|
this.removed = false;
|
2013-04-29 21:01:56 +00:00
|
|
|
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(
|
2013-05-25 10:01:32 +00:00
|
|
|
{ '$$': this.$$, '$input': this.sortKeyInput, 'label': ve.msg ( 'visualeditor-dialog-meta-categories-sortkey-label' ) }
|
2013-04-29 21:01:56 +00:00
|
|
|
);
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$sortKeyForm = this.$$( '<form>' ).addClass( 've-ui-mwCategoryPopupWidget-sortKeyForm' )
|
2013-04-29 21:01:56 +00:00
|
|
|
.append( this.sortKeyLabel.$, this.sortKeyInput.$ );
|
|
|
|
|
|
|
|
// Events
|
2013-06-10 22:48:01 +00:00
|
|
|
this.connect( this, { 'hide': 'onHide' } );
|
2013-05-01 22:21:32 +00:00
|
|
|
this.removeButton.connect( this, { 'click': 'onRemoveCategory' } );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$sortKeyForm.on( 'submit', ve.bind( this.onSortKeySubmit, this ) );
|
|
|
|
|
|
|
|
// Initialization
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$.addClass( 've-ui-mwCategoryPopupWidget' ).hide();
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$title
|
2013-10-02 00:00:57 +00:00
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-title ve-ui-icon-tag' )
|
2013-06-12 23:43:23 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-categories-category' ) );
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$menu
|
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-content' )
|
|
|
|
.append(
|
|
|
|
this.$title,
|
|
|
|
this.removeButton.$.addClass( 've-ui-mwCategoryPopupWidget-removeButton' ),
|
|
|
|
this.$sortKeyForm
|
|
|
|
);
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$body.append( this.$menu );
|
|
|
|
config.$overlay.append( this.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.MWCategoryPopupWidget, ve.ui.PopupWidget );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event removeCategory
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {string} category Category name
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event updateSortkey
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {string} category Category name
|
|
|
|
* @param {string} sortkey New sortkey
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Handle category remove events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @emits removeCategory
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onRemoveCategory = function () {
|
2013-06-10 22:48:01 +00:00
|
|
|
this.removed = true;
|
2013-04-29 21:01:56 +00:00
|
|
|
this.emit( 'removeCategory', this.category );
|
|
|
|
this.closePopup();
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Handle sort key form submit events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Form submit event
|
|
|
|
* @emits updateSortkey
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onSortKeySubmit = function () {
|
|
|
|
this.closePopup();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Open a category item popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.openPopup = function ( item ) {
|
|
|
|
this.show();
|
|
|
|
this.popupOpen = true;
|
|
|
|
this.category = item.value;
|
|
|
|
this.loadCategoryIntoPopup( item );
|
|
|
|
this.setPopup( item );
|
|
|
|
};
|
|
|
|
|
2013-06-12 23:25:28 +00:00
|
|
|
/**
|
|
|
|
* Handle popup hide events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onHide = function() {
|
|
|
|
var newSortkey = this.sortKeyInput.$input.val();
|
|
|
|
if ( !this.removed && newSortkey !== this.origSortkey ) {
|
|
|
|
this.emit( 'updateSortkey', this.category, this.sortKeyInput.$input.val() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Load item information into the popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.loadCategoryIntoPopup = function ( item ) {
|
2013-06-10 22:48:01 +00:00
|
|
|
this.origSortkey = item.sortkey;
|
2013-04-29 21:01:56 +00:00
|
|
|
this.sortKeyInput.$input.val( item.sortKey );
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Close the popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.closePopup = function () {
|
|
|
|
this.hide();
|
|
|
|
this.popupOpen = false;
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Set the default sort key.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} value Default sort key value
|
|
|
|
*/
|
2013-05-03 22:17:35 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.setDefaultSortKey = function ( value ) {
|
|
|
|
this.sortKeyInput.$input.attr( 'placeholder', value );
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Display the popup next to an item.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.setPopup = function ( item ) {
|
2013-06-12 23:25:28 +00:00
|
|
|
var left = item.$arrow.offset().left + ( item.$arrow.width() / 2 ),
|
|
|
|
top = item.$arrow.offset().top + item.$arrow.height(),
|
2013-04-29 21:01:56 +00:00
|
|
|
width = this.$menu.outerWidth( true ),
|
|
|
|
height = this.$menu.outerHeight( true );
|
|
|
|
|
2013-07-20 09:27:11 +00:00
|
|
|
// Flip for RTL:
|
|
|
|
if ( this.$container.attr( 'dir' ) === 'rtl' ) {
|
|
|
|
// flip me, I'm a mirror:
|
|
|
|
this.$.css( {
|
|
|
|
'right': this.$container.outerWidth( true ) - left,
|
|
|
|
'top': top
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
this.$.css( { 'left': left, 'top': top } );
|
|
|
|
}
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
this.display( width, height );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|