MediaWiki:Gadget-SearchBox.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
const SearchBox = {
init( $content ) {
$content.find( '.template-search-box form' ).on( 'submit', SearchBox.onSubmit );
},
/**
* Fix when an exact match is tried and a prefix is present
* This fix will be unnecessary when https://phabricator.wikimedia.org/T249608 is resolved
*/
onSubmit( event ) {
const button = event.originalEvent.submitter;
if ( button.name !== 'go' ) {
return;
}
const form = button.closest( 'form' );
const prefix = form.querySelector( 'input[name="prefix"]' ).value;
if ( !prefix ) {
return;
}
const search = form.querySelector( 'input[name="search"]' ).value.trim();
if ( !search ) {
return;
}
event.preventDefault();
const subpage = search.charAt( 0 ).toUpperCase() + search.slice( 1 ); // Capitalize
window.location.href = '/Special:Search/' + prefix + subpage;
}
};
mw.hook( 'wikipage.content' ).add( SearchBox.init );