mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
130e446e52
Objectives: * Reduce the number of clicks and mouse maneuvers required to insert media, references or template parameters * Make use of highlighting with mouse movement or arrow key presses, similar to menus, to suggest action when clicked * Improve the way media search results look and feel Changes: ve.ui.SelectWidget.js * Add mouseleave handler to un-highlight when the mouse exits the widget * Document highlight events (already being emitted) ve.ui.SearchWidget.js * Propagate both select and highlight events from results widget * Make arrow keys change highlight instead of selection * Get rid of enter event, make enter key select highlighted item instead * Provide direct access to results widget through getResults method ve.ui.MenuWidget.js * Use the selected item as a starting point if nothing is currently highlighted when adjusting the highlight position ve.ui.Dialog.js * Add footless option to hide the foot element and make the body extend all the way down to the bottom * Remove applyButton, which only some dialogs need, and should be creating themselves, along with other buttons as needed ve.ui.Widget.css * Change highlight and selected colors of option widgets to match other selection colors used elsewhere * Leave selected and highlighted widget looking selected ve.ui.Frame.css * Add background color to combat any color that might have been applied to the frame body in the imported CSS from the parent frame ve.ui.Dialog.css * Add rules for footless mode ve.ui.MWReferenceResultWidget.js, ve.ui.MWParameterResultWidget.js, ve.ui.MWMediaResultWidget.js * Allow highlighting ve.ui.MWParamterSearchWidget.js * Switch from selecting the first item when filtering to highlighting ve-mw/ve.ui.Widget.js * Adjust media result widget styling to better match other elements ve.ui.MWTransclusionDialog.js, ve.ui.MWReferenceListDialog.js, ve.ui.MWReferenceEditDialog.js, ve.ui.MWMetaDialog.js ve.ui.MWMediaEditDialog.js * Add apply button, as per it being removed from parent class ve.ui.MWTransclusionDialog.js, ve.ui.MWReferenceInsertDialog.js, ve.ui.MWMediaInsertDialog.js * Insert parameter/reference/media on select, instead of clicking an insert button * Use 'insert' instead of 'apply' as argument for close method Bug: 50774 Bug: 51143 Change-Id: Ia18e79f1f8df2540f465468edb01f5ce989bf843
164 lines
3.6 KiB
JavaScript
164 lines
3.6 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface SearchWidget class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.SearchWidget object.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.Widget
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Config options
|
|
* @cfg {string|jQuery} [placeholder] Placeholder text for query input
|
|
* @cfg {string} [value] Initial query value
|
|
*/
|
|
ve.ui.SearchWidget = function VeUiSearchWidget( config ) {
|
|
// Configuration intialization
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
ve.ui.Widget.call( this, config );
|
|
|
|
// Properties
|
|
this.query = new ve.ui.TextInputWidget( {
|
|
'$$': this.$$,
|
|
'icon': 'search',
|
|
'placeholder': config.placeholder,
|
|
'value': config.value
|
|
} );
|
|
this.results = new ve.ui.SelectWidget( { '$$': this.$$ } );
|
|
this.$query = this.$$( '<div>' );
|
|
this.$results = this.$$( '<div>' );
|
|
|
|
// Events
|
|
this.query.connect( this, {
|
|
'change': 'onQueryChange',
|
|
'enter': 'onQueryEnter'
|
|
} );
|
|
this.results.connect( this, {
|
|
'highlight': 'onResultsHighlight',
|
|
'select': 'onResultsSelect'
|
|
} );
|
|
this.query.$input.on( 'keydown', ve.bind( this.onQueryKeydown, this ) );
|
|
|
|
// Initialization
|
|
this.$query
|
|
.addClass( 've-ui-searchWidget-query' )
|
|
.append( this.query.$ );
|
|
this.$results
|
|
.addClass( 've-ui-searchWidget-results' )
|
|
.append( this.results.$ );
|
|
this.$
|
|
.addClass( 've-ui-searchWidget' )
|
|
.append( this.$results, this.$query );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.SearchWidget, ve.ui.Widget );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event highlight
|
|
* @param {Object|null} item Item data or null if no item is highlighted
|
|
*/
|
|
|
|
/**
|
|
* @event select
|
|
* @param {Object|null} item Item data or null if no item is selected
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle query key down events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Key down event
|
|
*/
|
|
ve.ui.SearchWidget.prototype.onQueryKeydown = function ( e ) {
|
|
var highlightedItem,
|
|
dir = e.which === ve.Keys.DOWN ? 1 : ( e.which === ve.Keys.UP ? -1 : 0 );
|
|
|
|
if ( dir ) {
|
|
highlightedItem = this.results.getHighlightedItem();
|
|
if ( !highlightedItem ) {
|
|
highlightedItem = this.results.getSelectedItem();
|
|
}
|
|
this.results.highlightItem( this.results.getRelativeSelectableItem( highlightedItem, dir ) );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle select widget select events.
|
|
*
|
|
* Clears existing results. Subclasses should repopulate items according to new query.
|
|
*
|
|
* @method
|
|
* @param {string} value New value
|
|
*/
|
|
ve.ui.SearchWidget.prototype.onQueryChange = function () {
|
|
// Reset
|
|
this.results.clearItems();
|
|
};
|
|
|
|
/**
|
|
* Handle select widget enter key events.
|
|
*
|
|
* Selects highlighted item.
|
|
*
|
|
* @method
|
|
* @param {string} value New value
|
|
*/
|
|
ve.ui.SearchWidget.prototype.onQueryEnter = function () {
|
|
// Reset
|
|
this.results.selectItem( this.results.getHighlightedItem() );
|
|
};
|
|
|
|
/**
|
|
* Handle select widget highlight events.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.OptionWidget} item Highlighted item
|
|
* @emits highlight
|
|
*/
|
|
ve.ui.SearchWidget.prototype.onResultsHighlight = function ( item ) {
|
|
this.emit( 'highlight', item ? item.getData() : null );
|
|
};
|
|
|
|
/**
|
|
* Handle select widget select events.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.OptionWidget} item Selected item
|
|
* @emits select
|
|
*/
|
|
ve.ui.SearchWidget.prototype.onResultsSelect = function ( item ) {
|
|
this.emit( 'select', item ? item.getData() : null );
|
|
};
|
|
|
|
/**
|
|
* Get the query input.
|
|
*
|
|
* @method
|
|
* @returns {ve.ui.TextInputWidget} Query input
|
|
*/
|
|
ve.ui.SearchWidget.prototype.getQuery = function () {
|
|
return this.query;
|
|
};
|
|
|
|
/**
|
|
* Get the results list.
|
|
*
|
|
* @method
|
|
* @returns {ve.ui.SelectWidget} Select list
|
|
*/
|
|
ve.ui.SearchWidget.prototype.getResults = function () {
|
|
return this.results;
|
|
};
|