https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114250

Revision: 114250
Author:   amire80
Date:     2012-03-20 10:58:10 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
Refactoring ext.translate.special.pagetranslation.js to make it reusable: The 
generic autocompletion funcionality is in 
ext.translate.multiselectautocomplete.js and 
ext.translate.special.pagetranslation.js only applies it to 
Special:PageTranslation.

Modified Paths:
--------------
    trunk/extensions/Translate/Translate.php
    
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js

Added Paths:
-----------
    
trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js

Modified: trunk/extensions/Translate/Translate.php
===================================================================
--- trunk/extensions/Translate/Translate.php    2012-03-20 10:46:16 UTC (rev 
114249)
+++ trunk/extensions/Translate/Translate.php    2012-03-20 10:58:10 UTC (rev 
114250)
@@ -249,11 +249,19 @@
        ),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.translate.multiselectautocomplete'] = array(
+       'scripts' => 'resources/ext.translate.multiselectautocomplete.js',
+       'dependencies' => array(
+               'jquery.ui.autocomplete',
+       ),
+       'position' => 'top',
+) + $resourcePaths;
+
 $wgResourceModules['ext.translate.special.pagetranslation'] = array(
        'scripts' => 'resources/ext.translate.special.pagetranslation.js',
        'styles' => 'resources/ext.translate.special.pagetranslation.css',
        'dependencies' => array(
-               'jquery.ui.autocomplete',
+               'ext.translate.multiselectautocomplete',
        ),
        'position' => 'top',
 ) + $resourcePaths;

Copied: 
trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js 
(from rev 114245, 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js)
===================================================================
--- 
trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js   
                            (rev 0)
+++ 
trunk/extensions/Translate/resources/ext.translate.multiselectautocomplete.js   
    2012-03-20 10:58:10 UTC (rev 114250)
@@ -0,0 +1,80 @@
+/*
+ * @author Santhosh Thottingal
+ * jQuery autocomplete based multiple selector for input box.
+ * Autocompleted values will be available in input filed as comma separated 
values.
+ * The values for autocompletion is from the language selector in this case.
+ * The input field is created in PHP code.
+ * Credits: http://jqueryui.com/demos/autocomplete/#multiple
+ */
+jQuery( function( $ ) {
+       "use strict"
+       
+       $.widget( "ui.multiselectautocomplete", {
+               options: { 
+                       inputbox: null, // a jQuery selector for the input box 
where selections are written.
+                       // @TODO can have more options.
+               },
+               _create: function() {
+                       var self = this,
+                               select = this.element.hide(),
+                               options = this.options;
+                       function split( val ) {
+                               return val.split( /,\s*/ );
+                       }
+                       
+                       var input = this.input = $( options.inputbox 
).autocomplete( {
+                               delay: 0,
+                               minLength: 0,
+                               source: function( request, response ) {
+                                       var term = split( request.term ).pop();
+                                       var matcher = new RegExp( 
$.ui.autocomplete.escapeRegex( term ), "i" );
+                                       response( select.children( "option" 
).map( function() {
+                                               var text = $( this ).text();
+                                               var value = $( this ).val();
+                                               var term = split( request.term 
).pop();
+                                               if ( this.value && ( 
!request.term || matcher.test(text) ) ) {
+                                                       return {
+                                                               label: 
text.replace(
+                                                                       new 
RegExp(
+                                                                       
"(?![^&;]+;)(?!<[^<>]*)(" +
+                                                                       
$.ui.autocomplete.escapeRegex( term ) +
+                                                                       
")(?![^<>]*>)(?![^&;]+;)", "gi"
+                                                                       ), 
"<strong>$1</strong>" ),
+                                                               value: value,
+                                                               option: this
+                                                       };
+                                               }
+                                       } ) );
+                               },
+                               select: function( event, ui ) {
+                                       ui.item.option.selected = true;
+                                       self._trigger( "selected", event, {
+                                               item: ui.item.option
+                                       });
+                                       var terms = split( $(this).val() );
+                                       // remove the current input
+                                       terms.pop();
+                                       // add the selected item
+                                       terms.push( ui.item.value );
+                                       // add placeholder to get the 
comma-and-space at the end
+                                       terms.push( "" );
+                                       $( this ).val( terms.join( ", " ) );
+                                       return false;
+                               }
+                       } );
+
+                       input.data( "autocomplete" )._renderItem = function( 
ul, item ) {
+                               return $( "<li>" )
+                                       .data( "item.autocomplete", item )
+                                       .append( "<a>" + item.label + "</a>" )
+                                       .appendTo( ul );
+                       };
+               }, // End of _create
+
+               destroy: function() {
+                       this.input.remove();
+                       this.element.show();
+                       $.Widget.prototype.destroy.call( this );
+               }
+       } );
+} );

