$(".NavHeader").click(function(){
(function defaultVisibilityTogglesIIFE() {
if( 1 === $(this).closest(".NavHidden").next(".NavContent").length) {
"use strict";
$(this).closest(".NavHidden").next(".NavContent").toggle();
} else {
var NavigationBarHide = "ocultar";
$(this).next(".NavContent").toggle();
var NavigationBarShow = "exibir";
function checkAndSetToggleified(element) {
if (element.isToggleified) {
return true;
}
element.isToggleified = true;
}
function getToggleCategory(element, defaultCategory) {
if ($(element).find("table").first().is(".translations"))
return "translations";
var heading = element;
while ((heading = heading.previousElementSibling)) {
var num = heading.tagName.match(/H(\d)/);
if (num)
num = Number(num[1]);
else
continue;
if (4 <= num && num <= 6) {
if (heading.getElementsByTagName("span")[1])
heading = heading.getElementsByTagName("span")[0];
var text = jQuery(heading).text()
.toLowerCase()
.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ")
.replace(/^[1-9][0-9.]+ ?/, "");
if (/^[a-zA-Z0-9\s_-]+$/.test(text))
return text;
else
break;
} else if (num)
break;
}
return defaultCategory;
}
function createNavToggle(navFrame) {
if (checkAndSetToggleified(navFrame)) {
return;
}
var navHead, navContent;
for (var i = 0, children = navFrame.childNodes; i < children.length; ++i) {
var child = children[i];
if (child.nodeName === "DIV") {
var classList = child.classList;
if (classList.contains("NavHead"))
navHead = child;
if (classList.contains("NavContent"))
navContent = child;
}
}
if (!(navHead && navContent))
return;
$(navHead).find("a").on("click", function (e) {
e.stopPropagation();
});
var $navToggle = $("<a>").attr("role", "button").attr("tabindex", "0");
$("<span>").addClass("NavToggle")
.append($navToggle)
.prependTo(navHead);
navHead.style.cursor = "pointer";
var toggleCategory = $(navFrame).data("toggle-category")
|| getToggleCategory(navFrame, "todas caixas");
navHead.onclick = window.VisibilityToggles.register(toggleCategory,
function show() {
$navToggle.html(NavigationBarHide);
if (navContent)
navContent.style.display = "block";
},
function hide() {
$navToggle.html(NavigationBarShow);
if (navContent)
navContent.style.display = "none";
});
}
function setupHiddenQuotes(li) {
if (checkAndSetToggleified(li)) {
return;
}
var HQToggle, liComp, dl;
var HQShow = "citações";
var HQHide = "citações";
function show() {
HQToggle.html(HQHide);
$(li).children("ul").show();
}
function hide() {
HQToggle.html(HQShow);
$(li).children("ul").hide();
}
for (var k = 0; k < li.childNodes.length; k++) {
// Look at each component of the definition.
liComp = li.childNodes[k];
if (liComp.nodeName.toLowerCase() === "dl" && !dl) {
dl = liComp;
}
if (/^(ul|UL)$/.test(liComp.nodeName)) {
HQToggle = $("<a>").attr("role", "button").attr("tabindex", "0");
$(dl || liComp).before($("<span>").addClass("HQToggle").append(HQToggle));
HQToggle.on("click", window.VisibilityToggles.register("quotations", show, hide));
break;
}
}
}
function viewSwitching(rootElement) {
if (checkAndSetToggleified(rootElement)) {
return;
}
var $rootElement = $(rootElement);
var showButtonText = $rootElement.data("vs-showtext") || "mais";
var hideButtonText = $rootElement.data("vs-hidetext") || "menos";
var toSkip = $rootElement.find(".vsSwitcher").find("*");
var elemsToHide = $rootElement.find(".vsHide").not(toSkip);
var elemsToShow = $rootElement.find(".vsShow").not(toSkip);
// Find the element to place the toggle button in.
var toggleElement = $rootElement.find(".vsToggleElement").not(toSkip).first();
// The toggleElement becomes clickable in its entirety, but
// we need to prevent this if a contained link is clicked instead.
toggleElement.children("a").on("click", function (e) {
e.stopPropagation();
});
var toggleButton = $("<a>").attr("role", "button").attr("tabindex", "0");
$("<span>").addClass("NavToggle").append(toggleButton).prependTo(toggleElement);
var toggleCategory = $rootElement.data("toggle-category");
if (!toggleCategory) {
var classNames = $rootElement.attr("class").split(/\s+/);
for (var i = 0; i < classNames.length; ++i) {
var className = classNames[i].split("-");
if (className[0] == "vsToggleCategory") {
toggleCategory = className[1];
}
}
}
if (!toggleCategory)
toggleCategory = "others";
toggleElement.css("cursor", "pointer");
toggleElement.on("click", window.VisibilityToggles.register(toggleCategory,
function show() {
toggleButton.html(hideButtonText);
elemsToShow.hide();
elemsToHide.show();
},
function hide() {
toggleButton.html(showButtonText);
elemsToShow.show();
elemsToHide.hide();
}));
}
window.listSwitcherRowCount = window.listSwitcherRowCount || 3;
function getListItemsToHide($listItems, columnCount, rowsInShowState) {
var count = $listItems.length;
var itemsPerColumn = Math.ceil(count / columnCount);
var $elemsToHide = $();
if (itemsPerColumn > rowsInShowState) {
for (var i = 0; i < columnCount; ++i) {
var columnStart = i * itemsPerColumn;
$elemsToHide = $elemsToHide
.add($listItems.slice(columnStart + rowsInShowState, columnStart + itemsPerColumn));
}
}
return $elemsToHide;
}
function enableListSwitch (rootElement, rowsInShowState) {
if (checkAndSetToggleified(rootElement)) {
return;
}
var $rootElement = $(rootElement);
var $termList = $rootElement.find(".term-list");
var $toggleElement = $rootElement.find(".list-switcher-element");
var columnCount = parseInt($termList.data("column-count"), 10);
if (!(columnCount && columnCount > 0)) {
$toggleElement.hide();
return;
}
var $listItems = $rootElement.find("ul").first().find("li");
var $toHide = getListItemsToHide($listItems, columnCount, rowsInShowState);
if ($toHide.length === 0) {
$toggleElement.hide();
return;
}
$toggleElement.css("cursor", "pointer");
var $toggleButton = $("<a>").attr("role", "button").attr("tabindex", "0");
var rootBackgroundColor = $termList.css("background-color"),
rootBackground = $termList.css("background");
var $navToggle = $("<span>").addClass("NavToggle");
if (rootBackgroundColor || rootBackground)
$navToggle.css(rootBackgroundColor ? "background-color" : "background",
rootBackgroundColor || rootBackground);
$toggleElement.children("a").on("click", function (e) {
e.stopPropagation();
});
var toggleCategory = $rootElement.data("toggle-category")
|| getToggleCategory($rootElement[0], "other lists");
var showButtonText = $toggleElement.data("showtext") || "mais";
var hideButtonText = $toggleElement.data("hidetext") || "menos";
$toggleElement.on("click", window.VisibilityToggles.register(toggleCategory,
function show() {
$toggleButton.html(hideButtonText);
$toHide.show();
},
function hide() {
$toggleButton.html(showButtonText);
$toHide.hide();
}));
$navToggle.append($toggleButton).prependTo($toggleElement);
$toggleElement.show();
}
window.createNavToggle = createNavToggle;
window.setupHiddenQuotes = setupHiddenQuotes;
window.viewSwitching = viewSwitching;
window.getToggleCategory = getToggleCategory;
mw.hook('wikipage.content').add(function($content) {
// NavToggles
$('.NavFrame', $content).each(function(){
createNavToggle(this);
});
if (mw.config.get('wgNamespaceNumber') === 0) {
$('ol > li', $content).each(function(){
setupHiddenQuotes(this);
});
}
$('.vsSwitcher', $content).each(function(){
viewSwitching(this);
});
$(".list-switcher", $content).each(function () {
enableListSwitch(this, window.listSwitcherRowCount);
});
});
jQuery(mw).on("LivePreviewDone", function (ev, sels) {
var ols = jQuery(sels.join(",")).find("ol");
for (var i = 0; i < ols.length; i++) {
for (var j = 0; j < ols[i].childNodes.length; j++) {
var li = ols[i].childNodes[j];
if (li.nodeName.toUpperCase() == "LI") {
setupHiddenQuotes(li);
}
}
}
});
})();
|