User:PerfektesChaos/js/clickDivertimento
JavaScript gadget to add specific functionality on pages: Open particular links automatically on new browser window or tab.
This affects namely
- any page source text currently edited, to avoid loosing of edit work
- watchlists (both recent and edit list) and “recent changes”, which may be used as persistent navigation overview
- on individual request:
- URL search special page
- user contributions
- page history
- what links here
On most browsers a different window can be forced by simultaneous pressing [Ctrl] or [Shift]. If forgotten on page preview the edit change may be lost when returning to edit mode.
Usage
[edit]- If your project has registered this as a gadget, just activate on your Preferences page.
- Otherwise include the following lines into your common.js or similar:
mw.loader.load("https://wiki.riteme.site/w/index.php?title=User:PerfektesChaos/js/clickDivertimento/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript");
- The gadget works also with non-WMF sites using MediaWiki 1.18 or higher.
- If not working as registered user the gadget can be activated by greasemonkey or browser user script.
User options
[edit]Quick interactive costumization
[edit]The simple on/off switch options can be set interactively on Special:Blankpage as soon as the script library has been loaded.
When reloading a page the preferences declared here come into effect. This dynamic assignment overrides the static setting by JavaScript.
These user preferences are not visible to other users.
Even anonymous users may store preferences, but for current browser profile only (utilizing localStorage).
Configuration by JavaScript
[edit]Insert the following lines into your common.js (best before mw.loader.load, if present):
if ( typeof mw.libs.clickDivertimento !== "object" ) {
mw.libs.clickDivertimento = { };
}
mw.libs.clickDivertimento.key1 = value1;
Key | Value | Meaning |
---|---|---|
large
|
true
|
Include more list pages. Default: false – watchlists and “recent changes”
|
leave
|
true
|
All external links shall be opened in new browser window. Default: false – unchanged layout
|
mode
|
0
|
Create entirely new window. Default: 0 – For all diverted targets
|
targets
|
object
|
Use the same window for similar links Default: No specification. Assigns to a window name one of
A window name should begin with letter, only ASCII letters and digits, no more than 10 for distictive name. |
Example:
if ( typeof mw.libs.clickDivertimento !== "object" ) {
mw.libs.clickDivertimento = { };
}
mw.libs.clickDivertimento.large = true;
mw.libs.clickDivertimento.targets = { wphelp: "/wiki/Help:",
DNB: "http://d-nb.info/",
jdk: [ "http://java.com/",
/http:\/\/(:?docs\.)?oracle\.com\// ]
};
Include more list pages
[edit]On individual request apply to:
- URL search special page
- user contributions
- page history
- recent changes
The target window diverting is always applied to the list section of
All external links shall be opened in new browser window
[edit]On any page all links written as URL in source text shall be diverted.
- Default: open in the same window, if no other reason.
Create entirely new window
[edit]- For all diverted targets (default)
1
– Shared windows for the same tasks2
– All in the same but different window
Use the same window for similar links
[edit]Specified URL patterns shall be collected within the same window. This window gets a specific name and will be reused.
This comes into effect if not requested “entirely new window for all diverted targets”, but some kind of window sharing.
A window name should begin with letter, only ASCII letters and digits, no more than 10 for distictive name.
Codes
[edit]Source code |
|
ResourceLoader |
|
Namespaces | all |
Cookie | anonymous users only: preferencesGadgetOptions (localStorage)
|
mw.libs
|
clickDivertimento
|
MediaWiki |
|
Other languages
[edit]This gadget is prepared for multilingual support.
- If you like a version in your own language, please forward translations to me:
- This documentation page.
- The
Texts
mapping on top of source code. - Further ISO 639 language codes your translation might support.