Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Strayerror (talk | contribs)
No edit summary
Strayerror (talk | contribs)
No edit summary
Line 26: Line 26:


mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {
   //const tabs = ['current', 'legacy'];
   const tabs = ['current', 'legacy'];
   const [hint, frag] = window.location.hash.slice(1).split('#');
   const [hint, frag] = window.location.hash.slice(1).split('#');


   const pref = localStorage.getItem('preferredVersion') || 'current';
   const pref = localStorage.getItem('preferredVersion') || 'current';


  console.log(hint, frag, tabs);
   if (hint && frag && tabs.indexOf(hint) !== -1) {
   if (hint && frag && tabs.indexOf(hint) !== -1) {
  //pref = hint;
    pref = hint;
     location.hash = frag;
     location.hash = frag;
   }
   }
Line 40: Line 39:
     if (tabs.indexOf(tab) === -1) return;
     if (tabs.indexOf(tab) === -1) return;


    // Hide all tab contents
     $content.find('div.vt-content').hide();
     $content.find('div.vt-content').hide();
    // Show the selected one
     $content.find('div.vt-' + tab).show();
     $content.find('div.vt-' + tab).show();


    // Update active class on <li> tabs
     $content.find('ul.version-tabs li').removeClass('active');
     $content.find('ul.version-tabs li').removeClass('active');
     $content.find('ul.version-tabs li[data-tab="' + tab + '"]').addClass('active');
     $content.find('ul.version-tabs li[data-tab="' + tab + '"]').addClass('active');


    // Save selection
     localStorage.setItem('preferredVersion', tab);
     localStorage.setItem('preferredVersion', tab);
   }
   }


  // Click handler for tab <li>
   $content.find('ul.version-tabs li').click(function (e) {
   $content.find('ul.version-tabs li').click(function (e) {
     e.preventDefault();
     e.preventDefault();
Line 60: Line 54:
   });
   });


  // Initialize the tab from saved preference or default
   activateTab(pref);
   activateTab(pref);
});
});

Revision as of 03:55, 11 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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
	};

	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 tabs = ['current', 'legacy'];
  const [hint, frag] = window.location.hash.slice(1).split('#');

  const pref = localStorage.getItem('preferredVersion') || 'current';

  if (hint && frag && tabs.indexOf(hint) !== -1) {
    pref = hint;
    location.hash = frag;
  }

  function activateTab(tab) {
    if (tabs.indexOf(tab) === -1) return;

    $content.find('div.vt-content').hide();
    $content.find('div.vt-' + tab).show();

    $content.find('ul.version-tabs li').removeClass('active');
    $content.find('ul.version-tabs li[data-tab="' + tab + '"]').addClass('active');

    localStorage.setItem('preferredVersion', tab);
  }

  $content.find('ul.version-tabs li').click(function (e) {
    e.preventDefault();
    const selected = this.dataset.tab;
    activateTab(selected);
  });

  activateTab(pref);
});