User:Scormus/global.js

/*

Tools: reload cache

*/

//idea & coding: Marooned 2010-04-01 $(function{	if (wgPageName != 'User:Scormus/sandboxzzz') return;	var chicken = $(' ').attr('src', 'http://img19.yfrog.com/img19/6621/chickeng.gif').css({'position':'absolute', 'z-index':1000}).appendTo(document.body);	var width = $.getViewportWidth;	var offsetH = offsetV = 0;	var animate = function {		offsetH+=10;		offsetV+=2;		chicken.css({'top':offsetV + 10 + 'px', 'left':width - offsetH + 'px'});		if (width - offsetH < -88) {			clearInterval(intervalId);			chicken.remove;			$('body').css('overflow-x', '');		}	};	var intervalId = setInterval(animate, 50);	$('body').css('overflow-x', 'hidden');	chicken.show; }); // The source code on this page is covered by the CC-BY-SA license and this code may be freely used on any Wikia site for any purpose under this license. // Beyond Wikia, this code must retain the attribution below and this must be easily visible on any page that uses the source code directly or indirectly: // This code was created by Scormus for championsonline.wikia.com // // Any and all other copyright restriction remain in place.

// remove the x for ACTION xaddOnloadHook(function { alert('28');       writeAllNotations;        alert('end flagA:');	});

var worldDX = 0; var worldDY = 0; var worldScaleX = 1.; var worldScaleY = 1.; var params = {}; var defaultMap = "default"; var defaultMapVersion = "full"; var maphtml = "empty"; var thisLabelX = 0; var thisLabelY = 0;

