Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Adding elements: fix description of mw.util.addPortletLink()
Line 325:
 
==== Adding elements ====
There is a special function in <code>mediawiki.util</code>, <code>[[:mwhttps://www.mediawiki.org/wiki/ResourceLoader/Default_modulesCore_modules#addPortletLink|mediawiki mw.util.js]addPortletLink()]</code> that simplifies the process of adding your own links to portlets. The advantage of using this function is that your code should work across all skins, and not break when these skins change their HTML.
 
* <code>portletId</code> – ID of the target [[#Portlets (menus and tabs)|portlet]]
[https://doc.wikimedia.org/mediawiki-core/master/js/module-mediawiki.util.html#.addPortletLink mw.util.addPortletLink](
* linkURL<code>href</code> link URL; set to # if you don't need to open a page, and want to use a JavaScript listener instead
 
* linkText<code>text</code> – human-readable link text
* portletType
* elementID<code>id</code> (optional) – suggest using a prefix such as {{abbr|ca-|Content Actions (p-cactions)}}, {{abbr|pt-|Personal Tools (p-personal)}}, {{abbr|n-|Navigation (p-navigation)}}, or {{abbr|t-|Tools/Toolbox (p-tb)}} – for consistency with other links in the group of chosen portletType
* linkURL – set to # if you don't need to open a page, and want to use a JavaScript listener instead
* <code>tooltip</code> (optional) – helpful text appearing on mouse hover
* linkText – human-readable text
* <code>accesskey</code> (optional) – [https://www.w3schools.com/tags/att_global_accesskey.asp keyboard shortcut key]; set to <code>null</code> if you don't need it
* elementID (optional) – suggest using a prefix such as {{abbr|ca-|Content Actions (p-cactions)}}, {{abbr|pt-|Personal Tools (p-personal)}}, {{abbr|n-|Navigation (p-navigation)}}, or {{abbr|t-|Tools/Toolbox (p-tb)}} – for consistency with other links in the group of chosen portletType
* tooltip<code>nextNode</code> (optional) – helpfulelement textthat appearingthis onwill mousebe hoveradded in front of
* keyboardShortcutKey (optional) – set to <code>null</code> if you don't need it [https://www.w3schools.com/tags/att_global_accesskey.asp]
* nextNode (optional) – element that this will be added in front of
 
);<syntaxhighlight lang="javascript">