Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / resources / jquery / jquery.suggestions.js
index d80680f..edc18a7 100644 (file)
  *
  * Options:
  *
- * fetch(query): Callback that should fetch suggestions and set the suggestions property. Executed in the context of the
- *             textbox
+ * fetch(query): Callback that should fetch suggestions and set the suggestions property.
+ *      Executed in the context of the textbox
  *             Type: Function
- * cancel: Callback function to call when any pending asynchronous suggestions fetches should be canceled.
- *             Executed in the context of the textbox
+ * cancel: Callback function to call when any pending asynchronous suggestions fetches
+ *      should be canceled. Executed in the context of the textbox
  *             Type: Function
  * special: Set of callbacks for rendering and selecting
  *             Type: Object of Functions 'render' and 'select'
  *             Type: Number, Range: 0 - 1200, Default: 120
  * submitOnClick: Whether to submit the form containing the textbox when a suggestion is clicked
  *             Type: Boolean, Default: false
- * maxExpandFactor: Maximum suggestions box width relative to the textbox width. If set to e.g. 2, the suggestions box
- *             will never be grown beyond 2 times the width of the textbox.
+ * maxExpandFactor: Maximum suggestions box width relative to the textbox width. If set
+ *      to e.g. 2, the suggestions box will never be grown beyond 2 times the width of the textbox.
  *             Type: Number, Range: 1 - infinity, Default: 3
  * expandFrom: Which direction to offset the suggestion box from.
- *      Values 'start' and 'end' translate to left and right respectively depending on the directionality
- *      of the current document, according to $( 'html' ).css( 'direction' ).
+ *      Values 'start' and 'end' translate to left and right respectively depending on the
+ *      directionality of the current document, according to $( 'html' ).css( 'direction' ).
  *      Type: String, default: 'auto', options: 'left', 'right', 'start', 'end', 'auto'.
  * positionFromLeft: Sets expandFrom=left, for backwards compatibility
  *             Type: Boolean, Default: true
@@ -60,18 +60,22 @@ $.suggestions = {
                        context.config.cancel.call( context.data.$textbox );
                }
        },
+
        /**
-        * Restore the text the user originally typed in the textbox, before it was overwritten by highlight(). This
-        * restores the value the currently displayed suggestions are based on, rather than the value just before
+        * Restore the text the user originally typed in the textbox, before it
+        * was overwritten by highlight(). This restores the value the currently
+        * displayed suggestions are based on, rather than the value just before
         * highlight() overwrote it; the former is arguably slightly more sensible.
         */
        restore: function ( context ) {
                context.data.$textbox.val( context.data.prevText );
        },
+
        /**
-        * Ask the user-specified callback for new suggestions. Any previous delayed call to this function still pending
-        * will be canceled. If the value in the textbox is empty or hasn't changed since the last time suggestions were fetched, this
-        * function does nothing.
+        * Ask the user-specified callback for new suggestions. Any previous delayed
+        * call to this function still pending will be canceled. If the value in the
+        * textbox is empty or hasn't changed since the last time suggestions were fetched,
+        * this function does nothing.
         * @param {Boolean} delayed Whether or not to delay this by the currently configured amount of time
         */
        update: function ( context, delayed ) {
@@ -101,6 +105,7 @@ $.suggestions = {
                }
                $.suggestions.special( context );
        },
+
        special: function ( context ) {
                // Allow custom rendering - but otherwise don't do any rendering
                if ( typeof context.config.special.render === 'function' ) {
@@ -112,13 +117,17 @@ $.suggestions = {
                        }, 1 );
                }
        },
