Jump to content

MediaWiki talk:Gadget-search-new-tab.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

More info and discussion elsewhere

[edit]

Go to commons:MediaWiki talk:Gadget-search-new-tab.js - The gadget on the Commons is explained there, and there are many discussion and Bugzilla links. --Timeshifter (talk) 05:09, 28 January 2013 (UTC)[reply]

Commons gadget

[edit]

commons:MediaWiki:Gadget-search-new-tab.js

Currently, the JS here on English Wikipedia is the same as in the gadget JS on the Commons. --Timeshifter (talk) 05:09, 28 January 2013 (UTC)[reply]

doesn’t always work

[edit]

This Gadget sometimes randomly doesn’t work. I noticed this especially on Special:Watchlist, but this may be conincidential, as I’m using it more often there than on any other page. Browser error console doesn’t report any issues. After my request on dewiki’s technical help desk, de:User:Fomafix suspects the gadget has to explictly wait for the document to be ready. @Krinkle: The comment in the gadget’s source code says you said it would not have to wait. So, should this be changed or is there something else, which would make this gadget randomly not work? --nenntmichruhigip (Diskussion) 19:19, 14 November 2017 (UTC)[reply]

Gadget-search-new-tab doesn't work on suggestions

[edit]

I noticed MediaWiki:Gadget-search-new-tab.js doesn't seem to work on suggested sites anymore. I.e. typing "test" in the search box, pressing the down arrow twice to select Test cricket, and pressing Ctrl+↵ Enter loads in the current tab instead of a new one. Can this be fixed somehow? --nenntmichruhigip (Diskussion) 22:38, 1 January 2023 (UTC)[reply]

@Nenntmichruhigip: move this to the right page for this gadget, there is a current maintainer, User:Timeshifter who may help out. — xaosflux Talk 01:59, 2 January 2023 (UTC)[reply]
@Nenntmichruhigip:@Krinkle:@Xaosflux:. I don't understand this stuff. I've only ever just copied stuff that worked on one wiki to another. I have no idea where to discuss this stuff even. I see no link for this gadget at Special:Preferences#mw-prefsection-gadgets. I found this page by looking around for info here: MediaWiki:Gadgets-definition.
I never noticed the ping in the last message. I've had health problems the last couple years. So I will not be able to help.
Currently the gadget works from the search page, but not from the search form at the top of every article. That is why I came here today. Please put a link at Special:Preferences#mw-prefsection-gadgets where people will look first. Or stuff will stay broken, cause few will know where to report problems.
And an admin needs to remove the following from MediaWiki:Gadget-search-new-tab.js:
"Open search in new tab by User:Timeshifter"
As I said, I don't understand this stuff.
I started this thread:
Wikipedia:Village pump (technical)/Archive 210#Problems with gadget: "Open search results in a new tab or window when holding down the Ctrl key"
--Timeshifter (talk) 00:53, 22 January 2024 (UTC)[reply]
Removed Timeshifter note; Nenntmichruhigip can you give exact steps to reproduce this problem? — xaosflux Talk 10:56, 22 January 2024 (UTC)[reply]
Thanks. Pinging Jroberson108. --Timeshifter (talk) 00:08, 23 January 2024 (UTC)[reply]
Not sure what else to add to my initial description. Happens in both Vector and Timeless. --nenntmichruhigip (Diskussion) 16:51, 27 January 2024 (UTC)[reply]

xaosflux and others with the necessary rights. Can you, or someone else, please add a link to MediaWiki:Gadget-search-new-tab.js (or its talk page that we are on now) from its entry on the gadget preferences list: Special:Preferences#mw-prefsection-gadgets? This will help in not waiting years again for reports, ideas, discussion, and fixes. --Timeshifter (talk) 22:35, 26 January 2024 (UTC)[reply]

 Donexaosflux Talk 23:41, 26 January 2024 (UTC)[reply]
Thanks! Is there a way for me to watchlist that gadgets page? --Timeshifter (talk) 00:10, 27 January 2024 (UTC)[reply]
@Nenntmichruhigip: does this work for you now? Jroberson108 (talk) 19:03, 29 January 2024 (UTC)[reply]

Interface-protected edit request on 23 January 2024

[edit]

