- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Difference between revisions of "MediaWiki:DetailToggle.js"
Jump to navigation
Jump to search
com>Ckwng (Compatibility with tabview) |
com>Ckwng |
||
Line 23: | Line 23: | ||
function update(toggle_element, toggle) { | function update(toggle_element, toggle) { | ||
var property = toggle_element.data("target") || "default", | var property = toggle_element.data("target") || "default", | ||
+ | property_anti = toggle_element.data("anti-target"), | ||
property_default = toggle_element.data("default") || "show", | property_default = toggle_element.data("default") || "show", | ||
target = "toggle-target-" + property, | target = "toggle-target-" + property, | ||
target_class = "." + target, | target_class = "." + target, | ||
+ | anti_target_class, | ||
toggleStorage = ToggleStorage(target, property_default); | toggleStorage = ToggleStorage(target, property_default); | ||
+ | if (property_anti) { | ||
+ | anti_target_class = ".toggle-anti-target-" + property; | ||
+ | } | ||
if (toggle) { | if (toggle) { | ||
toggleStorage.toggle(); | toggleStorage.toggle(); | ||
Line 34: | Line 39: | ||
$(".toggle-hide").hide(); | $(".toggle-hide").hide(); | ||
$(target_class).show(); | $(target_class).show(); | ||
+ | if (anti_target_class) { | ||
+ | $(anti_target_class).hide(); | ||
+ | } | ||
} else { | } else { | ||
$(".toggle-show").hide(); | $(".toggle-show").hide(); | ||
$(".toggle-hide").show(); | $(".toggle-hide").show(); | ||
$(target_class).hide(); | $(target_class).hide(); | ||
+ | if (anti_target_class) { | ||
+ | $(anti_target_class).show(); | ||
+ | } | ||
} | } | ||
} | } |
Revision as of 07:34, 8 July 2016
(function(mw, $) {
"use strict";
$(document).ready(function() {
if (typeof(Storage) === "undefined") {
return;
}
var ToggleStorage = function(property, property_default) {
if (!localStorage[property]) {
localStorage[property] = property_default;
}
return {
toggle: function() {
localStorage[property] = localStorage[property] === "show" ? "hide" : "show";
},
on: function() {
return localStorage[property] === "show";
}
};
}
function update(toggle_element, toggle) {
var property = toggle_element.data("target") || "default",
property_anti = toggle_element.data("anti-target"),
property_default = toggle_element.data("default") || "show",
target = "toggle-target-" + property,
target_class = "." + target,
anti_target_class,
toggleStorage = ToggleStorage(target, property_default);
if (property_anti) {
anti_target_class = ".toggle-anti-target-" + property;
}
if (toggle) {
toggleStorage.toggle();
}
if (toggleStorage.on()) {
$(".toggle-show").show();
$(".toggle-hide").hide();
$(target_class).show();
if (anti_target_class) {
$(anti_target_class).hide();
}
} else {
$(".toggle-show").hide();
$(".toggle-hide").show();
$(target_class).hide();
if (anti_target_class) {
$(anti_target_class).show();
}
}
}
function updateContent() {
$(".toggle").each(function() {
var toggle_element = $(this);
toggle_element.show();
update(toggle_element);
toggle_element.off("click");
toggle_element.click(function() {
update(toggle_element, true);
});
});
}
updateContent();
mw.hook("wikipage.content").add(updateContent);
});
}(mediaWiki, jQuery));