MediaWiki:Common.js

From WaterWiki.net

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/* Any JavaScript here will be loaded for all users on every page load. */
function toggleIt(id) {
    var it = document.getElementById(id);
    if (it.style.display == 'none') {
	it.style.display = 'block';
	it.style.visibility = 'visible';
    } else {
	it.style.display = 'none';
	it.style.visibility = 'hidden';
    }
}

/*Adds back to the top links*/
addOnloadHook (function () {
addTopArray = document.getElementsByTagName('span');
for (addTopCntr=0;addTopCntr<addTopArray.length;addTopCntr++)
{
if (addTopArray[addTopCntr].className == "editsection")
{
addTopArray[addTopCntr].innerHTML = addTopArray[addTopCntr].innerHTML + " [<span class='back' ><a href='#top'>top</span></a>] ";
}
}
}
);

//Properly should be served by DynamicPageList extension
function addCodeToFunction(func,code){
    if(func == undefined)
        return code;
    else{
        return function(){
            func();
            code();
        }
    }
}

function addMarkersFromMicroformats(classname) {

  var markers = getElementsByClassName(document, "div", classname);
  //var markers = document.getElementsByClassName(classname);
	
	// Loop through all event elements to extract data about each event
	for (var i=0; i < markers.length; i++) {
			
		//markers[i].latitude =  markers[i].getElementsByClassName('latitude')[0].innerHTML;
		//markers[i].longitude =  markers[i].getElementsByClassName('longitude')[0].innerHTML;
		//markers[i].description = markers[i].getElementsByClassName('description')[0].innerHTML;

                try {
		  markers[i].latitude =  getElementsByClassName(markers[i],'span','latitude')[0].innerHTML;
		  markers[i].longitude =  getElementsByClassName(markers[i],'span','longitude')[0].innerHTML;
		  markers[i].description = getElementsByClassName(markers[i],'p','description')[0].innerHTML;
                } catch(err) {

                }
				
		if (markers[i].latitude && markers[i].longitude) {
	
			var point = new GPoint(markers[i].longitude, markers[i].latitude);
			var html = markers[i].description;
			var marker = createMarker(point, html, markers[i]);
			map.addOverlay(marker);
			
			markers[i].marker = marker;
			markers[i].html = html;

			markers[i].onclick = function(){					
				var p = new GPoint(this.longitude, this.latitude); 
				map.centerAndZoom(p);
				this.marker.openInfoWindowHtml(this.html, {
					maxWidth: '300'
				});
			};
		}
	}
}

function createMarker(point, html, obj) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html, {
			maxWidth: '300'
		});
		marker.title = '';
		});
		return marker;
	}