Merge "Add "unsaved changes" warning to Special:Preferences"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.htmlform.js
index 9eea492..594800e 100644 (file)
        } );
 
        function enhance( $root ) {
+               var $matrixTooltips, $autocomplete;
 
                /**
                 * @ignore
                        } );
                }
 
-               var $matrixTooltips = $root.find( '.mw-htmlform-matrix .mw-htmlform-tooltip' );
+               $matrixTooltips = $root.find( '.mw-htmlform-matrix .mw-htmlform-tooltip' );
                if ( $matrixTooltips.length ) {
                        mw.loader.using( 'jquery.tipsy', function () {
                                $matrixTooltips.tipsy( { gravity: 's' } );
                        } );
                }
 
+               // Set up autocomplete fields
+               $autocomplete = $root.find( '.mw-htmlform-autocomplete' );
+               if ( $autocomplete.length ) {
+                       mw.loader.using( 'jquery.suggestions', function () {
+                               $autocomplete.suggestions( {
+                                       fetch: function ( val ) {
+                                               var $el = $( this );
+                                               $el.suggestions( 'suggestions',
+                                                       $.grep( $el.data( 'autocomplete' ), function ( v ) {
+                                                               return v.indexOf( val ) === 0;
+                                                       } )
+                                               );
+                                       }
+                               } );
+                       } );
+               }
+
                // Add/remove cloner clones without having to resubmit the form
                $root.find( '.mw-htmlform-cloner-delete-button' ).click( function ( ev ) {
                        ev.preventDefault();
                        $ul = $( this ).prev( 'ul.mw-htmlform-cloner-ul' );
 
                        html = $ul.data( 'template' ).replace(
-                               $ul.data( 'uniqueId' ), 'clone' + ( ++cloneCounter ), 'g'
+                               new RegExp( $.escapeRE( $ul.data( 'uniqueId' ) ), 'g' ),
+                               'clone' + ( ++cloneCounter )
                        );
 
                        $li = $( '<li>' )