Please change everything to the following code. Issue details at MediaWiki talk:Gadget-search-new-tab.js#Gadget-search-new-tab doesn't work on suggestions.

/* 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');
					}
				}
			}
		}
	});
});

Jroberson108 (talk) 21:49, 23 January 2024 (UTC)[reply]

I don't have permissions to change the code, so I submitted a change request. Adding target="_blank" to this form doesn't work anymore. I had to move the event listener to the parent element, check if the key combination is pressed, get the selected result's href, then open it in a new window. I tested it in my common.js file using Windows 10 browsers, where navigating to the suggested result and pressing Ctrl+↵ Enter opens it in a new window the same as pressing Ctrl+left mouse click. I extended it to include Mac's ⌘ Cmd+↵ Enter key combination since, as I recall, their normal shortcut is ⌘ Cmd+left mouse click, but I don't have a Mac to test it with. The code is JSHint valid. I omitted forms with #searchbox, #search, .search-types, #search-types, #powersearch because I couldn't find them to test them. Maybe legacy before the redesign? Jroberson108 (talk) 21:56, 23 January 2024 (UTC)[reply]

Thanks. The other code may be for Special:Search and the advanced search after further levels of search at Special:Search. There may be other search forms on Wikipedia too. I have seen this gadget before it was a gadget, and it worked on Apple devices too.
Someone at my Village Pump discussion (you might want to read the latest reply) thought the problem might be connected to this too:
Wikipedia:Village pump (technical)/Archive 210#What is removing the button that this script adds to the search bar?
Are the top of page search forms using the same code on Vector 2010 and 2022? What about other skins? What about Special:Search on different skins? Maybe some of the extra code is for that. --Timeshifter (talk) 22:35, 23 January 2024 (UTC)[reply]
To be clear, ctrl+↵ Enter should still work on Mac. I was saying they normally use ⌘ Command instead of ctrl. The Special:Search form uses #powersearch, but that form is very different from the one in the header. Selecting any of the suggestions keeps you on the page instead of taking you to the related page like the header form does. Doesn't seem like it can be used there. Are there any other forms that auto suggest results that take you to the actual page? The other discussions are related, which is why I had to move the event listener outside the form. The other skins do look different, so I'll have to look at them too. Jroberson108 (talk) 22:57, 23 January 2024 (UTC)[reply]
The other skins use #searchform on the home page's form and do take you to the article page when submitted, but they have completely different structures from Vector (2022), some with the suggestions at the bottom of the page somewhat decoupled from the form. MinervaNeue doesn't even have a way to arrow down to the recommended. So this code only works on Vector (2022). This gadget doesn't work on any skins, so as of now no one is using it even if it is enabled. I've already spent two days on this and I don't really want to continue with the other skins since I don't really see a practical or big need for this gadget, the new code at least works with the main default skin, and, as I recall, more than half of the traffic is from mobile (Minerva) which can't use it anyways. A simple ctrl+left mouse click accomplishes the same thing. Jroberson108 (talk) 23:32, 23 January 2024 (UTC)[reply]
I added the legacy code back in. It will allow it to work on Special:Search for all the skins, which uses #powersearch, although I'm not sure why you would do it on that page just to open a similar advanced search page. That leaves the header/sidebar searches for the other skins. I have yet to find these forms, but they are there just in case: #searchbox, #search, .search-types, #search-types. Jroberson108 (talk) 23:58, 23 January 2024 (UTC)[reply]
Looked at the skins again and found some of them. #searchbox seems to be a typo in the gadget and should be #search-box, used in Minerva header (corrected above, but still doesn't work in header search). Not sure where #search .search-types, #search-types are. Jroberson108 (talk) 00:16, 24 January 2024 (UTC)[reply]
Here's a rundown of the ids and classes found in the code (new/legacy) and the current forms. It should help if anyone else wants to take a crack at making it work for header searches. Again, in the new code above, all the special searches work and the header search for Vector (2022) works.
Search forms:
  • #search: Special:Search before searching [all skins]
  • #powersearch: Special:Search after searching [all skins]
  • #searchform: header/sidebar search [Vector (2022), Vector legacy (2010), MonoBook, Timeless]
  • .searchbox: Wikipedia:Village pump (all) and talk page searches [all skins] (auto suggest on Vector legacy (2010), MonoBook, and Timeless skins)
  • #search-box: header search [MinervaNeue] (no arrow navigation on auto suggest)
  • #search-types: unknown
  • .search-types: unknown
Jroberson108 (talk) 01:19, 24 January 2024 (UTC)[reply]
Thanks! I know I will be using it more. It is so convenient to me to search from the top of pages if results are opened in new tabs.
I wonder if archive searches of the Village Pumps, and archive searches of article talk archives, use other ids and classes. --Timeshifter (talk) 03:04, 24 January 2024 (UTC)[reply]
Wikipedia:Village_pump (all) and Help talk:Table use name="searchbox"; no id. What's odd is that they both auto suggest articles on the Vector legacy (2010), MonoBook, and Timeless skins, which seems like a bug. I updated the list above. Jroberson108 (talk) 03:46, 24 January 2024 (UTC)[reply]
Corrected the list, which was missing #powersearch. Fixed the one for the talk page too, which had a class. I adjusted the code to only target forms where it works. I created User:Jroberson108/Gadget-search-new-tab.js so that anyone can include it in their common.js file and disable this gadget for temporary testing purposes. Jroberson108 (talk) 16:23, 24 January 2024 (UTC)[reply]
FYI, I'm working on a fix for the header searches for the other skins in my common.js file. Jroberson108 (talk) 21:45, 24 January 2024 (UTC)[reply]
Replaced code. Works on header search for all skins except MinervaNeue, which doesn't have a way to select suggestions via arrow keys. Also, as previously mentioned, works on Special:Search for all skins including MinervaNeue, which that form also uses #search, so updated list. Code is testable by including User:Jroberson108/Gadget-search-new-tab.js in your common.js file and disabling this gadget. Hopefully that covers everything. Jroberson108 (talk) 02:48, 25 January 2024 (UTC)[reply]
Updated code to work for .searchbox forms when they have auto suggest, which I found the ones on the Vector legacy (2010), MonoBook, and Timeless skins have auto suggest. Jroberson108 (talk) 18:17, 25 January 2024 (UTC)[reply]

Jroberson108. And pinging some people from past discussions and revision histories linked below. Killiondude. Rd232. Rillke. Krenair.

I found some more info here that lists the purpose of each term (at some point):

Looks like this was worked on in various wikis, by various people, and I was mainly trying to get it to work for me as a copy, or an import, back in 2012 and 2013, and onwards. I didn't understand much of the code then or now. But I passed on links to what was working where.

There are many links on the various pages linked above and below. Eventually others created the gadgets on Wikipedia and the Commons. I wonder if this gadget rewrite above will work on the Commons too. Or if the terms are different. See these pages too:

--Timeshifter (talk) 19:12, 27 January 2024 (UTC)[reply]

 Done * Pppery * it has begun... 21:25, 28 January 2024 (UTC)[reply]

Thanks Pppery and Jroberson108.
Test results using Ctrl-click
Win 10 Pro desktop PC. In Vector 2022. I did some quick tests in desktop Firefox, Edge, Chrome, Opera to see when ctrl-click worked to produce results in a new tab. I turned off the popup blocker completely in Firefox settings to get consistent accurate results.
Not logged in:
ctrl-click on the search button of header search worked on all those browsers except Firefox.
ctrl-click works on the header search suggestions on all browsers.
ctrl-click works in Special:Search on the search button. On all browsers except Firefox.
ctrl-click on Special:Search suggestions did not work on any browser.
Logged in:
ctrl-click header search worked on all browsers except Firefox. I turned off popup blocker completely in Firefox settings. I purged via Shift-Reload, and Ctrl-F5. I uninstalled and reinstalled it in gadget preferences. Nothing worked to get Firefox to work on header searches (top of page search form). I am talking via ctrl-click on the search button.
ctrl-click works on the header search suggestions on all browsers.
ctrl-click works in Special:Search when ctrl-clicking the search button on all browsers.
ctrl-click works on Special:Search suggestions on all browsers.
--Timeshifter (talk) 23:30, 28 January 2024 (UTC). Corrections: --Timeshifter (talk) 02:00, 30 January 2024 (UTC)[reply]
@Timeshifter:, opening links in a new tab via ctrl-click is a built-in feature that most browsers have. This gadget enables opening suggested results in a new tab via ctrl-enter, which you can use the keyboard arrows to navigate to a suggested result; not possible in Minerva's header search. For Special:Search, pressing ctrl adds target="_blank" to the form and removes it if other keys (not enter) are pressed, allowing it to submit to a new tab if ctrl is followed by a click on the submit button or enter is pressed to submit it without having to hold down the ctrl key. Jroberson108 (talk) 23:58, 28 January 2024 (UTC)[reply]
I just tried it. ctrl-ENTER is not opening Firefox results in a new tab from the header search form when logged in.
I'll have to do some iphone SE 2020 browser tests too. May be awhile though.
On my desktop PC for all links on any website (other than search where no context menu normally pops up) I normally right-click the link and decide whether to open in a new tab or new window. I long ago stopped using ctrl-click due to inconsistencies and lack of choices.
But for search forms anywhere I don't remember right-clicking working. So I try ctrl-click to see what happens.
Correction. I just tried right-clicking the suggestions (in Firefox header or Special:Search) and I get the context menu with the new tab/window choices. --Timeshifter (talk) 00:22, 29 January 2024 (UTC)[reply]
You can try to purge cache by adding ?action=purge to the URL. I was wondering why it wasn't working for me in Firefox, then I remembered I have a pop-up blocker. In the header search, arrowing down to a suggested result and pressing ctrl-enter opens the result in a new tab. Right clicking on the suggested result (not the form submit) to open it in a new tab or ctrl-clicking on the suggested result do the same thing for me and aren't blocked. This is all in the Vector (2022) skin. Jroberson108 (talk) 00:38, 29 January 2024 (UTC)[reply]

Nothing seems to be working for me with the form submit button at the top of Wikipedia pages on Firefox in Vector 2022. Turning off the Firefox popup blocker did not help. The purge code did not help. Adblock Plus is turned off for Wikipedia. Is this relevant?:

Is ctrl-click or ctrl-enter on desktop Firefox working for you with the form submit button at the top of Wikipedia pages in Vector 2022? --Timeshifter (talk) 02:08, 29 January 2024 (UTC)[reply]

I feel like we are talking about two different things. There's the form's "Search" button and then there are the suggested results that appear under the form as you type in the input field.
For the header/top form, if you type in "test", then hold down ctrl and left-click on the "Search" button, for me, Chrome and Edge open it in a new tab, whereas Firefox opens it in the same tab. For the suggested results, if you type in "test", then hold down ctrl and left-click on one of the suggestions, it opens in a new tab in all three browsers. I can also right click on the suggestion and open it in a new tab for all three browsers. These features come from your browser and have nothing to do with this gadget, which you can logout and test this. If you are experiencing something different when logged out, then it might be a browser extension. If it's different when logged in, then it might be another gadget, setting or something in your common.js file. You can also try testing your browser in private/incognito mode, which usually disables a lot of the extensions.
For the suggested results, when you type in "test" and use the down arrow to highlight a suggested result, then hold down ctrl and press enter, it should open in a new tab for all three browsers if this gadget is enabled. Without this gadget, doing the same, Chrome and Edge do nothing, and Firefox opens it in the same tab. Jroberson108 (talk) 03:06, 29 January 2024 (UTC)[reply]
I am getting the same results as you for both ctrl-click and ctrl-Enter. I updated and clarified my previous ctrl-click list, and put it in a table for easy access. See table in previous post higher up in this section. Thanks for pointing out the built-in ctrl-click feature of browsers.
I see now that the gadget doesn't fix my problems since I am a Firefox user.
But if I use right-clicking for all searches on Wikipedia then my problems are solved without the gadget. Search terms entered in the search form show up as the first entry on the suggestions list. I can right click that and open the results list in a new tab. So I don't need the gadget.
But the gadget works perfectly for other browsers, and will be of service to those users who want to use ctrl-click on Special:Search suggestions. If they are in the habit of using ctrl-click for searches, and opening random links anywhere, then this will allow them to continue without thinking about it. --Timeshifter (talk) 02:23, 30 January 2024 (UTC)[reply]