Jump to content

User:Technical 13/SandBox/Gadget-extraTabs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 21:30, 29 January 2014 (Meh, all I can think of... The variable is properly defining, just not updating the link...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function() {
	var nsNum = mw.config.get('wgNamespaceNumber');
	if(nsNum === 10 || nsNum === 11){
		var isPage = false, isTalk = false, isSand = false, isTest = false;
		var rawPageName = mw.config.get('wgTitle');
		if(rawPageName.indexOf('/sandbox') !== -1){
			rawPageName = rawPageName.slice(0, rawPageName.indexOf('/sandbox'));
			isSand = true;
		}
		if (rawPageName.indexOf('/testcases') !== -1) {
			rawPageName = rawPageName.slice(0, rawPageName.indexOf('/testcases'));
			isTest = true;
		}
		if(nsNum === 11) {
			isTalk = true;
		} else if(nsNum === 10){
			isPage = true;
		}
		var rawPage = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName);
		var talkPage = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName);
		var sandbox = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/sandbox');
		var sandTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/sandbox');
		var testcases = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/testcases');
		var testTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/testcases');
		$('#ca-nstab-template').attr('href', rawPage);
		$('#ca-talk').attr('href', talkPage);
		mw.util.addPortletLink('p-namespaces', sandbox, 'Sandbox', 'ca-sand', 'View the sandbox');
		mw.util.addPortletLink('p-namespaces', testcases, 'Testcases', 'ca-test', 'View the testcases');
		if(isSand === true && isTalk === true){
			$('#ca-nstab-template').removeClass("selected");
			mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
			$('#ca-sandtalk').addClass("selected");
		} else if(isTest === true && isTalk === true){
			$('#ca-nstab-template').removeClass("selected");
			mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
			$('#ca-testtalk').addClass("selected");
		} else if(isSand === true){
			$('#ca-nstab-template').removeClass("selected");
			$('#ca-sand').addClass("selected");
			mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
		} else if(isTest === true){
			$('#ca-nstab-template').removeClass("selected");
			$('#ca-test').addClass("selected");
			mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
		}
	}
});