Content deleted Content added
update |
m Replaced deprecated <source> tags with <syntaxhighlight> |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 1:
{{User:The Transhumanist/Workshop boilerplate/Lead hatnote}}
: '''''
AnnotationToggler = Annotation Toggler. It adds a tab menu item to toggle list item (LI) annotations.
Line 10:
== Description / instruction manual ==
: '''''
The hot key is {{keypress|Shift
This script works on the list items in bulleted lists, lists in which each item is
Line 31:
hit the toggle again, and the descriptions return. The script stores its status so it
doesn't start over between pages — when annotations are turned off, they are off for
all pages until you turn them back on again.
{{User:The Transhumanist/Workshop boilerplate/Install}}
{{User:The Transhumanist/Workshop boilerplate/Explanatory notes}} <!--includes h2 heading-->
=== General approach ===
Line 342 ⟶ 332:
General usage:
<syntaxhighlight lang="javascript">
</syntaxhighlight>
It's components:
▲<code>mw.util.addPortletLink( portletId, href, text [, id [, tooltip [, accesskey [, nextnode ]]]] );</code>
* <code>mw.util.addPortletLink</code>: the ResourceLoader module to add links to the portlets.
* <code>portletId</code>: portlet id— the section where the new menu item is to be placed. Valid values:
** <code>p-navigation</code>: Navigation section in left sidebar
** <code>p-interaction</code>: Interaction section in left sidebar
** <code>p-tb</code>: Toolbox section in left sidebar
** <code>coll-print_export</code>: Print/export section in left sidebar
** <code>p-personal</code> Personal toolbar at the top of the page
** <code>p-views</code> Upper right tabs in Vector only (read, edit, history, watch, etc.)
** <code>p-cactions</code> Drop-down menu containing move, etc. (in Vector); subject/talk links and action links in other skins
* <code>href</code>: Link to the Wikipedia or external page
* <code>text</code>: Text that displays
* <code>id</code>: HTML id (optional)
* <code>tooltip</code>: Tooltip to display on mouseover (optional)
* <code>accesskey</code>: Shortcut key press (optional)
* <code>nextnode</code>: Existing portlet link to place the new portlet link before (optional)
The optional fields must be included in the above order. To skip a field without changing it, use the value <var>null</var>.
''For the documentation on this function, see https://www.mediawiki.org/wiki/ResourceLoader/Modules#addPortletLink'' and [[Help:Customizing toolbars]].
'''Important:''' It won't do anything until you bind it to a click handler (see below).
Line 376 ⟶ 378:
== Change log ==
* 2017-07-07▼
** Version 0.4 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=789519032 ready to embark on fixing the viewport]▼
* 2017-07-06▼
** Moved the functions to the end of the script to make it easier to follow; marked the sections clearly▼
* 2017-07-05▼
** Added document ready function, so the script waits until the DOM is loaded before running▼
** Changed menu items to "Annotations (show)" and "Annotations (hide)"▼
* 2017-01-19▼
** Version 0.3 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=760834841 Simplified the script to wrap annotations and then hide or show them].▼
* 2016-12-11▼
** Version 0.2 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=754184988 on/off status persists across pages]. ▼
* 2016-12-08
** Anchor regexes on <nowiki><li></nowiki> (starting only) element delimiters
Line 393 ⟶ 384:
*** Uses regex to remove annotations
*** Uses a toggle to switch back and forth between the two states
▲* 2016-12-11
▲** Version 0.2 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=754184988 on/off status persists across pages].
▲* 2017-01-19
▲** Version 0.3 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=760834841 Simplified the script to wrap annotations and then hide or show them].
▲* 2017-07-05
▲** Added document ready function, so the script waits until the DOM is loaded before running
▲** Changed menu items to "Annotations (show)" and "Annotations (hide)"
▲* 2017-07-06
▲** Moved the functions to the end of the script to make it easier to follow; marked the sections clearly
▲* 2017-07-07
▲** Version 0.4 – [https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=789519032 ready to embark on fixing the viewport]
* 2018-02-23
** Changed name to ViewAnnotationToggler.js
** removed activation filter so it works on all pages
* 2018-03-13
** Script editor wouldn't work while ViewAnnotationToggler was running, so added a deactivation filter so that this script doesn't run on edit pages.
== Task list ==
===
=== Desired/completed features ===
Line 776 ⟶ 783:
Post new discussion threads below.
== The Bug Report ==
Hi, {{ping|The Transhumanist}}. I've discovered an unintended side-effect caused by a line of code in your script, or should I say ''the'' line of code.
<syntaxhighlight lang="JavaScript>
cont.outerHTML = cont.outerHTML.replace(/(<li>.*?)( –.*)/g,'$1<span class="anno">$2</span>');
</syntaxhighlight>
This code strips action handlers from DOM elements which are descendants of <code>mw-content-text</code>. This notably affects 'buttons', such as the 'show/hide' button in the following templates:
{{collapse top}}
Peekaboo.
{{collapse bottom}}
{{Fragaria|state=expanded}}
You ''might'' be able to prevent this by iterating through <code><li></code> elements, like so:
<syntaxhighlight lang="JavaScript">
$("#mw-content-text li").each(function()
{
$(this).html($(this).html().replace(/(.*?)( –.*)/g,'$1<span class="anno">$2</span>'));
});
</syntaxhighlight>
Let me know if this helps! Regards, <span style="font-family:Times New Roman">[[User:Guywan|''GUYWAN'']] ( [[User talk:Guywan|''t'']] · [[Special:Contributions/Guywan|''c'']] )</span> 12:20, 6 June 2019 (UTC)
|