Difference between revisions of "MediaWiki:Common.js"
From Summertime Saga Wiki
Strayerror (talk | contribs) |
Strayerror (talk | contribs) |
||
| Line 26: | Line 26: | ||
mw.hook('wikipage.content').add(function ($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
| − | const | + | const _ = $content.find; |
const savedTab = localStorage.getItem("preferredVersion") || "current"; | const savedTab = localStorage.getItem("preferredVersion") || "current"; | ||
| Line 33: | Line 33: | ||
// Hide all tab contents | // Hide all tab contents | ||
| − | + | _("div.vt-content").hide(); | |
// Show the selected one | // Show the selected one | ||
| − | + | _("div.vt-" + tab).show(); | |
// Update active class on <li> tabs | // Update active class on <li> tabs | ||
| − | + | _("ul.version-tabs li").removeClass("active"); | |
| − | + | _("ul.version-tabs li[data-tab='" + tab + "']").addClass("active"); | |
// Save selection | // Save selection | ||
| Line 46: | Line 46: | ||
// Click handler for tab <li> | // Click handler for tab <li> | ||
| − | + | _("ul.version-tabs li").click(function () { | |
const selected = this.dataset.tab; | const selected = this.dataset.tab; | ||
activateTab(selected); | activateTab(selected); | ||
Revision as of 22:36, 9 October 2025
/* Any JavaScript here will be loaded for all users on every page load. */
// Wait for document ready
$(function() {
var htmle = function(str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
};
if ($('body').hasClass('page-Summertime_Saga_Wiki') && $('body').hasClass('action-view') && $('body').hasClass('skin-vector') && $('#ajax-posts').length && $('#ajax-version').length) {
var maxPosts = 5;
$.getJSON('/ssdata.json', function(data) {
$('#ajax-version').text(data.version);
$('#ajax-posts').html('');
data.posts.forEach(function(post, i) {
if (i >= maxPosts) {
return;
}
$('#ajax-posts').append('<dd><b>▪ ' + htmle(post.date) + ':</b> <a rel="nofollow" class="external text" href="https://www.patreon.com' + htmle(post.url) + '">' + htmle(post.title) + '</a></dd>');
});
});
}
}());
mw.hook('wikipage.content').add(function ($content) {
const _ = $content.find;
const savedTab = localStorage.getItem("preferredVersion") || "current";
function activateTab(tab) {
if (tab !== "current" && tab !== "legacy") return;
// Hide all tab contents
_("div.vt-content").hide();
// Show the selected one
_("div.vt-" + tab).show();
// Update active class on <li> tabs
_("ul.version-tabs li").removeClass("active");
_("ul.version-tabs li[data-tab='" + tab + "']").addClass("active");
// Save selection
localStorage.setItem("preferredVersion", tab);
}
// Click handler for tab <li>
_("ul.version-tabs li").click(function () {
const selected = this.dataset.tab;
activateTab(selected);
});
// Initialize the tab from saved preference or default
activateTab(savedTab);
});