summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/resources/js/ext.translate.special.operatorsuggest.js
blob: 362a259e24b5d1939238d9f994872240e9a0b5fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Autocomplete search operators.
 */
( function ( mw, $ ) {
	'use strict';

	function autocompleteOperators( request, response ) {
		var operators = [ 'language:', 'group:', 'filter:' ],
			result = [],
			lastterm = request.term.split( ' ' ).pop();

		$.each( operators, function ( index, value ) {
			var pos = value.indexOf( lastterm );
			if ( pos === 0 ) {
				result.push( value );
			}
		} );
		response( result );
	}

	$( '.tux-searchpage .searchinputbox' )
		.autocomplete( {
			source: autocompleteOperators,
			select: function ( event, ui ) {
				var $value = $( this ).val(),
					operators = $value.split( ' ' );

				operators.pop();
				operators.push( ui.item.value );

				$( this ).val( operators.join( ' ' ) );
				return false;
			},

			focus: function ( event ) {
				event.preventDefault();
			}
		} );
}( mediaWiki, jQuery ) );