Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Line 325:
 
==== Adding elements ====
There is a special function in <code>mediawiki.util</code>, <code>[https://www.mediawiki.org/wiki/ResourceLoader/Core_modules#addPortletLink mw.util.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. Its parameters, in order:
 
* <code>portletId</code> – ID of the target [[#Portlets (menus and tabs)|portlet]]
* <code>href</code> – link URL; set to <code>#</code> if you don't need to open a page and want to use a JavaScript listener instead
* <code>text</code> – human-readable link text
* <code>id</code> (optional) – suggestunique usingID of the item; use 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<code>portletId</code>
* <code>tooltip</code> (optional) – helpful text appearing on mouse hover
* <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