Modified: 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js
===================================================================
--- 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js   
    2012-03-20 10:46:16 UTC (rev 114249)
+++ 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js   
    2012-03-20 10:58:10 UTC (rev 114250)
@@ -7,76 +7,5 @@
  * Credits: http://jqueryui.com/demos/autocomplete/#multiple
  */
 jQuery( function( $ ) {
-       "use strict"
-       
-       $.widget( "ui.multiselectautocomplete", {
-               options: { 
-                       inputbox: null, // a jQuery selector for the input box 
where selections are written.
-                       // @TODO can have more options.
-               },
-               _create: function() {
-                       var self = this,
-                               select = this.element.hide(),
-                               options = this.options;
-                       function split( val ) {
-                               return val.split( /,\s*/ );
-                       }
-                       
-                       var input = this.input = $( options.inputbox 
).autocomplete( {
-                               delay: 0,
-                               minLength: 0,
-                               source: function( request, response ) {
-                                       var term = split( request.term ).pop();
-                                       var matcher = new RegExp( 
$.ui.autocomplete.escapeRegex( term ), "i" );
-                                       response( select.children( "option" 
).map( function() {
-                                               var text = $( this ).text();
-                                               var value = $( this ).val();
-                                               var term = split( request.term 
).pop();
-                                               if ( this.value && ( 
!request.term || matcher.test(text) ) ) {
-                                                       return {
-                                                               label: 
text.replace(
-                                                                       new 
RegExp(
-                                                                       
"(?![^&;]+;)(?!<[^<>]*)(" +
-                                                                       
$.ui.autocomplete.escapeRegex( term ) +
-                                                                       
")(?![^<>]*>)(?![^&;]+;)", "gi"
-                                                                       ), 
"<strong>$1</strong>" ),
-                                                               value: value,
-                                                               option: this
-                                                       };
-                                               }
-                                       } ) );
-                               },
-                               select: function( event, ui ) {
-                                       ui.item.option.selected = true;
-                                       self._trigger( "selected", event, {
-                                               item: ui.item.option
-                                       });
-                                       var terms = split( $(this).val() );
-                                       // remove the current input
-                                       terms.pop();
-                                       // add the selected item
-                                       terms.push( ui.item.value );
-                                       // add placeholder to get the 
comma-and-space at the end
-                                       terms.push( "" );
-                                       $( this ).val( terms.join( ", " ) );
-                                       return false;
-                               }
-                       } );
-
-                       input.data( "autocomplete" )._renderItem = function( 
ul, item ) {
-                               return $( "<li>" )
-                                       .data( "item.autocomplete", item )
-                                       .append( "<a>" + item.label + "</a>" )
-                                       .appendTo( ul );
-                       };
-               }, // End of _create
-
-               destroy: function() {
-                       this.input.remove();
-                       this.element.show();
-                       $.Widget.prototype.destroy.call( this );
-               }
-       } );
-
        $( "#wpUserLanguage" ).multiselectautocomplete( { inputbox : 
'#tpt-prioritylangs' } );
 } );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to