Index: trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js |
— | — | @@ -7,71 +7,74 @@ |
8 | 8 | * Credits: http://jqueryui.com/demos/autocomplete/#multiple |
9 | 9 | */ |
10 | 10 | jQuery( function( $ ) { |
| 11 | + "use strict" |
| 12 | + |
11 | 13 | $.widget( "ui.combobox", { |
12 | | - _create: function() { |
13 | | - var self = this, |
14 | | - select = this.element.hide(), |
15 | | - selected = select.children( ":selected" ); |
16 | | - function split( val ) { |
17 | | - return val.split( /,\s*/ ); |
18 | | - } |
19 | | - var input = this.input = $( '#tpt-prioritylangs' ) |
20 | | - .autocomplete( { |
21 | | - delay: 0, |
22 | | - minLength: 0, |
23 | | - source: function( request, response ) { |
24 | | - var term = split( request.term ).pop(); |
25 | | - var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" ); |
26 | | - response( select.children( "option" ).map(function() { |
27 | | - var text = $( this ).text(); |
28 | | - var value = $( this ).val(); |
29 | | - var term = split( request.term ).pop(); |
30 | | - if ( this.value && ( !request.term || matcher.test(text) ) ) |
31 | | - return { |
32 | | - label: text.replace( |
33 | | - new RegExp( |
34 | | - "(?![^&;]+;)(?!<[^<>]*)(" + |
35 | | - $.ui.autocomplete.escapeRegex(term) + |
36 | | - ")(?![^<>]*>)(?![^&;]+;)", "gi" |
37 | | - ), "<strong>$1</strong>" ), |
38 | | - value: value, |
39 | | - option: this |
40 | | - }; |
41 | | - }) ); |
42 | | - }, |
43 | | - select: function( event, ui ) { |
44 | | - ui.item.option.selected = true; |
45 | | - self._trigger( "selected", event, { |
46 | | - item: ui.item.option |
47 | | - }); |
48 | | - var terms = split( $(this).val() ); |
49 | | - // remove the current input |
50 | | - terms.pop(); |
51 | | - // add the selected item |
52 | | - terms.push( ui.item.value ); |
53 | | - // add placeholder to get the comma-and-space at the end |
54 | | - terms.push( "" ); |
55 | | - $( this ).val( terms.join( ", " ) ); |
56 | | - return false; |
| 14 | + _create: function() { |
| 15 | + var self = this, |
| 16 | + select = this.element.hide(), |
| 17 | + selected = select.children( ":selected" ); |
| 18 | + |
| 19 | + function split( val ) { |
| 20 | + return val.split( /,\s*/ ); |
57 | 21 | } |
58 | 22 | |
59 | | - }); |
| 23 | + var input = this.input = $( '#tpt-prioritylangs' ) |
| 24 | + .autocomplete( { |
| 25 | + delay: 0, |
| 26 | + minLength: 0, |
| 27 | + source: function( request, response ) { |
| 28 | + var term = split( request.term ).pop(); |
| 29 | + var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" ); |
| 30 | + response( select.children( "option" ).map( function() { |
| 31 | + var text = $( this ).text(); |
| 32 | + var value = $( this ).val(); |
| 33 | + var term = split( request.term ).pop(); |
| 34 | + if ( this.value && ( !request.term || matcher.test(text) ) ) { |
| 35 | + return { |
| 36 | + label: text.replace( |
| 37 | + new RegExp( |
| 38 | + "(?![^&;]+;)(?!<[^<>]*)(" + |
| 39 | + $.ui.autocomplete.escapeRegex( term ) + |
| 40 | + ")(?![^<>]*>)(?![^&;]+;)", "gi" |
| 41 | + ), "<strong>$1</strong>" ), |
| 42 | + value: value, |
| 43 | + option: this |
| 44 | + }; |
| 45 | + } |
| 46 | + } ) ); |
| 47 | + }, |
| 48 | + select: function( event, ui ) { |
| 49 | + ui.item.option.selected = true; |
| 50 | + self._trigger( "selected", event, { |
| 51 | + item: ui.item.option |
| 52 | + }); |
| 53 | + var terms = split( $(this).val() ); |
| 54 | + // remove the current input |
| 55 | + terms.pop(); |
| 56 | + // add the selected item |
| 57 | + terms.push( ui.item.value ); |
| 58 | + // add placeholder to get the comma-and-space at the end |
| 59 | + terms.push( "" ); |
| 60 | + $( this ).val( terms.join( ", " ) ); |
| 61 | + return false; |
| 62 | + } |
| 63 | + } ); |
60 | 64 | |
61 | | - input.data( "autocomplete" )._renderItem = function( ul, item ) { |
62 | | - return $( "<li></li>" ) |
63 | | - .data( "item.autocomplete", item ) |
64 | | - .append( "<a>" + item.label + "</a>" ) |
65 | | - .appendTo( ul ); |
66 | | - }; |
| 65 | + input.data( "autocomplete" )._renderItem = function( ul, item ) { |
| 66 | + return $( "<li>" ) |
| 67 | + .data( "item.autocomplete", item ) |
| 68 | + .append( "<a>" + item.label + "</a>" ) |
| 69 | + .appendTo( ul ); |
| 70 | + }; |
| 71 | + }, // End of _create |
67 | 72 | |
68 | | - }, |
| 73 | + destroy: function() { |
| 74 | + this.input.remove(); |
| 75 | + this.element.show(); |
| 76 | + $.Widget.prototype.destroy.call( this ); |
| 77 | + } |
| 78 | + } ); |
69 | 79 | |
70 | | - destroy: function() { |
71 | | - this.input.remove(); |
72 | | - this.element.show(); |
73 | | - $.Widget.prototype.destroy.call( this ); |
74 | | - } |
75 | | - }); |
76 | | - |
77 | 80 | $( "#wpUserLanguage" ).combobox(); |
78 | 81 | } ); |