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
|
|
|
*/
|
2014-05-15 16:12:43 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget = function VeUiMWCategoryPopupWidget( config ) {
|
2013-05-16 19:34:18 +00:00
|
|
|
// Configuration initialization
|
2014-08-22 20:50:48 +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>' );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
framed: false,
|
|
|
|
icon: 'remove',
|
|
|
|
title: ve.msg( 'visualeditor-inspector-remove-tooltip' )
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.sortKeyInput = new OO.ui.TextInputWidget( { $: this.$ } );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.sortKeyField = new OO.ui.FieldLayout( this.sortKeyInput, {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg ( 'visualeditor-dialog-meta-categories-sortkey-label' )
|
2014-01-22 20:13:59 +00:00
|
|
|
} );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$sortKeyForm = this.$( '<form>' ).addClass( 've-ui-mwCategoryPopupWidget-sortKeyForm' )
|
2014-01-22 20:13:59 +00:00
|
|
|
.append( this.sortKeyField.$element );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.connect( this, { hide: 'onHide' } );
|
|
|
|
this.removeButton.connect( this, { click: 'onRemoveCategory' } );
|
2014-07-08 22:33:32 +00:00
|
|
|
this.$sortKeyForm.on( 'submit', this.onSortKeySubmit.bind( this ) );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// 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' ) );
|
2014-02-14 20:03:42 +00:00
|
|
|
this.$hiddenStatus = this.$( '<div>' );
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$menu
|
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-content' )
|
|
|
|
.append(
|
|
|
|
this.$title,
|
2014-02-14 20:03:42 +00:00
|
|
|
this.$hiddenStatus,
|
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 ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.toggle( true );
|
2013-04-29 21:01:56 +00:00
|
|
|
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;
|
2014-02-14 20:03:42 +00:00
|
|
|
if ( item.isHidden ) {
|
|
|
|
this.$hiddenStatus.text( ve.msg( 'visualeditor-dialog-meta-categories-hidden' ) );
|
|
|
|
} else {
|
|
|
|
this.$hiddenStatus.empty();
|
|
|
|
}
|
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 () {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.toggle( false );
|
2013-04-29 21:01:56 +00:00
|
|
|
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 ) {
|
2014-02-14 23:12:47 +00:00
|
|
|
var left = item.$indicator.offset().left + ( item.$indicator.width() / 2 ),
|
|
|
|
top = item.$indicator.offset().top + item.$indicator.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( {
|
2014-08-22 20:50:48 +00:00
|
|
|
right: this.$container.outerWidth( true ) - left,
|
|
|
|
top: top
|
2013-07-20 09:27:11 +00:00
|
|
|
} );
|
|
|
|
} else {
|
2014-08-22 20:50:48 +00:00
|
|
|
this.$element.css( { left: left, top: top } );
|
2013-07-20 09:27:11 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
this.setSize( width, height );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|