X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.searchSuggest.js;h=2d603bf8d4a9ee9e6447e55edc7f481c6d9e3e2d;hb=0a510ed072b68c009cd97307b77eef8a6279ea2a;hp=923dfc2c29576eb15fa32ef799411c8121f4d7c6;hpb=8b32da49e5dfd4a4af9f94bfdf25ec6981664616;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.searchSuggest.js b/resources/src/mediawiki/mediawiki.searchSuggest.js index 923dfc2c29..2d603bf8d4 100644 --- a/resources/src/mediawiki/mediawiki.searchSuggest.js +++ b/resources/src/mediawiki/mediawiki.searchSuggest.js @@ -12,12 +12,13 @@ namespace: 0, limit: maxRows, suggest: true - } ).done( function ( data ) { - response( data[ 1 ] ); + } ).done( function ( data, jqXHR ) { + response( data[ 1 ], { + type: jqXHR.getResponseHeader( 'X-OpenSearch-Type' ), + query: query + } ); } ); - }, - // The name of the request api for event logging purposes - type: 'prefix' + } }; $( function () { @@ -90,19 +91,37 @@ previousSearchText = searchText; } + /** + * defines the location of autocomplete. Typically either + * header, which is in the top right of vector (for example) + * and content which identifies the main search bar on + * Special:Search. Defaults to header for skins that don't set + * explicitly. + * + * @ignore + */ + function getInputLocation( context ) { + return context.config.$region + .closest( 'form' ) + .find( '[data-search-loc]' ) + .data( 'search-loc' ) || 'header'; + } + /** * Callback that's run when suggestions have been updated either from the cache or the API * 'this' is the search input box (jQuery object) * * @ignore */ - function onAfterUpdate() { + function onAfterUpdate( metadata ) { var context = this.data( 'suggestionsContext' ); mw.track( 'mediawiki.searchSuggest', { action: 'impression-results', numberOfResults: context.config.suggestions.length, - resultSetType: mw.searchSuggest.type + resultSetType: metadata.type || 'unknown', + query: metadata.query, + inputLocation: getInputLocation( context ) } ); } @@ -114,6 +133,14 @@ // linkParams object is modified and reused formData.linkParams[ formData.textParam ] = text; + // Allow trackers to attach tracking information, such + // as wprov, to clicked links. + mw.track( 'mediawiki.searchSuggest', { + action: 'render-one', + formData: formData, + index: context.config.suggestions.indexOf( text ) + 1 + } ); + // this is the container
, jQueryfied this.text( text ); @@ -181,9 +208,6 @@ searchboxesSelectors = [ // Primary searchbox on every page in standard skins '#searchInput', - // Special:Search - '#powerSearchText', - '#searchText', // Generic selector for skins with multiple searchboxes (used by CologneBlue) // and for MediaWiki itself (special pages with page title inputs) '.mw-searchInput' @@ -213,6 +237,10 @@ return true; } }, + update: { + before: onBeforeUpdate, + after: onAfterUpdate + }, cache: true, highlightInput: true } ) @@ -267,7 +295,9 @@ var context = $searchInput.data( 'suggestionsContext' ); mw.track( 'mediawiki.searchSuggest', { action: 'submit-form', - numberOfResults: context.config.suggestions.length + numberOfResults: context.config.suggestions.length, + $form: context.config.$region.closest( 'form' ), + inputLocation: getInputLocation( context ) } ); } ) // If the form includes any fallback fulltext search buttons, remove them