2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryWidget class.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 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.MWCategoryWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.Widget
|
2014-02-15 00:17:15 +00:00
|
|
|
* @mixins OO.ui.GroupElement
|
2014-11-14 20:44:55 +00:00
|
|
|
* @mixins OO.ui.DraggableGroupElement
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2014-10-14 22:48:24 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget = function VeUiMWCategoryWidget( config ) {
|
2014-11-21 13:00:50 +00:00
|
|
|
// Config initialization
|
2013-04-29 21:01:56 +00:00
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Widget.call( this, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2013-05-03 18:30:33 +00:00
|
|
|
// Mixin constructors
|
2014-09-04 00:18:41 +00:00
|
|
|
OO.ui.GroupElement.call( this, config );
|
2014-11-14 20:44:55 +00:00
|
|
|
OO.ui.DraggableGroupElement.call( this, $.extend( {}, config, { orientation: 'horizontal' } ) );
|
2013-05-03 18:30:33 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
// Properties
|
|
|
|
this.categories = {};
|
2014-03-11 19:02:16 +00:00
|
|
|
this.categoryRedirects = {}; // Source -> target
|
2013-04-29 21:01:56 +00:00
|
|
|
this.popupState = false;
|
|
|
|
this.savedPopupState = false;
|
|
|
|
this.popup = new ve.ui.MWCategoryPopupWidget( {
|
2014-10-16 05:52:15 +00:00
|
|
|
$: this.$
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2013-05-03 18:30:33 +00:00
|
|
|
this.input = new ve.ui.MWCategoryInputWidget( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$, $overlay: config.$overlay
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2015-01-15 22:07:34 +00:00
|
|
|
this.forceCapitalization = mw.config.get( 'wgCaseSensitiveNamespaces' ).indexOf( 14 ) === -1;
|
|
|
|
this.categoryPrefix = mw.config.get( 'wgFormattedNamespaces' )['14'] + ':';
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Events
|
2015-01-15 22:07:34 +00:00
|
|
|
this.input.connect( this, { choose: 'onInputChoose' } );
|
2013-05-01 22:21:32 +00:00
|
|
|
this.popup.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
removeCategory: 'onRemoveCategory',
|
|
|
|
updateSortkey: 'onUpdateSortkey',
|
|
|
|
hide: 'onPopupHide'
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2014-11-14 20:44:55 +00:00
|
|
|
this.connect( this, { reorder: 'onReorder' } );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ui-mwCategoryWidget' )
|
2013-04-29 21:01:56 +00:00
|
|
|
.append(
|
2013-07-25 12:34:25 +00:00
|
|
|
this.$group.addClass( 've-ui-mwCategoryWidget-items' ),
|
2013-11-01 19:45:59 +00:00
|
|
|
this.input.$element,
|
2014-10-16 05:52:15 +00:00
|
|
|
this.popup.$element,
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$( '<div>' ).css( 'clear', 'both' )
|
2013-04-29 21:01:56 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.MWCategoryWidget, OO.ui.Widget );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.mixinClass( ve.ui.MWCategoryWidget, OO.ui.GroupElement );
|
2014-11-14 20:44:55 +00:00
|
|
|
OO.mixinClass( ve.ui.MWCategoryWidget, OO.ui.DraggableGroupElement );
|
2013-06-10 23:41:12 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event newCategory
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {Object} item Category item
|
|
|
|
* @param {string} item.name Fully prefixed category name
|
|
|
|
* @param {string} item.value Category value (name without prefix)
|
|
|
|
* @param {Object} item.metaItem Category meta item
|
2014-11-14 20:44:55 +00:00
|
|
|
* @param {ve.dm.MetaItem} [afterCategory] Insert after this category; if unset, insert at the end
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event updateSortkey
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {Object} item Category item
|
|
|
|
* @param {string} item.name Fully prefixed category name
|
|
|
|
* @param {string} item.value Category value (name without prefix)
|
|
|
|
* @param {Object} item.metaItem Category meta item
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2015-01-15 22:07:34 +00:00
|
|
|
* Handle input 'choose' event.
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
2015-01-15 22:07:34 +00:00
|
|
|
* @param {OO.ui.MenuOptionWidget|null} item Selected item
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2015-01-15 22:07:34 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.onInputChoose = function ( item ) {
|
2014-02-14 20:03:42 +00:00
|
|
|
var categoryItem,
|
|
|
|
value = item && item.getData(),
|
2015-01-15 22:07:34 +00:00
|
|
|
widget = this;
|
2013-07-01 23:01:34 +00:00
|
|
|
|
|
|
|
if ( value && value !== '' ) {
|
|
|
|
// Add new item
|
2015-01-15 22:07:34 +00:00
|
|
|
categoryItem = this.getCategoryItemFromValue( value );
|
2014-10-15 20:07:39 +00:00
|
|
|
this.queryCategoryStatus( [categoryItem.name] ).done( function ( normalisedTitles ) {
|
|
|
|
// Remove existing items by name
|
|
|
|
var toRemove = mw.Title.newFromText( categoryItem.name ).getMainText();
|
2015-01-15 22:07:34 +00:00
|
|
|
if ( Object.prototype.hasOwnProperty.call( widget.categories, toRemove ) ) {
|
|
|
|
widget.categories[toRemove].metaItem.remove();
|
2014-10-15 20:07:39 +00:00
|
|
|
}
|
|
|
|
categoryItem.name = normalisedTitles[categoryItem.name] || categoryItem.name;
|
2015-01-15 22:07:34 +00:00
|
|
|
widget.emit( 'newCategory', categoryItem );
|
2014-02-14 20:03:42 +00:00
|
|
|
} );
|
2015-01-15 22:07:34 +00:00
|
|
|
}
|
|
|
|
};
|
2014-02-14 20:03:42 +00:00
|
|
|
|
2015-01-15 22:07:34 +00:00
|
|
|
/**
|
|
|
|
* Get a category item.
|
|
|
|
*
|
|
|
|
* @param {string} value Category name
|
|
|
|
* @returns {Object} Category item with name, value and metaItem properties
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.getCategoryItemFromValue = function ( value ) {
|
|
|
|
var title;
|
|
|
|
|
|
|
|
// Normalize
|
|
|
|
title = mw.Title.newFromText( this.categoryPrefix + value );
|
|
|
|
if ( title ) {
|
|
|
|
return {
|
|
|
|
name: title.getPrefixedText(),
|
|
|
|
value: title.getMainText(),
|
|
|
|
metaItem: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.forceCapitalization ) {
|
|
|
|
value = value.slice( 0, 1 ).toUpperCase() + value.slice( 1 );
|
2013-04-29 21:01:56 +00:00
|
|
|
}
|
2015-01-15 22:07:34 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
name: this.categoryPrefix + value,
|
|
|
|
value: value,
|
|
|
|
metaItem: {}
|
|
|
|
};
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
2014-11-14 20:44:55 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} item Item that was moved
|
|
|
|
* @param {number} newIndex The new index of the item
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.onReorder = function ( item, newIndex ) {
|
|
|
|
// Compute afterCategory before removing, otherwise newIndex
|
|
|
|
// could be off by one
|
|
|
|
var afterCategory = this.items[newIndex] && this.items[newIndex].metaItem;
|
|
|
|
if ( Object.prototype.hasOwnProperty.call( this.categories, item.value ) ) {
|
|
|
|
this.categories[item.value].metaItem.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit( 'newCategory', item, afterCategory );
|
|
|
|
};
|
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/**
|
2013-06-10 22:22:30 +00:00
|
|
|
* Removes category from model.
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
2013-06-10 22:22:30 +00:00
|
|
|
* @method
|
2013-05-06 11:34:32 +00:00
|
|
|
* @param {string} name category name
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.onRemoveCategory = function ( name ) {
|
|
|
|
this.categories[name].metaItem.remove();
|
2015-02-27 22:04:39 +00:00
|
|
|
delete this.categories[name];
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-10 22:22:30 +00:00
|
|
|
* Update sortkey value, emit updateSortkey event
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
2013-06-10 22:22:30 +00:00
|
|
|
* @method
|
2013-05-06 11:34:32 +00:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.onUpdateSortkey = function ( name, value ) {
|
|
|
|
this.categories[name].sortKey = value;
|
|
|
|
this.emit( 'updateSortkey', this.categories[name] );
|
|
|
|
};
|
|
|
|
|
2015-02-27 22:04:39 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.clearItems = function () {
|
|
|
|
OO.ui.GroupElement.prototype.clearItems.call( this );
|
|
|
|
this.categories = {};
|
|
|
|
};
|
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/**
|
|
|
|
* Sets popup state when popup is hidden
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.onPopupHide = function () {
|
|
|
|
this.popupState = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves current popup state
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.onSavePopupState = function () {
|
|
|
|
this.savedPopupState = this.popupState;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles popup menu per category item
|
|
|
|
* @param {Object} item
|
|
|
|
*/
|
2013-05-25 12:53:33 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.onTogglePopupMenu = function ( item ) {
|
2013-04-29 21:01:56 +00:00
|
|
|
// Close open popup.
|
|
|
|
if ( this.savedPopupState === false || item.value !== this.popup.category ) {
|
|
|
|
this.popup.openPopup( item );
|
|
|
|
} else {
|
|
|
|
// Handle toggle
|
|
|
|
this.popup.closePopup();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-05-03 22:17:35 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.setDefaultSortKey = function ( value ) {
|
|
|
|
this.popup.setDefaultSortKey( value );
|
|
|
|
};
|
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/**
|
|
|
|
* Get list of category names.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string[]} List of category names
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.getCategories = function () {
|
|
|
|
return ve.getObjectKeys( this.categories );
|
|
|
|
};
|
|
|
|
|
2014-02-14 20:03:42 +00:00
|
|
|
/**
|
2014-10-15 20:07:39 +00:00
|
|
|
* Starts a request to update the link cache's hidden and missing status for
|
|
|
|
* the given titles, following normalisation responses as necessary.
|
|
|
|
* The returned promise will be resolved with an object with input titles as keys
|
|
|
|
* and their normalised versions as values, where different.
|
2014-02-14 20:03:42 +00:00
|
|
|
*
|
|
|
|
* @param {string[]} categoryNames
|
|
|
|
* @return {jQuery.Promise}
|
|
|
|
*/
|
2014-10-15 20:07:39 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.queryCategoryStatus = function ( categoryNames ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
var categoryWidget = this,
|
|
|
|
categoryNamesToQuery = [];
|
2014-02-14 20:03:42 +00:00
|
|
|
// Get rid of any we already know the hidden status of.
|
|
|
|
categoryNamesToQuery = $.grep( categoryNames, function ( categoryTitle ) {
|
2014-09-20 00:59:22 +00:00
|
|
|
var cacheEntry = ve.init.platform.linkCache.getCached( categoryTitle );
|
|
|
|
return !( cacheEntry && cacheEntry.hidden );
|
2014-02-14 20:03:42 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if ( !categoryNamesToQuery.length ) {
|
2014-10-15 20:07:39 +00:00
|
|
|
return $.Deferred().resolve( {} ).promise();
|
2014-02-14 20:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new mw.Api().get( {
|
|
|
|
action: 'query',
|
|
|
|
prop: 'pageprops',
|
|
|
|
titles: categoryNamesToQuery.join( '|' ),
|
2014-03-11 19:02:16 +00:00
|
|
|
ppprop: 'hiddencat',
|
|
|
|
redirects: ''
|
2014-02-14 20:03:42 +00:00
|
|
|
} ).then( function ( result ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
var linkCacheUpdate = {},
|
|
|
|
normalisedTitles = {};
|
2014-02-14 20:03:42 +00:00
|
|
|
if ( result && result.query && result.query.pages ) {
|
|
|
|
$.each( result.query.pages, function ( index, pageInfo ) {
|
2014-09-20 00:59:22 +00:00
|
|
|
linkCacheUpdate[pageInfo.title] = {
|
2014-11-05 22:45:09 +00:00
|
|
|
missing: Object.prototype.hasOwnProperty.call( pageInfo, 'missing' ),
|
2014-09-24 21:52:41 +00:00
|
|
|
hidden: pageInfo.pageprops &&
|
|
|
|
Object.prototype.hasOwnProperty.call( pageInfo.pageprops, 'hiddencat' )
|
2014-09-20 00:59:22 +00:00
|
|
|
};
|
2014-02-14 20:03:42 +00:00
|
|
|
} );
|
|
|
|
}
|
2014-03-11 19:02:16 +00:00
|
|
|
if ( result && result.query && result.query.redirects ) {
|
|
|
|
$.each( result.query.redirects, function ( index, redirectInfo ) {
|
|
|
|
categoryWidget.categoryRedirects[redirectInfo.from] = redirectInfo.to;
|
|
|
|
} );
|
|
|
|
}
|
2014-09-20 00:59:22 +00:00
|
|
|
ve.init.platform.linkCache.set( linkCacheUpdate );
|
2014-10-15 20:07:39 +00:00
|
|
|
|
|
|
|
if ( result.query && result.query.normalized ) {
|
|
|
|
$.each( result.query.normalized, function ( index, normalisation ) {
|
|
|
|
normalisedTitles[normalisation.from] = normalisation.to;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return normalisedTitles;
|
2014-02-14 20:03:42 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/**
|
|
|
|
* Adds category items.
|
|
|
|
*
|
|
|
|
* @method
|
2013-05-03 18:30:33 +00:00
|
|
|
* @param {Object[]} items Items to add
|
|
|
|
* @param {number} [index] Index to insert items after
|
2014-02-14 20:03:42 +00:00
|
|
|
* @return {jQuery.Promise}
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2013-05-03 18:30:33 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.addItems = function ( items, index ) {
|
|
|
|
var i, len, item, categoryItem,
|
|
|
|
categoryItems = [],
|
2014-11-14 20:44:55 +00:00
|
|
|
existingCategoryItems = [],
|
2014-02-14 20:03:42 +00:00
|
|
|
categoryNames = $.map( items, function ( item ) {
|
|
|
|
return item.name;
|
|
|
|
} ),
|
|
|
|
categoryWidget = this;
|
|
|
|
|
2014-10-15 20:07:39 +00:00
|
|
|
return this.queryCategoryStatus( categoryNames ).then( function ( normalisedTitles ) {
|
2014-11-14 20:44:55 +00:00
|
|
|
var itemTitle, config, cachedData,
|
|
|
|
checkValueMatches = function ( existingCategoryItem ) {
|
|
|
|
return config.item.value === existingCategoryItem.value;
|
|
|
|
};
|
2014-10-15 20:07:39 +00:00
|
|
|
|
2014-02-14 20:03:42 +00:00
|
|
|
for ( i = 0, len = items.length; i < len; i++ ) {
|
|
|
|
item = items[i];
|
2014-10-15 20:07:39 +00:00
|
|
|
item.name = normalisedTitles[item.name] || item.name;
|
2014-02-14 20:03:42 +00:00
|
|
|
|
2014-10-15 20:07:39 +00:00
|
|
|
itemTitle = new mw.Title( item.name, mw.config.get( 'wgNamespaceIds' ).category );
|
2014-02-14 20:03:42 +00:00
|
|
|
// Create a widget using the item data
|
2014-03-11 19:02:16 +00:00
|
|
|
config = {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: categoryWidget.$,
|
2014-09-24 22:18:09 +00:00
|
|
|
item: item
|
2014-03-11 19:02:16 +00:00
|
|
|
};
|
2014-10-15 20:07:39 +00:00
|
|
|
if ( Object.prototype.hasOwnProperty.call( categoryWidget.categoryRedirects, itemTitle.getPrefixedText() ) ) {
|
2014-03-11 19:02:16 +00:00
|
|
|
config.redirectTo = new mw.Title(
|
2014-10-15 20:07:39 +00:00
|
|
|
categoryWidget.categoryRedirects[itemTitle.getPrefixedText()],
|
2014-03-11 19:02:16 +00:00
|
|
|
mw.config.get( 'wgNamespaceIds' ).category
|
|
|
|
).getMainText();
|
2014-10-15 20:07:39 +00:00
|
|
|
cachedData = ve.init.platform.linkCache.getCached( categoryWidget.categoryRedirects[itemTitle.getPrefixedText()] );
|
2014-09-24 22:18:09 +00:00
|
|
|
} else {
|
2014-11-05 22:45:09 +00:00
|
|
|
cachedData = ve.init.platform.linkCache.getCached( item.name );
|
2014-03-11 19:02:16 +00:00
|
|
|
}
|
2014-10-15 20:07:39 +00:00
|
|
|
config.hidden = cachedData.hidden;
|
|
|
|
config.missing = cachedData.missing;
|
|
|
|
|
2014-03-11 19:02:16 +00:00
|
|
|
categoryItem = new ve.ui.MWCategoryItemWidget( config );
|
2014-02-14 20:03:42 +00:00
|
|
|
categoryItem.connect( categoryWidget, {
|
2014-08-22 20:50:48 +00:00
|
|
|
savePopupState: 'onSavePopupState',
|
|
|
|
togglePopupMenu: 'onTogglePopupMenu'
|
2014-02-14 20:03:42 +00:00
|
|
|
} );
|
|
|
|
|
2014-10-15 20:07:39 +00:00
|
|
|
// Index item
|
|
|
|
categoryWidget.categories[itemTitle.getMainText()] = categoryItem;
|
2014-02-14 20:03:42 +00:00
|
|
|
// Copy sortKey from old item when "moving"
|
2014-11-14 20:44:55 +00:00
|
|
|
existingCategoryItems = $.grep( categoryWidget.items, checkValueMatches );
|
|
|
|
if ( existingCategoryItems.length ) {
|
|
|
|
// There should only be one element in existingCategoryItems
|
|
|
|
categoryItem.sortKey = existingCategoryItems[0].sortKey;
|
|
|
|
categoryWidget.removeItems( [ existingCategoryItems[0] ] );
|
2014-02-14 20:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
categoryItems.push( categoryItem );
|
2013-04-29 21:01:56 +00:00
|
|
|
}
|
2013-05-03 18:30:33 +00:00
|
|
|
|
2014-11-14 20:44:55 +00:00
|
|
|
OO.ui.DraggableGroupElement.prototype.addItems.call( categoryWidget, categoryItems, index );
|
2013-05-03 18:30:33 +00:00
|
|
|
|
2014-02-14 20:03:42 +00:00
|
|
|
categoryWidget.fitInput();
|
|
|
|
} );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-14 20:44:55 +00:00
|
|
|
* @inheritdoc
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2014-11-14 20:44:55 +00:00
|
|
|
ve.ui.MWCategoryWidget.prototype.removeItems = function ( items ) {
|
|
|
|
var i, len, categoryItem;
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2014-11-14 20:44:55 +00:00
|
|
|
for ( i = 0, len = items.length; i < len; i++ ) {
|
|
|
|
categoryItem = items[i];
|
2014-09-30 18:11:09 +00:00
|
|
|
if ( categoryItem ) {
|
|
|
|
categoryItem.disconnect( this );
|
|
|
|
items.push( categoryItem );
|
2014-11-14 20:44:55 +00:00
|
|
|
delete this.categories[categoryItem.value];
|
2014-09-30 18:11:09 +00:00
|
|
|
}
|
2013-04-29 21:01:56 +00:00
|
|
|
}
|
2013-05-03 18:30:33 +00:00
|
|
|
|
2014-11-14 20:44:55 +00:00
|
|
|
OO.ui.DraggableGroupElement.prototype.removeItems.call( this, items );
|
2013-05-03 18:30:33 +00:00
|
|
|
|
|
|
|
this.fitInput();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Auto-fit the input.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryWidget.prototype.fitInput = function () {
|
2013-06-12 23:25:28 +00:00
|
|
|
var gap, min, $lastItem,
|
2013-11-01 19:45:59 +00:00
|
|
|
$input = this.input.$element;
|
2013-05-03 18:30:33 +00:00
|
|
|
|
2015-01-31 00:41:37 +00:00
|
|
|
if ( !$input.is( ':visible' ) ) {
|
2013-05-03 18:30:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
$input.css( { width: 'inherit' } );
|
2013-05-03 18:30:33 +00:00
|
|
|
min = $input.outerWidth();
|
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
$input.css( { width: '100%' } );
|
2013-11-01 19:45:59 +00:00
|
|
|
$lastItem = this.$element.find( '.ve-ui-mwCategoryItemWidget:last' );
|
2013-05-03 18:30:33 +00:00
|
|
|
if ( $lastItem.length ) {
|
|
|
|
// Try to fit to the right of the last item
|
|
|
|
gap = ( $input.offset().left + $input.outerWidth() ) -
|
|
|
|
( $lastItem.offset().left + $lastItem.outerWidth() );
|
|
|
|
if ( gap >= min ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
$input.css( { width: gap } );
|
2013-05-03 18:30:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|