+
        /**
         * Sets the value of a property, and updates the widget accordingly
         * @param property String Name of property
         * @param value Mixed Value to set property with
         */
        configure: function ( context, property, value ) {
-               var newCSS;
+               var newCSS,
+                       $autoEllipseMe, $result, $results, $span,
+                       i, expWidth, matchedText, maxWidth, text;
+
                // Validate creation using fallback values
                switch( property ) {
                        case 'fetch':
@@ -212,22 +221,24 @@ $.suggestions = {
                                                }
 
                                                context.data.$container.css( newCSS );
-                                               var $results = context.data.$container.children( '.suggestions-results' );
+                                               $results = context.data.$container.children( '.suggestions-results' );
                                                $results.empty();
-                                               var expWidth = -1;
-                                               var $autoEllipseMe = $( [] );
-                                               var matchedText = null;
-                                               for ( var i = 0; i < context.config.suggestions.length; i++ ) {
+                                               expWidth = -1;
+                                               $autoEllipseMe = $( [] );
+                                               matchedText = null;
+                                               for ( i = 0; i < context.config.suggestions.length; i++ ) {
                                                        /*jshint loopfunc:true */
-                                                       var text = context.config.suggestions[i];
-                                                       var $result = $( '<div>' )
+                                                       text = context.config.suggestions[i];
+                                                       $result = $( '<div>' )
                                                                .addClass( 'suggestions-result' )
                                                                .attr( 'rel', i )
                                                                .data( 'text', context.config.suggestions[i] )
-                                                               .mousemove( function ( e ) {
+                                                               .mousemove( function () {
                                                                        context.data.selectedWithMouse = true;
                                                                        $.suggestions.highlight(
-                                                                               context, $(this).closest( '.suggestions-results div' ), false
+                                                                               context,
+                                                                               $(this).closest( '.suggestions-results div' ),
+                                                                               false
                                                                        );
                                                                } )
                                                                .appendTo( $results );
@@ -246,7 +257,7 @@ $.suggestions = {
 
                                                                // Widen results box if needed
                                                                // New width is only calculated here, applied later
-                                                               var $span = $result.children( 'span' );
+                                                               $span = $result.children( 'span' );
                                                                if ( $span.outerWidth() > $result.width() && $span.outerWidth() > expWidth ) {
                                                                        // factor in any padding, margin, or border space on the parent
                                                                        expWidth = $span.outerWidth() + ( context.data.$container.width() - $span.parent().width());
@@ -256,11 +267,15 @@ $.suggestions = {
                                                }
                                                // Apply new width for results box, if any
                                                if ( expWidth > context.data.$container.width() ) {
-                                                       var maxWidth = context.config.maxExpandFactor*context.data.$textbox.width();
+                                                       maxWidth = context.config.maxExpandFactor*context.data.$textbox.width();
                                                        context.data.$container.width( Math.min( expWidth, maxWidth ) );
                                                }
                                                // autoEllipse the results. Has to be done after changing the width
-                                               $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true, matchText: matchedText } );
+                                               $autoEllipseMe.autoEllipsis( {
+                                                       hasSpan: true,
+                                                       tooltip: true,
+                                                       matchText: matchedText
+                                               } );
                                        }
                                }
                                break;
@@ -280,6 +295,7 @@ $.suggestions = {
                                break;
                }
        },
+
        /**
         * Highlight a result in the results table
         * @param result <tr> to highlight: jQuery object, or 'prev' or 'next'
@@ -338,13 +354,16 @@ $.suggestions = {
                        context.data.$textbox.trigger( 'change' );
                }
        },
+
        /**
         * Respond to keypress event
         * @param key Integer Code of key pressed
         */
        keypress: function ( e, context, key ) {
-               var wasVisible = context.data.$container.is( ':visible' ),
+               var selected,
+                       wasVisible = context.data.$container.is( ':visible' ),
                        preventDefault = false;
+
                switch ( key ) {
                        // Arrow down
                        case 40:
@@ -376,7 +395,7 @@ $.suggestions = {
                        case 13:
                                context.data.$container.hide();
                                preventDefault = wasVisible;
-                               var selected = context.data.$container.find( '.suggestions-result-current' );
+                               selected = context.data.$container.find( '.suggestions-result-current' );
                                if ( selected.length === 0 || context.data.selectedWithMouse ) {
                                        // if nothing is selected OR if something was selected with the mouse,
                                        // cancel any current requests and submit the form
@@ -420,18 +439,18 @@ $.fn.suggestions = function () {
                if ( context === undefined || context === null ) {
                        context = {
                                config: {
-                                       'fetch' : function () {},
-                                       'cancel': function () {},
-                                       'special': {},
-                                       'result': {},
-                                       '$region': $(this),
-                                       'suggestions': [],
-                                       'maxRows': 7,
-                                       'delay': 120,
-                                       'submitOnClick': false,
-                                       'maxExpandFactor': 3,
-                                       'expandFrom': 'auto',
-                                       'highlightInput': false
+                                       fetch: function () {},
+                                       cancel: function () {},
+                                       special: {},
+                                       result: {},
+                                       $region: $(this),
+                                       suggestions: [],
+                                       maxRows: 7,
+                                       delay: 120,
+                                       submitOnClick: false,
+                                       maxExpandFactor: 3,
+                                       expandFrom: 'auto',
+                                       highlightInput: false
                                }
                        };
                }
@@ -480,14 +499,16 @@ $.fn.suggestions = function () {
                                .addClass( 'suggestions' )
                                .append(
                                        $( '<div>' ).addClass( 'suggestions-results' )
-                                               // Can't use click() because the container div is hidden when the textbox loses focus. Instead,
-                                               // listen for a mousedown followed by a mouseup on the same div
+                                               // Can't use click() because the container div is hidden when the
+                                               // textbox loses focus. Instead, listen for a mousedown followed
+                                               // by a mouseup on the same div.
                                                .mousedown( function ( e ) {
                                                        context.data.mouseDownOn = $( e.target ).closest( '.suggestions-results div' );
                                                } )
                                                .mouseup( function ( e ) {
-                                                       var $result = $( e.target ).closest( '.suggestions-results div' );
-                                                       var $other = context.data.mouseDownOn;
+                                                       var $result = $( e.target ).closest( '.suggestions-results div' ),
+                                                               $other = context.data.mouseDownOn;
+
                                                        context.data.mouseDownOn = $( [] );
                                                        if ( $result.get( 0 ) !== $other.get( 0 ) ) {
                                                                return;
@@ -502,14 +523,16 @@ $.fn.suggestions = function () {
                                )
                                .append(
                                        $( '<div>' ).addClass( 'suggestions-special' )
-                                               // Can't use click() because the container div is hidden when the textbox loses focus. Instead,
-                                               // listen for a mousedown followed by a mouseup on the same div
+                                               // Can't use click() because the container div is hidden when the
+                                               // textbox loses focus. Instead, listen for a mousedown followed
+                                               // by a mouseup on the same div.
                                                .mousedown( function ( e ) {
                                                        context.data.mouseDownOn = $( e.target ).closest( '.suggestions-special' );
                                                } )
                                                .mouseup( function ( e ) {
-                                                       var $special = $( e.target ).closest( '.suggestions-special' );
-                                                       var $other = context.data.mouseDownOn;
+                                                       var $special = $( e.target ).closest( '.suggestions-special' ),
+                                                               $other = context.data.mouseDownOn;
+
                                                        context.data.mouseDownOn = $( [] );
                                                        if ( $special.get( 0 ) !== $other.get( 0 ) ) {
                                                                return;