MediaWiki:Mobile.js

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 01:19, 25 December 2022 by Vish (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Mobile Menu */
var timer = setInterval(function() {
     if ($('.menu ul:first').length) {
         //console.log("mobile menu exists");
         clearInterval(timer);
         $.get('/customizations/mobilemenu.htm', function(data){
    		$('.menu ul:first').after(data);
		 });

          $(".menu").find(".level2").hide(); // hide level2 until level1 is clicked
          $(".level1").click(function(event){ 
               $(this).find(".level2").slideToggle(500);
          }); // if level1 is clicked, dropdown level2
     }
}, 100); // check every 100ms

//<tabber> extension req
//v3.0 Originally by User:fngplg. modified by User:Vish in 2021
//set active tab: https://jojowiki.com/page#activeTab
(function ($){
    var nstarget = window.location.hash.replace('#', '');
    if (nstarget === '') return;
    //convert wiki-utf 2 ansi
    nstarget = decodeURIComponent(nstarget).replace(/_/g, ' ');
    //console.log('trgt:'+nstarget);
    $(function(){
        setTimeout(function() {
            var nt2a = $('.tabberlive>.tabbernav>li>a[title="' + nstarget + '"]');
            if(nt2a.get(0) !== undefined) {
            	nt2a.click();
            	nt2a.get(0).scrollIntoView({inline: "nearest"});
        	}
        }, 100);//settimeout
    });//doc.rdy    
})(jQuery);

/* Tooltip */
$(".popup").click(function () {
    var $title = $(this).find(".title");
    if (!$title.length) {
        $(this).append('<span class="title">' + $(this).attr("title") + '</span>');
    } else {
        $title.remove();
    }
});

// Creates action=raw links for JS or CSS gadgets
// Useful for mw.loader.load, which doesn't accept page titles
function rawPageLink( pageName ) {
  return mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode(pageName) + '&action=raw&ctype=text/javascript';
}

// Overwriting deprecated functions that don't have an exact followup but can be easily mapped:
window.importScript = function ( page ) {
  if ( typeof page === 'string' && page.length ) {
    mw.loader.load( rawPageLink( page ) );
  }
};

// Highlighting for tabs on game pages
var selfLink = document.getElementsByClassName("mw-selflink");
if (selfLink.length > 2) {
	if (selfLink[1].firstChild.nodeName=='SPAN') {
		selfLink[1].firstChild.classList.add(selfLink[1].firstChild.classList[2].replace('2', ''));
		selfLink[1].firstChild.classList.remove(selfLink[1].firstChild.classList[2]);
	}
}

var gameTab = document.getElementsByClassName('mcbutton');
var headers = document.getElementsByClassName('mw-headline');

function compareText(item1, item2) {
	if (item1 == item2) {
		return true;
	}
}

function highlightTab(item) {
	item.classList.add(item.classList[2].replace('2', ''));
	item.classList.remove(item.classList[2]);
}


for (var i = 0; i < headers.length; i++) {
	if (typeof headers[i].firstChild.text !== 'undefined') {
	for (var j = 0; j < gameTab.length; j++) {
		if (compareText(headers[i].firstChild.text, gameTab[j].textContent)) {
			highlightTab(gameTab[j]);
		}
	}
	}
}