Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -249,11 +249,19 @@ |
250 | 250 | ), |
251 | 251 | ) + $resourcePaths; |
252 | 252 | |
| 253 | +$wgResourceModules['ext.translate.multiselectautocomplete'] = array( |
| 254 | + 'scripts' => 'resources/ext.translate.multiselectautocomplete.js', |
| 255 | + 'dependencies' => array( |
| 256 | + 'jquery.ui.autocomplete', |
| 257 | + ), |
| 258 | + 'position' => 'top', |
| 259 | +) + $resourcePaths; |
| 260 | + |
253 | 261 | $wgResourceModules['ext.translate.special.pagetranslation'] = array( |
254 | 262 | 'scripts' => 'resources/ext.translate.special.pagetranslation.js', |
255 | 263 | 'styles' => 'resources/ext.translate.special.pagetranslation.css', |
256 | 264 | 'dependencies' => array( |
257 | | - 'jquery.ui.autocomplete', |
| 265 | + 'ext.translate.multiselectautocomplete', |
258 | 266 | ), |
259 | 267 | 'position' => 'top', |
260 | 268 | ) + $resourcePaths; |
Index: trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js |
— | — | @@ -7,76 +7,5 @@ |
8 | 8 | * Credits: http://jqueryui.com/demos/autocomplete/#multiple |
9 | 9 | */ |
10 | 10 | jQuery( function( $ ) { |
11 | | - "use strict" |
12 | | - |
13 | | - $.widget( "ui.multiselectautocomplete", { |
14 | | - options: { |
15 | | - inputbox: null, // a jQuery selector for the input box where selections are written. |
16 | | - // @TODO can have more options. |
17 | | - }, |
18 | | - _create: function() { |
19 | | - var self = this, |
20 | | - select = this.element.hide(), |
21 | | - options = this.options; |
22 | | - function split( val ) { |
23 | | - return val.split( /,\s*/ ); |
24 | | - } |
25 | | - |
26 | | - var input = this.input = $( options.inputbox ).autocomplete( { |
27 | | - delay: 0, |
28 | | - minLength: 0, |
29 | | - source: function( request, response ) { |
30 | | - var term = split( request.term ).pop(); |
31 | | - var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" ); |
32 | | - response( select.children( "option" ).map( function() { |
33 | | - var text = $( this ).text(); |
34 | | - var value = $( this ).val(); |
35 | | - var term = split( request.term ).pop(); |
36 | | - if ( this.value && ( !request.term || matcher.test(text) ) ) { |
37 | | - return { |
38 | | - label: text.replace( |
39 | | - new RegExp( |
40 | | - "(?![^&;]+;)(?!<[^<>]*)(" + |
41 | | - $.ui.autocomplete.escapeRegex( term ) + |
42 | | - ")(?![^<>]*>)(?![^&;]+;)", "gi" |
43 | | - ), "<strong>$1</strong>" ), |
44 | | - value: value, |
45 | | - option: this |
46 | | - }; |
47 | | - } |
48 | | - } ) ); |
49 | | - }, |
50 | | - select: function( event, ui ) { |
51 | | - ui.item.option.selected = true; |
52 | | - self._trigger( "selected", event, { |
53 | | - item: ui.item.option |
54 | | - }); |
55 | | - var terms = split( $(this).val() ); |
56 | | - // remove the current input |
57 | | - terms.pop(); |
58 | | - // add the selected item |
59 | | - terms.push( ui.item.value ); |
60 | | - // add placeholder to get the comma-and-space at the end |
61 | | - terms.push( "" ); |
62 | | - $( this ).val( terms.join( ", " ) ); |
63 | | - return false; |
64 | | - } |
65 | | - } ); |
66 | | - |
67 | | - input.data( "autocomplete" )._renderItem = function( ul, item ) { |
68 | | - return $( "<li>" ) |
69 | | - .data( "item.autocomplete", item ) |
70 | | - .append( "<a>" + item.label + "</a>" ) |
71 | | - .appendTo( ul ); |
72 | | - }; |
73 | | - }, // End of _create |
74 | | - |
75 | | - destroy: function() { |
76 | | - this.input.remove(); |
77 | | - this.element.show(); |
78 | | - $.Widget.prototype.destroy.call( this ); |
79 | | - } |
80 | | - } ); |
81 | | - |
82 | 11 | $( "#wpUserLanguage" ).multiselectautocomplete( { inputbox : '#tpt-prioritylangs' } ); |
83 | 12 | } ); |
Index: trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js |
— | — | @@ -0,0 +1,80 @@ |
| 2 | +/* |
| 3 | + * @author Santhosh Thottingal |
| 4 | + * jQuery autocomplete based multiple selector for input box. |
| 5 | + * Autocompleted values will be available in input filed as comma separated values. |
| 6 | + * The values for autocompletion is from the language selector in this case. |
| 7 | + * The input field is created in PHP code. |
| 8 | + * Credits: http://jqueryui.com/demos/autocomplete/#multiple |
| 9 | + */ |
| 10 | +jQuery( function( $ ) { |
| 11 | + "use strict" |
| 12 | + |
| 13 | + $.widget( "ui.multiselectautocomplete", { |
| 14 | + options: { |
| 15 | + inputbox: null, // a jQuery selector for the input box where selections are written. |
| 16 | + // @TODO can have more options. |
| 17 | + }, |
| 18 | + _create: function() { |
| 19 | + var self = this, |
| 20 | + select = this.element.hide(), |
| 21 | + options = this.options; |
| 22 | + function split( val ) { |
| 23 | + return val.split( /,\s*/ ); |
| 24 | + } |
| 25 | + |
| 26 | + var input = this.input = $( options.inputbox ).autocomplete( { |
| 27 | + delay: 0, |
| 28 | + minLength: 0, |
| 29 | + source: function( request, response ) { |
| 30 | + var term = split( request.term ).pop(); |
| 31 | + var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" ); |
| 32 | + response( select.children( "option" ).map( function() { |
| 33 | + var text = $( this ).text(); |
| 34 | + var value = $( this ).val(); |
| 35 | + var term = split( request.term ).pop(); |
| 36 | + if ( this.value && ( !request.term || matcher.test(text) ) ) { |
| 37 | + return { |
| 38 | + label: text.replace( |
| 39 | + new RegExp( |
| 40 | + "(?![^&;]+;)(?!<[^<>]*)(" + |
| 41 | + $.ui.autocomplete.escapeRegex( term ) + |
| 42 | + ")(?![^<>]*>)(?![^&;]+;)", "gi" |
| 43 | + ), "<strong>$1</strong>" ), |
| 44 | + value: value, |
| 45 | + option: this |
| 46 | + }; |
| 47 | + } |
| 48 | + } ) ); |
| 49 | + }, |
| 50 | + select: function( event, ui ) { |
| 51 | + ui.item.option.selected = true; |
| 52 | + self._trigger( "selected", event, { |
| 53 | + item: ui.item.option |
| 54 | + }); |
| 55 | + var terms = split( $(this).val() ); |
| 56 | + // remove the current input |
| 57 | + terms.pop(); |
| 58 | + // add the selected item |
| 59 | + terms.push( ui.item.value ); |
| 60 | + // add placeholder to get the comma-and-space at the end |
| 61 | + terms.push( "" ); |
| 62 | + $( this ).val( terms.join( ", " ) ); |
| 63 | + return false; |
| 64 | + } |
| 65 | + } ); |
| 66 | + |
| 67 | + input.data( "autocomplete" )._renderItem = function( ul, item ) { |
| 68 | + return $( "<li>" ) |
| 69 | + .data( "item.autocomplete", item ) |
| 70 | + .append( "<a>" + item.label + "</a>" ) |
| 71 | + .appendTo( ul ); |
| 72 | + }; |
| 73 | + }, // End of _create |
| 74 | + |
| 75 | + destroy: function() { |
| 76 | + this.input.remove(); |
| 77 | + this.element.show(); |
| 78 | + $.Widget.prototype.destroy.call( this ); |
| 79 | + } |
| 80 | + } ); |
| 81 | +} ); |
Property changes on: trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 82 | + native |