Jump to content

User:RCSDevs/spider web.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by RCSDevs (talk | contribs) at 22:25, 19 July 2016. 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.
importStylesheet('User:RCSDevs/spider_web.css');

$(document).ready(function()
{
	var section = $('aside.ra-read-more.post-content.noprint').eq(0),
		tag = section.find('h2').eq(0),
		list = section.find('ul').eq(0).clone(),
		showSpiderWeb = localStorage.getItem('SHOW_SPIDERWEB') ? localStorage.getItem('SHOW_SPIDERWEB') : false;
	
	tag.html('Related Pages | <a id="toggle_spiderweb" href="#">Toggle SpiderWeb</a>');

	var setup = function()
	{
		if(showSpiderWeb)
		{
			var width = tag.width();
			
			section.children().not(tag).remove();
			section.append('<div id="web_container" style="width: ' + width + 'px; height: ' + (width / 3) + 'px"></div>');	
		}
		else
		{
			section.append(list);
		}
	};

	$('#toggle_spiderweb').click(function(event)
	{
		event.preventDefault();
		showSpiderWeb = !showSpiderWeb;
		localStorage.setItem('SHOW_SPIDERWEB', showSpiderWeb);
		setup();
	});
	
	$(window).resize(setup);
});