MediaWiki:Common.js

From WaterWiki.net

(Difference between revisions)
Jump to: navigation, search
Line 46: Line 46:
//markers[i].latitude =  markers[i].getElementsByClassName('latitude')[0].innerHTML;
//markers[i].latitude =  markers[i].getElementsByClassName('latitude')[0].innerHTML;
//markers[i].longitude =  markers[i].getElementsByClassName('longitude')[0].innerHTML;
//markers[i].longitude =  markers[i].getElementsByClassName('longitude')[0].innerHTML;
-
//markers[i].description = markers[i].getElementsByClassName('description')[0].innerHTML;
+
markers[i].description = markers[i].getElementsByClassName('description')[0].innerHTML;
markers[i].latitude =  getElementsByClassName(markers[i],'span','latitude')[0].innerHTML;
markers[i].latitude =  getElementsByClassName(markers[i],'span','latitude')[0].innerHTML;
markers[i].longitude =  getElementsByClassName(markers[i],'span','longitude')[0].innerHTML;
markers[i].longitude =  getElementsByClassName(markers[i],'span','longitude')[0].innerHTML;
-
markers[i].description = getElementsByClassName(markers[i],'span','description')[0].innerHTML;
+
//markers[i].description = getElementsByClassName(markers[i],'span','description')[0].innerHTML;

Revision as of 14:06, 30 September 2009

/* 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;

		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],'span','description')[0].innerHTML;

				
		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;
	}