mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-05 22:22:54 +00:00
23b2da91fd
Objectives: * Allow adding content or templates within a transclusion * Add template placeholder to model and view which resolves to nothing when saving (thus disappearing if not resolved) Changes: *.php * Add links to new messages and files ve.ui.OutlineControlsWidget.js * Organize controls into "adders" and "movers" ve.ui.Widget.css * Add styles for adders/movers sections of outline controls * Make adders appear on hover to reduce clutter ve.ui.Icons-*.css * Add icon for "add item" ve.ui.Dialog.css * Add styles for add template fieldsets * Make placeholder items in the outline italic ve.ui.PagedDialog.js * Pass adders config to outline controls ve.ui.MWTransclusionDialog.js * Add support for adding content and templates ve.dm.MWTransclusionModel.js * Add addPlaceholder method ve.dm.MWTemplatePlaceholderModel.js * New class, pretty much an empty part * Using this makes the UI much easier to work with - no need to special case the outline control for new items * Because it's not supported specifically in ve.dm.MWTransclusionModel.getPlainObject, it produces nothing and goes away naturally on apply Change-Id: I3478560fb53ba2ccd3fb26bafb6a61e6415565eb
146 lines
3.6 KiB
JavaScript
146 lines
3.6 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWTitleInputWidget class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/*global mw*/
|
|
|
|
/**
|
|
* Creates an ve.ui.MWTitleInputWidget object.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.TextInputWidget
|
|
* @mixins ve.ui.LookupInputWidget
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Config options
|
|
* @param {number} [namespace] Namespace to prepend to queries not prefixed with ':'
|
|
*/
|
|
ve.ui.MWTitleInputWidget = function VeUiMWTitleInputWidget( config ) {
|
|
// Config intialization
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
ve.ui.TextInputWidget.call( this, config );
|
|
|
|
// Mixin constructors
|
|
ve.ui.LookupInputWidget.call( this, this, config );
|
|
|
|
// Properties
|
|
this.namespace = config.namespace || null;
|
|
|
|
// Events
|
|
this.lookupMenu.connect( this, { 'select': 'onLookupMenuItemSelect' } );
|
|
|
|
// Initialization
|
|
this.$.addClass( 've-ui-mwTitleInputWidget' );
|
|
this.lookupMenu.$.addClass( 've-ui-mwTitleInputWidget-menu' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.MWTitleInputWidget, ve.ui.TextInputWidget );
|
|
|
|
ve.mixinClass( ve.ui.MWTitleInputWidget, ve.ui.LookupInputWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle menu item select event.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.MenuItemWidget} item Selected item
|
|
*/
|
|
ve.ui.MWTitleInputWidget.prototype.onLookupMenuItemSelect = function ( item ) {
|
|
if ( item ) {
|
|
this.setValue( item.getData() );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Gets a new request object of the current lookup query value.
|
|
*
|
|
* @method
|
|
* @returns {jQuery.Deferred} Deferred object with success and fail handlers already attached
|
|
*/
|
|
ve.ui.MWTitleInputWidget.prototype.getLookupRequest = function () {
|
|
var value = this.value;
|
|
|
|
// Prefix with default namespace name
|
|
if ( this.namespace !== null && value.charAt( 0 ) !== ':' ) {
|
|
value = mw.config.get( 'wgFormattedNamespaces' )[this.namespace] + ':' + value;
|
|
}
|
|
|
|
// Dont send leading ':' to open search
|
|
if ( value.charAt( 0 ) === ':' ) {
|
|
value = value.substr( 1 );
|
|
}
|
|
|
|
return $.ajax( {
|
|
'url': mw.util.wikiScript( 'api' ),
|
|
'data': {
|
|
'format': 'json',
|
|
'action': 'opensearch',
|
|
'search': value,
|
|
'suggest': ''
|
|
},
|
|
'dataType': 'json'
|
|
} );
|
|
};
|
|
|
|
/**
|
|
* Get lookup cache item from server response data.
|
|
*
|
|
* @method
|
|
* @param {Mixed} data Response from server
|
|
*/
|
|
ve.ui.MWTitleInputWidget.prototype.getLookupCacheItemFromData = function ( data ) {
|
|
return ve.isArray( data ) && data.length ? data[1] : [];
|
|
};
|
|
|
|
/**
|
|
* Get list of menu items from a server response.
|
|
*
|
|
* @param {Object} data Query result
|
|
* @returns {ve.ui.MenuItemWidget[]} Menu items
|
|
*/
|
|
ve.ui.MWTitleInputWidget.prototype.getLookupMenuItemsFromData = function ( data ) {
|
|
var i, len, title, value,
|
|
menu$$ = this.lookupMenu.$$,
|
|
items = [],
|
|
matchingPages = data;
|
|
|
|
// Matching pages
|
|
if ( matchingPages && matchingPages.length ) {
|
|
for ( i = 0, len = matchingPages.length; i < len; i++ ) {
|
|
title = new mw.Title( matchingPages[i] );
|
|
if ( this.namespace !== null ) {
|
|
value = title.getNamespaceId() === this.namespace ?
|
|
title.getNameText() : ':' + title.getPrefixedText();
|
|
} else {
|
|
value = title.getPrefixedText();
|
|
}
|
|
items.push( new ve.ui.MenuItemWidget(
|
|
value, { '$$': menu$$, 'label': value }
|
|
) );
|
|
}
|
|
}
|
|
|
|
return items;
|
|
};
|
|
|
|
/**
|
|
* Set selection in the lookup menu with current information.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
ve.ui.MWTitleInputWidget.prototype.initializeLookupMenuSelection = function () {
|
|
// Attempt to maintain selection on current annotation
|
|
this.lookupMenu.selectItem( this.lookupMenu.getItemFromData( this.annotation ), true );
|
|
// Parent method
|
|
ve.ui.LookupInputWidget.prototype.initializeLookupMenuSelection.call( this );
|
|
};
|