User:Effan R/common.js

require(['wikia.window', 'jquery', 'mw'], function (window, $, mw) {   window.HashAnchorInTabView = window.AnchorInTabView || {};    if (typeof window.HashAnchorInTabView.Load !== 'undefined' || $('body').hasClass('editor')) {       return; // prevent second load.    }    window.HashAnchorInTabView = $.extend({ Load: true, }, window.HashAnchorInTabView);

function processHash { //Split hash into tab-name and (section heading if present) //Matches with or without # var res = location.hash.match(/^#?(.+?)(?:(?:[\.%]2f|\/)(.+))?$/i);

// Should not be here if #hash is empty (hook will not be added) // Just to make sure. Possibly remove this check once stable. if (res === null) { return; }       var loc = res[1].replace(/\./g, "%"); var sect = res[2];

console.log("loc:" + loc + "\nsect:" + sect); var $tab = $('.tabs>li[data-tab^="flytabs"]').filter(function {               console.log(mw.util.wikiUrlencode($(this).find('a>span:first').text));        		return (mw.util.wikiUrlencode($(this).find('a>span:first').text) === loc);        	});

console.log($tab);

if ($tab.length !== 0) { var tabId = $tab.attr('data-tab'); if (!$tab.hasClass('selected')) { $elem = $tab.find('a'); if ($elem !== undefined) { console.log("Clicked to Select Tab:" + tabId); $elem.click; }           }            else { console.log("Tab already Selected:" + tabId);

//console.log("Element is:"); //console.log($elem); //mw.hook('wikipage.content').remove(process); }       }    }

if (location.hash !== "") { mw.hook('wikipage.content').add(processHash); } });