X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.searchSuggest.js;h=7c7aca39fa3a6e9d1ca8b2bf24ba5c3c2904de71;hb=3eebaaffcf25c3779725309570de924ad5bea766;hp=2d603bf8d4a9ee9e6447e55edc7f481c6d9e3e2d;hpb=a0803c9bc551631c8a35bf2d99705a724cb62039;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.searchSuggest.js b/resources/src/mediawiki/mediawiki.searchSuggest.js index 2d603bf8d4..7c7aca39fa 100644 --- a/resources/src/mediawiki/mediawiki.searchSuggest.js +++ b/resources/src/mediawiki/mediawiki.searchSuggest.js @@ -138,7 +138,7 @@ mw.track( 'mediawiki.searchSuggest', { action: 'render-one', formData: formData, - index: context.config.suggestions.indexOf( text ) + 1 + index: context.config.suggestions.indexOf( text ) } ); // this is the container
, jQueryfied @@ -156,15 +156,19 @@ } // The function used when the user makes a selection - function selectFunction( $input ) { + function selectFunction( $input, source ) { var context = $input.data( 'suggestionsContext' ), text = $input.val(); - mw.track( 'mediawiki.searchSuggest', { - action: 'click-result', - numberOfResults: context.config.suggestions.length, - clickIndex: context.config.suggestions.indexOf( text ) + 1 - } ); + // Selecting via keyboard triggers a form submission. That will fire + // the submit-form event in addition to this click-result event. + if ( source !== 'keyboard' ) { + mw.track( 'mediawiki.searchSuggest', { + action: 'click-result', + numberOfResults: context.config.suggestions.length, + index: context.config.suggestions.indexOf( text ) + } ); + } // allow the form to be submitted return true; @@ -177,6 +181,12 @@ // linkParams object is modified and reused formData.linkParams[ formData.textParam ] = query; + mw.track( 'mediawiki.searchSuggest', { + action: 'render-one', + formData: formData, + index: context.config.suggestions.indexOf( query ) + } ); + if ( $el.children().length === 0 ) { $el .append( @@ -280,9 +290,20 @@ }, special: { render: specialRenderFunction, - select: function ( $input ) { - $input.closest( 'form' ) - .append( $( '' ) ); + select: function ( $input, source ) { + var context = $input.data( 'suggestionsContext' ), + text = $input.val(); + if ( source === 'mouse' ) { + // mouse click won't trigger form submission, so we need to send a click event + mw.track( 'mediawiki.searchSuggest', { + action: 'click-result', + numberOfResults: context.config.suggestions.length, + index: context.config.suggestions.indexOf( text ) + } ); + } else { + $input.closest( 'form' ) + .append( $( '' ) ); + } return true; // allow the form to be submitted } }, @@ -297,7 +318,10 @@ action: 'submit-form', numberOfResults: context.config.suggestions.length, $form: context.config.$region.closest( 'form' ), - inputLocation: getInputLocation( context ) + inputLocation: getInputLocation( context ), + index: context.config.suggestions.indexOf( + context.data.$textbox.val() + ) } ); } ) // If the form includes any fallback fulltext search buttons, remove them