- 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 (For User:がか) |
(No difference)
|
Revision as of 20:49, 18 February 2016
(function($) {
"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_default = toggle_element.data("default") || "show",
target = "toggle-target-" + property,
target_class = "." + target,
toggleStorage = ToggleStorage(target, property_default);
if (toggle) {
toggleStorage.toggle();
}
if (toggleStorage.on()) {
toggle_element.find(".toggle-show").show();
toggle_element.find(".toggle-hide").hide();
$(target_class).show();
} else {
toggle_element.find(".toggle-show").hide();
toggle_element.find(".toggle-hide").show();
$(target_class).hide();
}
}
$(".toggle").each(function() {
$(this).show();
update($(this));
});
$(".toggle").click(function() {
update($(this), true);
});
});
}(jQuery));