- 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:がか) |
com>Ckwng (Compatibility with tabview) |
||
Line 1: | Line 1: | ||
− | (function($) { | + | (function(mw, $) { |
"use strict"; | "use strict"; | ||
$(document).ready(function() { | $(document).ready(function() { | ||
Line 6: | Line 6: | ||
return; | return; | ||
} | } | ||
− | + | ||
var ToggleStorage = function(property, property_default) { | var ToggleStorage = function(property, property_default) { | ||
if (!localStorage[property]) { | if (!localStorage[property]) { | ||
Line 31: | Line 31: | ||
} | } | ||
if (toggleStorage.on()) { | if (toggleStorage.on()) { | ||
− | + | $(".toggle-show").show(); | |
− | + | $(".toggle-hide").hide(); | |
$(target_class).show(); | $(target_class).show(); | ||
} else { | } else { | ||
− | + | $(".toggle-show").hide(); | |
− | + | $(".toggle-hide").show(); | |
$(target_class).hide(); | $(target_class).hide(); | ||
} | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | $(".toggle"). | + | 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); | ||
}); | }); | ||
− | }(jQuery)); | + | }(mediaWiki, jQuery)); |
Revision as of 08:45, 20 February 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_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-show").show();
$(".toggle-hide").hide();
$(target_class).show();
} else {
$(".toggle-show").hide();
$(".toggle-hide").show();
$(target_class).hide();
}
}
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));