User:Gvanhorn38/monobook.js

addOnloadHook(determinePageType);

//Make sure the page is: // 1. not special // 2. is an article // 3. is an article being viewed // 4. restrict the name space to only the Main name space (0) function determinePageType { if( wgCanonicalSpecialPageName == false && wgIsArticle == true && wgAction == "view" && wgNamespaceNumber == 0) { findKeyWord; } } //end of determinPageType

//Find a keyword in the page in order to determine whether to display Visipedia button //This function finds 'bird' for now... function findKeyWord {

// put the value of 'bird' in string var keyString = 'bird';

if (document.all){ // to detect IE	        // this variable will hold all the text on the page for IE		var txt = document.body.createTextRange; if (txt.findText(keyString)){ // if found visipedia; //execute visipedia code }	}		else{ // Netscape or Firefox or Chrome if(document.getElementsByTagName("body")[0].innerText != undefined){ if(document.getElementsByTagName("body")[0].innerText.indexOf(keyString) >= 0){ visipedia; }	   }            else if(document.getElementsByTagName("body")[0].textContent != undefined){ if(document.getElementsByTagName("body")[0].textContent.indexOf(keyString) >= 0){ visipedia; }	   }	}		}  // end function findKeyWord

//Visipedia Code //creates an iframe to embed the code function visipedia {

var newdiv=document.createElement("div"); //Cross Browser Button Creation function createButtonElement(name) { var buttonHtml = '';

var buttonFragment = document.createElement('div'); buttonFragment.innerHTML = buttonHtml; return buttonFragment.firstChild; }

//Make the "Visipedia" Button (Embedded iframe), and attach event //var startButton = createButtonElement('button'); //hookEvent(startButton,"click",startUp); //Make the "new window Visipedia" button, and attach event var newWindowButton = createButtonElement('button2'); hookEvent(newWindowButton,"click",launchWindow);

//newdiv.appendChild(startButton); //append text to new div newdiv.appendChild(newWindowButton); //append new window button document.getElementById('bodyContent').appendChild(newdiv); //append new div to another div

//Executes when the button is clicked function startUp { //Replace the button with an iframe newdiv.removeChild(startButton);

var iframe = createIframe ('iframe0', '100%', 600);

//this segment of code is used to write directly to the iframe if (iframe) { var iframeDoc; if (iframe.contentDocument) { iframeDoc = iframe.contentDocument; }			else if (iframe.contentWindow) { iframeDoc = iframe.contentWindow.document; }		else if (window.frames[iframe.name]) { iframeDoc = window.frames[iframe.name].document; }		if (iframeDoc) { //iframeDoc.open; //iframeDoc.write(			//' Grant Van Horn.<\/p><\/body><\/html>'); //iframeDoc.close; }	}   //Function to create the iframe function createIframe (iframeName, width, height) { var iframe; if (document.createElement && (iframe = document.createElement('iframe'))) { iframe.name = iframe.id = iframeName; iframe.width = width; iframe.height = height; iframe.src = 'http://vasuki.ucsd.edu/gvanhorn_working/open-mock1.php';

//Attach the iframe newdiv.appendChild(iframe);

}	return iframe; } }  //Function to launch Visipedia in a new window function launchWindow { var category = '?category=bird'; var address = 'http://vasuki.ucsd.edu/gvanhorn_working/open-mock1.php'+category; window.open(address,'Visipedia','width=800,height=800,resizable=yes,scrollbars=no,toolbar=no'); } } //end of visipedia

//Hooking Events to an element function hookEvent(element, eventName, callback) { if(typeof(element) == "string") element = document.getElementById(element); if(element == null) return; if(element.addEventListener) element.addEventListener(eventName, callback, false); else if(element.attachEvent) element.attachEvent("on" + eventName, callback); }

//Un-Hooking Events from an Element //*****Not Used Yet******** function unhookEvent(element, eventName, callback) { if(typeof(element) == "string") element = document.getElementById(element); if(element == null) return; if(element.removeEventListener) element.removeEventListener(eventName, callback, false); else if(element.detachEvent) element.detachEvent("on" + eventName, callback); }

// This function inserts newNode after referenceNode //****Not used yet****** function insertAfter( referenceNode, newNode ) {   referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling ); }