MediaWiki:Gadget-search-new-tab.js
Appearance
This page is loaded as a part of the search-new-tab gadget, used by 13,537 users. |
/* JSHint-valid */
/* globals $:false */
$(function() {
// Special:Search for all skins.
$('#powersearch, #search').on('keydown', function(e) {
$(this).prop('target', e.ctrlKey || e.metaKey ? '_blank' : '');
});
// CodexTypeaheadSearch header search [only on Vector (2022)].
$('#p-search').on('keydown', '.cdx-typeahead-search #searchform', function(e) {
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
var URI = $(this).find('.cdx-menu-item--selected a.cdx-menu-item__content').prop('href');
if (URI != undefined) {
window.open(URI, '_blank');
return false;
}
}
});
// Header/Side search on other skins [no auto suggest nav on MinervaNeue].
// Search box [auto suggest on Vector legacy (2010), MonoBook, Timeless].
$('div:not(.cdx-typeahead-search) #searchform #searchInput, .searchbox .mw-searchInput').on('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
if ($(this).data('suggestionsContext') != undefined) {
var selectedIndex = $(this).data('suggestionsContext').config.suggestions.indexOf($(this).val());
if (selectedIndex != -1) {
var URI = $('.suggestions-results a:nth-child(' + (selectedIndex + 1) + ')').prop('href');
if (URI != undefined) {
window.open(URI, '_blank');
$(this).trigger('blur');
}
}
}
}
});
});