MediaWiki:Gadget-defaultVisibilityToggles.js: Difference between revisions
Tag: Undo |
No edit summary |
||
| Line 1: | Line 1: | ||
/* jshint undef: true | /* jshint undef: true */ | ||
/* globals $, jQuery, mw, window, getComputedStyle */ | /* globals $, jQuery, mw, window, getComputedStyle */ | ||
(function defaultVisibilityTogglesIIFE() { | |||
"use strict"; | "use strict"; | ||
| Line 11: | Line 10: | ||
var NavigationBarHide = "hide ▲"; | var NavigationBarHide = "hide ▲"; | ||
var NavigationBarShow = "show ▼"; | var NavigationBarShow = "show ▼"; | ||
var nbsp = "\u00a0"; | |||
// Check if an element has been activated with a toggle. | // Check if an element has been activated with a toggle. | ||
| Line 102: | Line 103: | ||
navHead.onclick = window.VisibilityToggles.register(toggleCategory, | navHead.onclick = window.VisibilityToggles.register(toggleCategory, | ||
function show() { | function show() { | ||
$navToggle. | $navToggle.text(NavigationBarHide); | ||
if (navContent) | if (navContent) | ||
navContent.style.display = "block"; | navContent.style.display = "block"; | ||
}, | }, | ||
function hide() { | function hide() { | ||
$navToggle. | $navToggle.text(NavigationBarShow); | ||
if (navContent) | if (navContent) | ||
navContent.style.display = "none"; | navContent.style.display = "none"; | ||
| Line 140: | Line 141: | ||
itCaption.onclick = window.VisibilityToggles.register(toggleCategory, | itCaption.onclick = window.VisibilityToggles.register(toggleCategory, | ||
function show() { | function show() { | ||
$navToggle. | $navToggle.text(NavigationBarHide); | ||
if (it) { | if (it) { | ||
it.classList.remove("inflection-table-collapsed"); | it.classList.remove("inflection-table-collapsed"); | ||
| Line 146: | Line 147: | ||
}, | }, | ||
function hide() { | function hide() { | ||
$navToggle. | $navToggle.text(NavigationBarShow); | ||
if (it) { | if (it) { | ||
it.classList.add("inflection-table-collapsed"); | it.classList.add("inflection-table-collapsed"); | ||
| Line 174: | Line 175: | ||
/* ==Hidden Quotes== */ | /* ==Hidden Quotes== */ | ||
function setupHiddenQuotes(li) { | function setupHiddenQuotes(li) { | ||
if (checkAndSetToggleified(li)) | if (checkAndSetToggleified(li)) | ||
return; | return; | ||
let HQToggleButton, liComp, dl; | |||
function show() { | function show() { | ||
HQToggleButton.text("quotations ▲"); | |||
$(li).children("ul").show(); | $(li).children("ul").show(); | ||
} | } | ||
function hide() { | function hide() { | ||
HQToggleButton.text("quotations ▼"); | |||
$(li).children("ul").hide(); | $(li).children("ul").hide(); | ||
} | } | ||
for ( | for (const liComp of li.childNodes) { | ||
// Look at each component of the definition. | // Look at each component of the definition. | ||
if (liComp.tagName === "DL" && !dl) | |||
if (liComp. | |||
dl = liComp; | dl = liComp; | ||
// If we find a ul or dl, we have quotes or example sentences, and thus need a button. | // If we find a ul or dl, we have quotes or example sentences, and thus need a button. | ||
if ( | if (liComp.tagName === "UL") { | ||
$(li).children("ul").addClass("wikt-quote-container"); | |||
$(dl || liComp).before($("<span>").addClass("HQToggle").attr("data-nosnippet", "").append( | HQToggleButton = $("<a>").attr("role", "button").attr("tabindex", "0"); | ||
$(dl || liComp).before($("<span>").addClass("HQToggle").attr("data-nosnippet", "").append(HQToggleButton).css("margin-left", "5px")); | |||
HQToggleButton.on("click", window.VisibilityToggles.register("quotations", show, hide)); | |||
break; | break; | ||
} | } | ||
| Line 257: | Line 256: | ||
toggleElement.on("click", window.VisibilityToggles.register(toggleCategory, | toggleElement.on("click", window.VisibilityToggles.register(toggleCategory, | ||
function show() { | function show() { | ||
toggleButton. | toggleButton.text(hideButtonText); | ||
elemsToShow.hide(); | elemsToShow.hide(); | ||
elemsToHide.show(); | elemsToHide.show(); | ||
}, | }, | ||
function hide() { | function hide() { | ||
toggleButton. | toggleButton.text(showButtonText); | ||
elemsToShow.show(); | elemsToShow.show(); | ||
elemsToHide.hide(); | elemsToHide.hide(); | ||
| Line 321: | Line 320: | ||
$toggleElement.on("click", window.VisibilityToggles.register(toggleCategory, | $toggleElement.on("click", window.VisibilityToggles.register(toggleCategory, | ||
function show() { | function show() { | ||
$toggleButton. | $toggleButton.text(hideButtonText); | ||
if (rootElement) { | if (rootElement) { | ||
rootElement.classList.remove("list-switcher-collapsed"); | rootElement.classList.remove("list-switcher-collapsed"); | ||
| Line 327: | Line 326: | ||
}, | }, | ||
function hide() { | function hide() { | ||
$toggleButton. | $toggleButton.text(showButtonText); | ||
if (rootElement) { | if (rootElement) { | ||
rootElement.classList.add("list-switcher-collapsed"); | rootElement.classList.add("list-switcher-collapsed"); | ||
| Line 397: | Line 396: | ||
function show() { | function show() { | ||
toggler. | toggler.text(text + nbsp + "▲"); | ||
$(dlTag).show(); | $(dlTag).show(); | ||
$(elements).show(); | $(elements).show(); | ||
} | } | ||
function hide() { | function hide() { | ||
toggler. | toggler.text(text + nbsp + "▼"); | ||
if ($(dlTag).children().length === elements.length) { | if ($(dlTag).children().length === elements.length) { | ||
$(dlTag).hide(); | $(dlTag).hide(); | ||
| Line 437: | Line 436: | ||
function show() { | function show() { | ||
toggler. | toggler.text(category + nbsp + "▲"); | ||
$(dlTag).show(); | $(dlTag).show(); | ||
$(elements).show(); | $(elements).show(); | ||
} | } | ||
function hide() { | function hide() { | ||
toggler. | toggler.text(category + nbsp + "▼"); | ||
if ($(dlTag).children().length === elements.length) { | if ($(dlTag).children().length === elements.length) { | ||
$(dlTag).hide(); | $(dlTag).hide(); | ||
| Line 529: | Line 528: | ||
}); | }); | ||
})(); | })(); | ||