MediaWiki:Gadget-defaultVisibilityToggles.js: Difference between revisions

Undo revision 462950 by Sware (talk)
Tag: Undo
No edit summary
Line 1: Line 1:
/* jshint undef: true, esversion: 5 */
/* jshint undef: true */
/* globals $, jQuery, mw, window, getComputedStyle */
/* globals $, jQuery, mw, window, getComputedStyle */


mw.loader.using(['mediawiki.util', 'mediawiki.storage', 'jquery'], function () {
(function defaultVisibilityTogglesIIFE() {
    $(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.html(NavigationBarHide);
$navToggle.text(NavigationBarHide);
if (navContent)
if (navContent)
navContent.style.display = "block";
navContent.style.display = "block";
},
},
function hide() {
function hide() {
$navToggle.html(NavigationBarShow);
$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.html(NavigationBarHide);
$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.html(NavigationBarShow);
$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;
}
var HQToggle, liComp, dl;
let HQToggleButton, liComp, dl;
var HQShow = "quotations ▼";
 
var HQHide = "quotations ▲";
function show() {
function show() {
HQToggle.html(HQHide);
HQToggleButton.text("quotations ▲");
$(li).children("ul").show();
$(li).children("ul").show();
}
}
function hide() {
function hide() {
HQToggle.html(HQShow);
HQToggleButton.text("quotations ▼");
$(li).children("ul").hide();
$(li).children("ul").hide();
}
}
for (var k = 0; k < li.childNodes.length; k++) {
for (const liComp of li.childNodes) {
// Look at each component of the definition.
// Look at each component of the definition.
liComp = li.childNodes[k];
if (liComp.tagName === "DL" && !dl)
if (liComp.nodeName.toLowerCase() === "dl" && !dl) {
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 (/^(ul|UL)$/.test(liComp.nodeName)) {
if (liComp.tagName === "UL") {
HQToggle = $("<a>").attr("role", "button").attr("tabindex", "0");
$(li).children("ul").addClass("wikt-quote-container");
$(dl || liComp).before($("<span>").addClass("HQToggle").attr("data-nosnippet", "").append(HQToggle).css("margin-left", "5px"));
HQToggleButton = $("<a>").attr("role", "button").attr("tabindex", "0");
HQToggle.on("click", window.VisibilityToggles.register("quotations", show, hide));
$(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.html(hideButtonText);
toggleButton.text(hideButtonText);
elemsToShow.hide();
elemsToShow.hide();
elemsToHide.show();
elemsToHide.show();
},
},
function hide() {
function hide() {
toggleButton.html(showButtonText);
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.html(hideButtonText);
$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.html(showButtonText);
$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.html(text + "&nbsp;▲");
toggler.text(text + nbsp + "▲");
$(dlTag).show();
$(dlTag).show();
$(elements).show();
$(elements).show();
}
}
function hide() {
function hide() {
toggler.html(text + "&nbsp;▼");
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.html(category + "&nbsp;▲");
toggler.text(category + nbsp + "▲");
$(dlTag).show();
$(dlTag).show();
$(elements).show();
$(elements).show();
}
}
function hide() {
function hide() {
toggler.html(category + "&nbsp;▼");
toggler.text(category + nbsp + "▼");
if ($(dlTag).children().length === elements.length) {
if ($(dlTag).children().length === elements.length) {
$(dlTag).hide();
$(dlTag).hide();
Line 529: Line 528:
});
});
})();
})();
});