2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryPopupWidget class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-04-29 21:01:56 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWCategoryPopupWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.PopupWidget
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
|
|
|
* @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
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.PopupWidget.call( this, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.category = null;
|
2013-06-10 22:48:01 +00:00
|
|
|
this.origSortkey = null;
|
|
|
|
this.removed = false;
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$title = this.$( '<label>' );
|
|
|
|
this.$menu = this.$( '<div>' );
|
2013-10-09 20:09:59 +00:00
|
|
|
this.removeButton = new OO.ui.IconButtonWidget( {
|
2013-11-01 19:45:59 +00:00
|
|
|
'$': this.$, 'icon': 'remove', 'title': ve.msg( 'visualeditor-inspector-remove-tooltip' )
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.sortKeyInput = new OO.ui.TextInputWidget( { '$': this.$ } );
|
2013-10-09 20:09:59 +00:00
|
|
|
this.sortKeyLabel = new OO.ui.InputLabelWidget(
|
2013-11-01 19:45:59 +00:00
|
|
|
{ '$': this.$, '$input': this.sortKeyInput, 'label': ve.msg ( 'visualeditor-dialog-meta-categories-sortkey-label' ) }
|
2013-04-29 21:01:56 +00:00
|
|
|
);
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$sortKeyForm = this.$( '<form>' ).addClass( 've-ui-mwCategoryPopupWidget-sortKeyForm' )
|
|
|
|
.append( this.sortKeyLabel.$element, this.sortKeyInput.$element );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// 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-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ui-mwCategoryPopupWidget' ).hide();
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$title
|
2013-10-09 20:09:59 +00:00
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-title oo-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,
|
2013-11-01 19:45:59 +00:00
|
|
|
this.removeButton.$element.addClass( 've-ui-mwCategoryPopupWidget-removeButton' ),
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$sortKeyForm
|
|
|
|
);
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$body.append( this.$menu );
|
2013-11-01 19:45:59 +00:00
|
|
|
config.$overlay.append( this.$element );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.MWCategoryPopupWidget, OO.ui.PopupWidget );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
/* 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
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires removeCategory
|
2013-06-10 22:22:30 +00:00
|
|
|
*/
|
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
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires updateSortkey
|
2013-06-10 22:22:30 +00:00
|
|
|
*/
|
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
|
|
|
|
*/
|
2013-12-06 02:34:44 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onHide = function () {
|
2013-06-12 23:25:28 +00:00
|
|
|
var newSortkey = this.sortKeyInput.$input.val();
|
2013-11-27 17:26:49 +00:00
|
|
|
if ( !this.removed && newSortkey !== ( this.origSortkey || '' ) ) {
|
2013-06-12 23:25:28 +00:00
|
|
|
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:
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.css( {
|
2013-07-20 09:27:11 +00:00
|
|
|
'right': this.$container.outerWidth( true ) - left,
|
|
|
|
'top': top
|
|
|
|
} );
|
|
|
|
} else {
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.css( { 'left': left, 'top': top } );
|
2013-07-20 09:27:11 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
this.display( width, height );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|