Jump to content

MediaWiki:GeoHack.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Redrose64 (talk | contribs) at 18:01, 9 June 2014 (update link from toolserver to labs). 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.
/* 
 * The file is used by [[tswiki:GeoHack]] and applies effects to [[Template:GeoTemplate]].
 */
 
/* basic function library */
function appendCSS(text) {
	var s = document.createElement('style');
	s.type = 'text/css';
	s.rel = 'stylesheet';
	if (s.styleSheet) s.styleSheet.cssText = text //IE
	else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null
	document.getElementsByTagName('head')[0].appendChild(s);
}

/* Click tracker to see which services are most used */
var tracker = "//toolserver.org/~dispenser/ghct";
function addTrackers(){
	var anchors = document.getElementById('mw_content').getElementsByTagName('A');
	for(var i=0; anchors[i]!=null; i++){
		anchors[i].onmousedown = function(){if(document.images){(new Image).src=[tracker,'/',(this.textContent||this.innerText||"NA").replace(/\W/g,'').toLowerCase(),'/',this.href.replace(/[\w+]+:\/*([0-9A-Za-z.\-]*).*/,"$1")].join("");return true;};
		}
	}
}

/* Allow draggable maps to be used */
var iframeurl = '//wma.wmflabs.org/iframe.html';
var wma_class_R = /\bWMA:(\S+)/;
function addWikiMiniAtlas() {
	var arrElements = document.getElementById('mw_content').getElementsByTagName('DIV');
	var mapparams, container;
	for(var i=0; (container=arrElements[i]); i++){
		mapparams = container.className.match(wma_class_R);
		if(mapparams){
			iframe = document.createElement('iframe');
			iframe.frameBorder = 0;
			iframe.scrolling = 'no';
			iframe.src = iframeurl + '?' + mapparams[1];
			iframe.style.width = mapparams[1].split('_')[2]+'px';
			iframe.style.height = mapparams[1].split('_')[3]+'px';
			while(container.firstChild)
				container.removeChild(container.firstChild);
			container.appendChild(iframe); // set attributes before insertion - IE6
			container.style.display = '';
		}
	}
}

window.onload = function() {
	/* Add row hover effect */
	appendCSS(".directory tr:hover {background:#fdc !important;}");
    addTrackers();
	addWikiMiniAtlas(); 
}