function getMapImageData(mapCode, mapVersion) { if (mapCode == "mil") { var mapData = new Object; mapData["imageURL"] = "http://images1.wikia.nocookie.net/__cb20100413230531/championsonline/images/5/55/Millennium_City_Full_Map.png"; mapData["worldGridPoints"]= ["1169 66 1920", "10061 198 -2712"]; mapData["imageGridPoints"] = ["345,123", "1421,687"]; return mapData; }

return getMapImageDataFromPage(mapVersion);

// return getDefaultMapImageData; }

function getMapImageDataFromPage(mapVersion) { var mapData = new Object; mapData["imageURL"] = "http://images1.wikia.nocookie.net/__cb20100413230531/championsonline/images/5/55/Millennium_City_Full_Map.png";

var refWorldGridPoint1=document.getElementById("worldGridPoint1"); if (!refWorldGridPoint1) { return getDefaultMapImageData; }

var refWorldGridPoint2=document.getElementById("worldGridPoint2"); if (!refWorldGridPoint2) { return getDefaultMapImageData; }

var refImageGridPoint1=document.getElementById("imageGridPoint1"); if (!refImageGridPoint1) { return getDefaultMapImageData; }

var refImageGridPoint2=document.getElementById("imageGridPoint2"); if (!refImageGridPoint2) { return getDefaultMapImageData; }

mapData["worldGridPoints"]= [refWorldGridPoint1.firstChild.nodeValue, refWorldGridPoint2.firstChild.nodeValue]; mapData["imageGridPoints"] = [refImageGridPoint1.firstChild.nodeValue, refImageGridPoint2.firstChild.nodeValue]; return mapData; }

function getDefaultMapImageData { var mapData = new Object; mapData["imageURL"] = "http://images1.wikia.nocookie.net/__cb20100413230531/championsonline/images/5/55/Millennium_City_Full_Map.png"; mapData["worldGridPoints"]= ["1169 66 1920", "10061 198 -2712"]; mapData["imageGridPoints"] = ["374,100", "1263,564"]; return mapData; }

function getMapNotationData(notationCode, mapVersion) { if (notationCode == "circle") { var notationData = new Object; notationData["imageURL"] = "http://images2.wikia.nocookie.net/__cb20100413235557/championsonline/images/7/7e/Map_location_highlight_green_circle_30x30.png"; notationData["notationSize"] = "30,30"; return notationData; } return getMapNotationDataFromPage(notationCode); }

function getMapNotationDataFromPage(notationCode) { var refLabel=document.getElementById("refLabel" + notationCode);

//  alert("refLabel:"+refLabel+ "  refLabel.0:"+refLabel.childNodes[0]+ " refLabel.0.0:"+ refLabel.childNodes[0].childNodes[0]);

if (!refLabel) { return getDefaultNotationData; }

var refLabelLink =refLabel.childNodes[0];

if (!refLabelLink ) { return getDefaultNotationData; }

var refImage = refLabelLink.childNodes[0];

if (!refImage) { return getDefaultNotationData; }

var notationData = new Object; notationData["imageURL"] = refImage.src; notationData["notationSize"] = refImage.height + "," + refImage.width; return notationData; }

function getDefaultNotationData { var notationData = new Object; notationData["imageURL"] = "http://images2.wikia.nocookie.net/__cb20100413235557/championsonline/images/7/7e/Map_location_highlight_green_circle_30x30.png"; notationData["notationSize"] = "10,10"; return notationData; }

function getMapImageURL(mapCode, mapVersion) { var mapData = getMapImageData(mapCode, mapVersion); return mapData["imageURL"]; }

function getMapWorldGridPoints(mapCode, mapVersion) { var mapData = getMapImageData(mapCode, mapVersion); return mapData["worldGridPoints"]; }

function getMapImageGridPoints(mapCode, mapVersion) { var mapData = getMapImageData(mapCode, mapVersion); return mapData["imageGridPoints"]; }

function getMapNotationURL(notationCode, mapVersion) { var notationData = getMapNotationData(notationCode, mapVersion); return notationData["imageURL"]; }

function getMapNotationSize(notationCode, mapVersion) { var notationData = getMapNotationData(notationCode, mapVersion); return notationData["notationSize"]; }

function setParams { var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { var hash = hashes[i].split('='); var name = decodeURI(hash[0]); var value = decodeURI(hash[1]); params[name] = value; }

if (typeof(params["location"]) == "undefined") { params["location"] = decodeURI(location.search).substr(1); } if (typeof(params["map"]) == "undefined") { params["map"] = defaultMap; } if (typeof(params["mapVersion"]) == "undefined") { params["mapVersion"] = defaultMapVersion; } }

function getLocationFromSearch { var co_location = decodeURI(location.search).substr(1); return co_location; }

function getYFromLocationString(str) { var lastCommaIndex = str.lastIndexOf(","); if (lastCommaIndex > 0) { return str.substr(lastCommaIndex + 1); }

var lastSpaceIndex = str.lastIndexOf(" "); if (lastSpaceIndex > 0) { return str.substr(lastSpaceIndex + 1); } return str; }

function getXFromLocationString(str) { var firstCommaIndex = str.indexOf(","); if (firstCommaIndex > 0) { return str.substr(0, firstCommaIndex); }

var firstSpaceIndex = str.indexOf(" "); if (firstSpaceIndex > 0) { return str.substr(0, firstSpaceIndex); } return str; }

function writeAllNotations { setParams; var mapCode = params["map"]; var mapVersion = params["mapVersion"]; var notationCode = "Default";

maphtml = "";

setScale(mapCode, mapVersion); writeBackgroundMap(mapCode, mapVersion); if (params['nc']) { notationCode = params['nc']; } if (params['l']) { writeNotation(params['l'], notationCode, mapVersion); } else { writeNotation("0, 0, 0", notationCode, mapVersion); } var i = 1; while (params['l' + i] && i < 1000) { if (params['nc' + i]) { notationCode = params['nc' + i]; }   writeNotation(params['l' + i], notationCode, mapVersion); i++; } writeNotation("1169 66 1920", "circle", mapVersion); writeNotation("10061 198 -2712", "circle", mapVersion); }

function setScale(mapCode, mapVersion) { var worldGridPoints = getMapWorldGridPoints(mapCode, mapVersion); var imageGridPoints = getMapImageGridPoints(mapCode, mapVersion);

var worldGridPoint1 = worldGridPoints[0]; var imageGridPoint1 = imageGridPoints[0]; var xLocation1 = getXFromLocationString(imageGridPoint1); var yLocation1 = getYFromLocationString(imageGridPoint1); var xLocationWorld1 = getXFromLocationString(worldGridPoint1); var yLocationWorld1 = getYFromLocationString(worldGridPoint1);

var worldGridPoint2 = worldGridPoints[1]; var imageGridPoint2 = imageGridPoints[1]; var xLocation2 = getXFromLocationString(imageGridPoint2); var yLocation2 = getYFromLocationString(imageGridPoint2); var xLocationWorld2 = getXFromLocationString(worldGridPoint2); var yLocationWorld2 = getYFromLocationString(worldGridPoint2);

var xLocationAtZero = ((xLocationWorld1 * xLocation2) - (xLocationWorld2 * xLocation1)) / (xLocationWorld1 - xLocationWorld2); var yLocationAtZero = ((yLocationWorld1 * yLocation2) - (yLocationWorld2 * yLocation1)) / (yLocationWorld1 - yLocationWorld2);

worldDX = xLocationAtZero; worldDY = yLocationAtZero; if (xLocation1 != worldDX) { worldScaleX = xLocationWorld1 / (xLocation1 - worldDX); } else { worldScaleX = xLocationWorld2 / (xLocation2 - worldDX); } if (yLocation1 != worldDY)  { worldScaleY = yLocationWorld1 / (yLocation1 - worldDY); } else { worldScaleY = yLocationWorld2 / (yLocation2 - worldDY); }	}

function getScreenXFromLocationString(locationString) { var worldX = getXFromLocationString(locationString); return (worldX / worldScaleX) + worldDX; }

function getScreenYFromLocationString(locationString) { var worldY = getYFromLocationString(locationString); return (worldY / worldScaleY) + worldDY; }

function writeBackgroundMap(mapCode, mapVersion) { var mapImageURL = getMapImageURL(mapCode, mapVersion); // document.write(" "); maphtml = " "; }

function writeNotation(locationString, notationCode, mapVersion) { var mapNotationURL = getMapNotationURL(notationCode, mapVersion); var notationImageSize = getMapNotationSize(notationCode, mapVersion);

var notationImageHeight =getXFromLocationString(notationImageSize); var notationImageWidth = getYFromLocationString(notationImageSize);

var newX = getScreenXFromLocationString(locationString); newX = newX - notationImageWidth / 2 ; newX = Math.round(newX);

var newY = getScreenYFromLocationString(locationString); newY = newY - notationImageHeight / 2 ; newY = Math.round(newY);

thisLabelX = newX; thisLabelY = newY;

// document.write(" "); maphtml = maphtml + " ";

var div1 = document.createElement("div"); div1.style.position = "absolute"; div1.style.left = newX + "px"; div1.style.top = newY + "px";

var ahrf = document.createElement("a"); ahrf.href = ""; ahrf.class="image" ahrf.title= locationString;

div1.appendChild(ahrf);

var img2 = document.createElement("img"); //  img2.src = "http://images2.wikia.nocookie.net/__cb20100413235557/championsonline/images/7/7e/Map_location_highlight_green_circle_30x30.png"; img2.src = mapNotationURL; img2.name = "name"; img2.longDesc = "longDesc"; img2.alt = "alt"; ahrf.appendChild(img2);

//  var refLabel=document.getElementById("refLabel"); //  var newNode=refLabel.cloneNode(true); //  newNode.style.left = newX + "px"; // newNode.style.top = newY + "px";

var mainDiv=document.getElementById("mapDiv");

//  mainDiv.appendChild(newNode); mainDiv.appendChild(div1); }

// remove the x for ACTION //addOnloadHook(function { alert('2'); //       writeAllNotations; //        var newgrid=document.createElement("table"); //        var row = newgrid.insertRow(0); //        var cellLeft = row.insertCell(0); //        var textNode = document.createTextNode(maphtml); //        cellLeft.appendChild(textNode); //        var grid=document.getElementById("xyzxyz"); //        grid.parentNode.replaceChild(newgrid, grid); //        var mapVersion = params["mapVersion"]; //        writeNotation(params['location'], "circle", mapVersion); //        var flagA=document.getElementById("zzzaaa1"); //        flagA.style.left = thisLabelX + "px";; //        flagA.style.top = thisLabelY + "px";; //        writeNotation("1169 66 1920", "circle", mapVersion); //        var flagB=document.getElementById("zzzaaa2"); //        flagB.style.left = thisLabelX + "px";; //        flagB.style.top = thisLabelY + "px";; //       writeNotation("10061 198 -2712", "circle", mapVersion); //       var flagC=document.getElementById("zzzaaa3"); //       flagC.style.left = thisLabelX + "px";; //       flagC.style.top = thisLabelY + "px";;

//       var div1 = document.createElement("div"); //       div1.style.position = "absolute"; //       div1.style.left = "500px"; //       div1.style.top = "20px";

//       var img2 = document.createElement("img"); //       img2.src = "http://images2.wikia.nocookie.net/__cb20100413235557/championsonline/images/7/7e/Map_location_highlight_green_circle_30x30.png"; //       div1.appendChild(img2);

//       var link = document.createElement('a'); //       link.setAttribute('href', 'mypage.html');

//       var mainDiv=document.getElementById("yyyzzz");

//       div1.appendChild(link); //       mainDiv.appendChild(div1);

//       alert('end flagA:'); //	}); //