MediaWiki:Wikia.js/HoverTool.js

//DO DO LIST! /*
 * Find out why cookies are not being saved!
 * -> Always creates new cookie (NEW DATABASE)
 * When json for page pulled, create pop tool tip
 * Do not work when link contains special namespaces & external links
 * Do not work when link contains special namespaces & external links

//On hover of link $("a").hover(function{	//["file", "special", ]	//Gets first character of a link & full page name	var pageName = $(this).attr("href").split('/wiki/')[1];	var dbIndex = $(this).attr("href").split('/wiki/')[1][0].toLowerCase;	//Checks if database has been saved to cookies.	//If database has not been saved, download and save.	if (!$.cookie("hovertool-db-" + dbIndex)) {		//If first character is not a letter, assign to db 0, otherwise get matching database		if (['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'].indexOf(dbIndex) > -1) {			var dbTitle = "Project:HoverTool/" + dbIndex;		} else {			var dbTitle = "Project:HoverTool/0";		};		//Download JSON database		//Performs synchronous get request for page contents of database		var dbFetch = JSON.parse( $.ajax({				url:mw.util.wikiScript('api'),				data: { action: 'query', format: 'json', prop: 'revisions', titles: dbTitle, rvprop: "timestamp|content" },				async:false			}) .responseText );

//Parses database from get request and converts to JSON var dbJSON = JSON.parse(dbFetch["query"]["pages"][Object.keys(dbFetch.query.pages)[0]]["revisions"][0]["*"]) //Save database in cookies for faster loading next time $.cookie("hovertool-db-" + dbIndex, JSON.stringify(dbJSON), { expires: 7, path: '/' }); console.log("NEW DATABASE CREATED");

//If database has been saved, reloads from cookies. } else { //Pulls saved cookies and parses database as JSON object var dbJSON = JSON.parse($.cookie("hovertool-db-" + dbIndex)); console.log("DATABASE TAKEN FROM COOKIES"); }	//Returns JSON for page name from database console.log(dbJSON[pageName.replace(/_/g, " ")]); });