User:Ale jrb/Scripts/WikiNotes/wikinotes.js

/* =========================================================== *\ \* =========================================================== */
 * WikiNotes JavaScript note making program.                  **
 * Copyright (c) Alex Barley  2008.                  **
 * Licensed under the GNU Free Documentation License, Version **
 * 1.2 or later.                                              **
 * You copy, modify or distribute this script entirely at your **
 * own risk. No warranty is offered, of any kind. I accept no **
 * responsibility for any damage caused by your use of this   **
 * script in any medium.                                      **
 * WikiNotes - start main code. Do not edit below this line.  **
 * script in any medium.                                      **
 * WikiNotes - start main code. Do not edit below this line.  **
 * WikiNotes - start main code. Do not edit below this line.  **
 * WikiNotes - start main code. Do not edit below this line.  **
 * WikiNotes - start main code. Do not edit below this line.  **

var setup_wikiUrl 		= 'http://wiki.guildwars.com';

/* =========================================================== *\ \* =========================================================== */ function enforceContentChange(content) { document.getElementById('content').innerHTML = content; setTimeout('enforceContentChange(\''+content+'\')', 200); return false; } function wikiNotesLoad { function forbiddenPage(url) { var forbiddenPages = new Array(									  		'action=history',											'action=edit',											'&diff=',											'Special:',											'Main_Page',											'User:Ale_jrb/Scripts/WikiNotes',											/*'.php',*/											'.js',											'.css'									   ) for (var i = 0; i < forbiddenPages.length; i ++) { if (  url.indexOf(forbiddenPages[i]) > -1   ) { return true; } }		return false; }	// Check if Wikinotes is installed on this page. var pageHTML 		= document.body.innerHTML; if ((window.location.href).indexOf('edit=disabled') == -1) { // Under some circumstances, it shouldn't be an option. Here's where you disable pages. if (forbiddenPage(window.location.href) == false) { if (document.getElementById('wikinotes_notepad') != null) { // It's installed. Check if we should be uninstalling it. var checkUrl = setup_wikiUrl + '/wiki/' var url = location.href; if (url.indexOf(checkUrl) != -1) { wikipage = url.substring(checkUrl.length); }				else {					wikipage = url.substring(setup_wikiUrl.length + 17); if (wikipage.indexOf('&') > -1) wikipage = wikipage.substring(0, wikipage.indexOf('&')); }				if (location.href.indexOf('notes=uninstall') > -1) { ajaxGetWikiContents(wikipage, 'unins'); pageHTML = pageHTML.replace('accesskey="e">Edit', 'accesskey="e">Edit\ndeactivating notepad...'); }				else {					pageHTML = pageHTML.replace('accesskey="e">Edit', 'accesskey="e">Editing Disabled\ndeactivate notepad</li>'); pageHTML = pageHTML.replace('action=edit" title="You can edit this page. Please use the preview button before saving.', 'edit=disabled" title="Editing is disabled on this page to protect the integrity of the notepad.'); }							document.body.innerHTML = pageHTML; // Actually run Notes! controls.panel; restore.init; }			else {				// It's not installed. Check if we should be installing it. var checkUrl = setup_wikiUrl + '/wiki/' var url = location.href; if (url.indexOf(checkUrl) != -1) { wikipage = url.substring(checkUrl.length); }				else {					wikipage = url.substring(setup_wikiUrl.length + 17); if (wikipage.indexOf('&') > -1) wikipage = wikipage.substring(0, wikipage.indexOf('&')); }				if (location.href.indexOf('notes=install') > -1) { if ((wgTitle.substring(0, wgTitle.indexOf('/')) == wgUserName) || (wgTitle.substring(0, wgTitle.length) == wgUserName)) { ajaxGetWikiContents(wikipage, 'ins'); pageHTML = pageHTML.replace('accesskey="e">Edit</a></li>', 'accesskey="e">Edit</a></li>\n<a href="/index.php?title='+wikipage+'&amp;notes=install">activating notepad...</a></li>'); }					else {						enforceContentChange(' </a><h1 class="firstHeading">Activation Failed - <a href="http://guildwars.com/wiki/User:Ale_jrb/Scripts/WikiNotes">WikiNotes</a> You are unable to automatically generate notepads on pages that are not part of your userspace. To use WikiNotes on other pages, the page owner should first activate the notepad. '); }				}				else {					pageHTML = pageHTML.replace('accesskey="e">Edit</a></li>', 'accesskey="e">Edit</a></li>\n<a href="/index.php?title='+wikipage+'&amp;notes=install">activate notepad</a></li>'); }								document.body.innerHTML = pageHTML; }		}	}	else {		document.getElementById('content').innerHTML = ' </a><h1 class="firstHeading">Editing Disabled - <a href="http://guildwars.com/wiki/User:Ale_jrb/Scripts/WikiNotes">WikiNotes</a> To protect the integrity of the notepad, access to the editing page has been restricted. WikiNotes generates a lot of complicated HTML automatically, and this is easy to corrupt, rendering the notepad unusable.
 * INITIALISATION FUNCTIONS                              **

If you are confident about your ability to edit the page, or need to blank/otherwise alter it, you can do so by clicking <a href="'+wgServer+'/index.php?title='+wgPageName+'&action=edit">here</a>, or selecting the reactivated edit link above. ';	} }

function wikiNotesInstallChange(mode, content) { switch (mode) { case 'install': var newContent = '<div id="wikinotes_notepad">'+content+' '; ajaxPrep(newContent, 'TEST: Activating WikiNotes Notepad', 'redirect') break; case 'uninstall': controls.changed = false; var newContent = content; newContent = newContent.substring(newContent.indexOf('<div id="wikinotes_notepad">') + 28); newContent = ' '+newContent; newContent = newContent.replace('<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;"> Careful! This notepad has changed since it was last saved. Don\'t forget to save before browsing away. ', ''); ajaxPrep(newContent, 'TEST: Deactivating WikiNotes Notepad', 'redirect') break; } }

var restore={ init:function { // Locate all notes. var notes = document.getElementsByTagName('div'); for (var i = 0; i < notes.length; i ++) { if ((notes[i].className == 'wikinotes_note') && (notes[i].id != 'cpanel186354')) { var thisNote = notes[i]; var contents = ''; for (var j = 0; j < thisNote.childNodes[0].childNodes[1].childNodes.length; j ++) { if (thisNote.childNodes[0].childNodes[1].childNodes[j].nodeValue == null) { contents += "\n"; }					else {						contents += thisNote.childNodes[0].childNodes[1].childNodes[j].nodeValue; }				}				var newnote = new notepad; newnote.init(thisNote.id, contents, false); }		}	} }

/* =========================================================== *\ \* =========================================================== */ var managePage={ appendTagline:function { var tag = '<div id="wikinotes_tagline" style="position: absolute; top: 40px; left: 13px; background: #ffffff; font-size: 0.9em;">Powered by WikiNotes '; if ((document.getElementById('wikinotes_tagline') != null) && (document.getElementById('wikinotes_tagline').innerHTML != 'Powered by <a href="/wiki/User:Ale_jrb/Scripts/WikiNotes" title="User:Ale jrb/Scripts/WikiNotes">WikiNotes</a>')) { document.getElementById('wikinotes_tagline').parentNode.removeChild(document.getElementById('wikinotes_tagline')); }		return tag; } }
 * PAGE MANAGEMENT FUNCTIONS                             **

/* =========================================================== *\ \* =========================================================== */ var controls={ changed: false, browsewarn: false, panel:function { if (document.getElementById('wikinotes_notepad') == null) { return false; } controller = this.create('default', 'cpanel186354'); return controller; },	create:function(mode, id, divtitle) { switch (mode) { case 'default': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += '<div class="content_area" style="position: relative; text-align: right; top: 3px; right: 5px;">WikiNotes '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.savePage; controls.changed = false; controls.setMode(\'saving\', \'cpanel186354\'); return false;">Save Page '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 1px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:if (controls.browsewarning == true) { controls.browsewarning = false } else { controls.browsewarning = true } controls.setMode(\'default\', \'cpanel186354\'); return false;">Help &amp; About '; temp += '<div style="cursor: pointer; position: relative; float: left; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.setMode(\'edit\', \'cpanel186354\'); return false;">Create a New Note! ';				temp += ' '; // End main header code // Start warnings if 	(this.changed == true) { temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;"> Careful! This notepad has changed since it was last saved. Don\'t forget to save before browsing away. ';				}				if 	(this.browsewarning == true) { temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;"> This action will take you to a new page! When you have saved any changes, click <a href="'+setup_wikiUrl+'/wiki/User:Ale_jrb/Scripts/WikiNotes">here</a>. ';				}				// End warnings // Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; case 'edit': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += ' Editing a Note - WikiNotes '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:var newnote = new notepad; newnote.init(document.getElementById(\'title\').value, document.getElementById(\'text\').value, false); controls.changed = true; controls.setMode(\'default\', \'cpanel186354\'); return false;">Save Note '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 1px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.setMode(\'default\', \'cpanel186354\'); return false;">Cancel '; //temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 2px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.browsewarning = true; controls.setMode(\'default\', \'cpanel186354\'); return false;">Help '; temp += ' '; // End main header code // Start main edit code temp += '<div class="content_area" style="font-family: arial; font-size: 11px; padding: 3px; padding-top: 10px;">'; temp += 'Title: <input type="text" id="title" style="font-size: 11px; padding: 1px; background-color: #0099FF; border: 1px solid #000066;" size="50" />
 * NOTEPAD MANAGEMENT FUNCTIONS                          **

';				temp += 'Note: <textarea id="text" style="width: 486px; font-family: arial; font-size: 11px; background-color: #0099FF; border: 1px solid #000066; padding: 3px;" rows="5"> '; temp += ' '; // End main edit code // Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; case 'saving': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += '<div class="content_area" style="position: relative; text-align: right; top: 3px; right: 5px;">Saving NotePad - Please Wait - WikiNotes '; temp += ' '; // End main header code temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;">WikiNotes is saving your NotePad. This process may take some time, but interupting it may corrupt data. Please be patient. ';

// Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; }		temp += "\n\n "; this.controlpanel = new notepad; this.controlpanel.init('cpanel186354', temp, true); return this.controlpanel; },	setMode:function(mode, id, divtitle) { switch (mode) { case 'default': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += '<div class="content_area" style="position: relative; text-align: right; top: 3px; right: 5px;">WikiNotes '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.savePage; controls.changed = false; controls.setMode(\'saving\', \'cpanel186354\'); return false;">Save Page '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 1px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:if (controls.browsewarning == true) { controls.browsewarning = false } else { controls.browsewarning = true } controls.setMode(\'default\', \'cpanel186354\'); return false;">Help &amp; About '; temp += '<div style="cursor: pointer; position: relative; float: left; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.setMode(\'edit\', \'cpanel186354\'); return false;">Create a New Note! ';				temp += ' '; // End main header code // Start warnings if 	(this.changed == true) { temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;"> Careful! This notepad has changed since it was last saved. Don\'t forget to save before browsing away. ';				}				if 	(this.browsewarning == true) { temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;"> This action will take you to a new page! When you have saved any changes, click <a href="'+setup_wikiUrl+'/wiki/User:Ale_jrb/Scripts/WikiNotes">here</a>. ';				}				// End warnings // Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; case 'edit': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += ' Editing a Note - WikiNotes '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:var newnote = new notepad; newnote.init(document.getElementById(\'title\').value, document.getElementById(\'text\').value, false); controls.changed = true; controls.setMode(\'default\', \'cpanel186354\'); return false;">Save Note '; temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 1px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.setMode(\'default\', \'cpanel186354\'); return false;">Cancel '; //temp += '<div style="cursor: pointer; position: relative; float: right; top:9px; left: 2px; border: 1px solid #0000FF; padding: 0px 2px 0px 2px; font-family: arial; font-size: 10px;"><span onclick="javascript:controls.browsewarning = true; controls.setMode(\'default\', \'cpanel186354\'); return false;">Help '; temp += ' '; // End main header code // Start main edit code temp += '<div class="content_area" style="font-family: arial; font-size: 11px; padding: 3px; padding-top: 10px;">'; temp += 'Title: <input type="text" id="title" style="font-size: 11px; padding: 1px; background-color: #0099FF; border: 1px solid #000066;" size="50" />

';				temp += 'Note: <textarea id="text" style="width: 486px; font-family: arial; font-size: 11px; background-color: #0099FF; border: 1px solid #000066; padding: 3px;" rows="5"> '; temp += ' '; // Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; case 'saving': var temp = ''; // Start main header code temp += '<div id="cntrl-main" style="z-index: 1000000000; cursor: move; position: absolute; left: 10px; top: 10px; width: 500px; background-color: #66CCFF; border: 1px solid #000066; padding: 2px;">'; temp += '<div class="drag_controller" style="position: relative; background-color: #0099FF; border-bottom: 1px solid #0000FF; height: 48px; padding-right: 0px; font-family: arial; font-weight: bold;">'; temp += '<div class="content_area" style="position: relative; text-align: right; top: 3px; right: 5px;">Saving NotePad - Please Wait - WikiNotes '; temp += ' '; // End main header code temp += '<div style="position: relative; top: 3px; padding-bottom: 3px; text-align: center; font-family: arial; font-size: 12px;">WikiNotes is saving your NotePad. This process may take some time, but interupting it may corrupt data. Please be patient. ';

// Start end all temp += ' <div class="resize_controller" style="background-color: #000000; width:0px; height:0px;"> <div class="close_note" style="background-color: #000000; width:0px; height:0px;"> '; // End end all break; }		temp += "\n\n "; this.controlpanel.init('cpanel186354', temp, true); return this.controlpanel; },	setEditBox: function (title, content) { // Clean up the content. title = cleanContent(title, 'forEdit'); content = cleanContent(content, 'forEdit'); document.getElementById('title').value = title; document.getElementById('text').value = content; },	destroyNote: function (id) { var note = document.getElementById(id); note.parentNode.removeChild(note); },	refreshNote: function (id, content) { var refresher = new notepad; refresher.init(id, content, false, true); return false; }, 	savePage: function { var tag = managePage.appendTagline; var currentContent = document.getElementById('wikinotes_notepad'); currentContent = currentContent.innerHTML; currentContent = '<div id="wikinotes_notepad">' + currentContent + ''; currentContent += tag; currentContent += ' '; currentContent = wikifyHrefLinks(currentContent); currentContent = currentContent.replace('<div id="wikinotes_tagline" style="background: rgb(255, 255, 255) none repeat scroll 0% 0%; position: absolute; top: 40px; left: 13px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-size: 0.9em;">Powered by <a href="/wiki/User:Ale_jrb/Scripts/WikiNotes" title="User:Ale jrb/Scripts/WikiNotes">WikiNotes</a> ', ''); ajaxPrep(currentContent, 'Saving WikiNotes notepad'); } }

function notepad { // Notepad class. // This is the notepad class - it handles creating and managing notes. // If this page doesn't have Notes installed, never run anything. if (document.getElementById('wikinotes_notepad') == null) { return false; } /* public function init ( id as string, content as string, overwrite as boolean ) */ this.init = function (t, input, overwrite, ref) { if (document.getElementById(t) == null) {				this.create(t, input, overwrite) }			else {				this.update(t, input, overwrite, ref) }		}		this.create = function (t, input, overwrite) { // If you specify 'overwrite' as 'true', a div named 'drag_controller' should be in the // content. inputn = cleanContent(input, 'forSaving'); t = cleanContent(t, 'forSaving');

if (document.getElementById(t) == null) {					var domwindow           = document.createElement("div"); var title               = t;					domwindow.id             = t;					domwindow.className      = "wikinotes_note"; domwindow.style.position = "absolute"; if (overwrite == true) { var domwindowdata =' '; domwindowdata += input; domwindowdata += ''; domwindow.innerHTML = domwindowdata; document.getElementById("wikinotes_notepad").appendChild(domwindow) }					else {						var domwindowdata = '<div style="border: 1px solid #000000; min-width: 100px; max-width: 500px; -moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px;">' domwindowdata += ''; domwindowdata += '<div class="drag_controller" ondblclick="javascript:controls.refreshNote(\+title+'\', \+inputn+'\')" style="cursor: move; position: relative; height:20px; width:inherit; overflow: hidden; background-color:#BBBBBB;font-family:arial;font-size:16px;font-weight:bold;padding:1px 10px 1px 3px;">' + cleanContent(title, 'forDisplay') + ''; domwindowdata += '<div class="close_note" style="background-color: #BBBBBB; position: absolute; top: 1px; right: 5px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.destroyNote(\'' + title + '\'); return false;">x ] '; domwindowdata += '<div class="edit_note" style="background-color:#BBBBBB; position: absolute; top: 1px; right: 25px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.setMode(\'edit\',\'wiki-controls\'); controls.setEditBox(\+title+'\', \+inputn+'\'); return false;"> \\ ] '; domwindowdata += '<div class="btf_note" style="background-color: #BBBBBB; position: absolute; top: 1px; right: 47px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.refreshNote(\+title+'\', \+inputn+'\'); return false;"> ^ ] '; domwindowdata += ' '; domwindowdata += '<div class="content_area" style="min-height: 10px; max-height: 2000px; width:inherit; overflow: hidden; position:relative; background-color:#EEEEEE;padding:3px; -moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px;font-family:arial;font-size:10px;">' + cleanContent(inputn, 'forDisplay') + '<div class="resize_controller" style="cursor: se-resize; position: absolute; bottom:0px; right: 0px; height:10px; width:10px;"> '; domwindowdata += ' '; domwindow.innerHTML=domwindowdata document.getElementById("wikinotes_notepad").appendChild(domwindow) }					var t = document.getElementById(t); var divs = t.getElementsByTagName("div") var divs = t.getElementsByTagName("div") for (var i = 0; i < divs.length; i++) { t[divs[i].className] = divs[i]; }					// Move to front on create var y = document.body; var divs = y.getElementsByTagName("div") this.zIndexValue = 0; for (var i = 0; i < divs.length; i++) { if ((divs[i].style.zIndex > this.zIndexValue) && ((divs[i].id != 'cntrl-main') && (divs[i].id != 'cpanel186354') && (divs[i].id != ''))) { this.zIndexValue = parseInt(divs[i].style.zIndex); } }					t.style.zIndex = this.zIndexValue + 1; if (t.id == 'cpanel186354') t.style.zIndex = 999999999; t.drag_controller._parent = t;					t.drag_controller.onmousedown = this.drag; t.resize_controller._parent = t;					t.resize_controller.onmousedown = this.drag; }		}		this.update = function(t, input, overwrite, ref) { inputn = cleanContent(input, 'forSaving'); t = cleanContent(t, 'forSaving'); if (document.getElementById(t) != null) {

var note      = document.getElementById(t); var divs = note.getElementsByTagName("div") for (var i = 0; i < divs.length; i++) { note[divs[i].className] = divs[i]; }				var newcontent = input; var title     = t;				var tempin     = ''; var oldheight = note.content_area.style.height; if (overwrite == true) { tempin = newcontent; }				else {					tempin = ''; tempin += '<div style="border: 1px solid #000000; min-width: 100px; max-width: 500px; -moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px;">'; tempin += '<div class="drag_controller" ondblclick="javascript:controls.refreshNote(\+title+'\', \+inputn+'\')" style="cursor: move; position: relative; height:20px; width:inherit; overflow: hidden; background-color:#BBBBBB;font-family:arial;font-size:16px;font-weight:bold;padding:1px 10px 1px 3px;">' + cleanContent(title, 'forDisplay') + ''; tempin += '<div class="close_note" style="background-color: #BBBBBB; position: absolute; top: 1px; right: 5px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.destroyNote(\ + title + '\'); return false;">x ] <div class="edit_note" style="background-color:#BBBBBB; position: absolute; top: 1px; right: 25px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.setMode(\'edit\',\'wiki-controls\'); controls.setEditBox(\+title+'\', \''+inputn+'\'); return false;"> \\ ] '; tempin += '<div class="btf_note" style="background-color: #BBBBBB; position: absolute; top: 1px; right: 47px;">[<span style="cursor: default; text-decoration: none; color: #444444;" onmouseover="javascript:this.style.color = \'#999999\';" onmouseout="javascript:this.style.color = \'#444444\';" onclick="javascript:controls.refreshNote(\+title+'\', \+inputn+'\'); return false;"> ^ ] '; tempin += '<div class="content_area" style="min-height: 10px; max-height: 2000px; width:inherit; overflow: hidden; position:relative; background-color:#EEEEEE;padding:3px; -moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px;font-family:arial;font-size:10px;">' + cleanContent(inputn, 'forDisplay') + '<div class="resize_controller" style="cursor: se-resize; position: absolute; bottom:0px; right: 0px; height:10px; width:10px;"> '; tempin += ' ' tempin += ''; }				note.innerHTML = tempin; var divs = note.getElementsByTagName("div") for (var i = 0; i < divs.length; i++) { note[divs[i].className] = divs[i]; }				note.content_area.style.height = oldheight; t = document.getElementById(t); var divs = t.getElementsByTagName("div") for (var i = 0; i < divs.length; i++) { t[divs[i].className] = divs[i]; }				// Move to front on refresh? if (ref == true) { var y = document.body; var divs = y.getElementsByTagName("div") this.zIndexValue = 0; for (var i = 0; i < divs.length; i++) { if ((divs[i].style.zIndex > this.zIndexValue) && ((divs[i].id != 'cntrl-main') && (divs[i].id != 'cpanel186354') && (divs[i].id != ''))) { this.zIndexValue = parseInt(divs[i].style.zIndex); } }					t.style.zIndex = this.zIndexValue + 1; if (t.id == 'cpanel186354') t.style.zIndex = 999999999; }				t.drag_controller._parent = t;				t.drag_controller.onmousedown = this.drag; t.resize_controller._parent = t;				t.resize_controller.onmousedown = this.drag; }			}		/* public function drag ( event as window.event) */ this.drag = function (e) { var n = this; var p = this._parent; // Function is called by the drag div (so 'this' = that div) and parent is the whole content div. // If this is a normal note, we want to refresh it (bring it to top) if that mode is // enabled and it ISN'T the control panel. var divs = p.getElementsByTagName("div") for (var i = 0; i < divs.length; i++) { p[divs[i].className] = divs[i]; }			var id = p.id; var content = p.content_area.innerHTML; content = content.substring(0, content.indexOf('<div class="resize_controller"')); var e = window.event || e; // If e is set, use that, otherwise get the current event. n.initmousex = e.clientX // clientX is the mouseposition. n.initmousex now = the position where the mouse was clicked. n.initmousey = e.clientY n.initx = parseInt(p.offsetLeft) // offsetLeft is the div position of p (the holder div). n.initx now = the position where the div started when the mouse was clicked. n.inity = parseInt(p.offsetTop) n.width = parseInt(p.offsetWidth) // offsetWidth is the width of the div. n.width now = the starting width of the div (handy for resizing the note). n.cheight = parseInt(p.content_area.offsetHeight) // p.content_area is the inner div that contains the content. cheight now = the content height. document.onmousemove = getMoved; // Do the actual moving. document.onmouseup = doStop; function getMoved (e) { var e = window.event || e;						n.distancex = e.clientX - n.initmousex; n.distancey = e.clientY - n.initmousey; if (n.className == "drag_controller") { doMove(n.distancex, n.distancey); }						if (n.className == "resize_controller") { doSize(n.distancex, n.distancey); }						return false; }					function doMove (x, y) { p.style.left = x + n.initx + "px"; p.style.top = y + n.inity + "px"; return false; }					function doSize (x, y){ p.style.width              = Math.min(Math.max(n.width + x, 100), 500) + "px"; p.content_area.style.height = Math.min(Math.max(n.cheight + y, 10), 2000) + "px"; }					function doStop { var o = document.getElementById('outputdivver'); //o.innerHTML += 'Stopped'; document.onmousemove = null; document.onmouseup = null; return false; }		return false; } }

function wikifyHrefLinks(code) { // This mini function uses a regex to tranform the wiki-generated 'a href' links back into Wiki links. This lets us save them without totally destroying other page content or layouts. var regex = /<a href="\/wiki\/.+" title="(.+)">(.+)<\/a>/g; var matches = regex.exec(code); var j = 0; var wikifiedLink = new Array; if (matches != null) { for (var i = 0; i < matches.length; i += 3) { wikifiedLink[j] = + matches[i + 2] +; j ++; }		for (var k = 0; k < wikifiedLink.length; k ++) { code = code.replace(/<a href="\/wiki\/.+" title=".+">.+<\/a>/, wikifiedLink[k]); }	}	return code; }

function cleanContent(content, mode) { switch (mode) { // forEdit converts the saved machine-friendly code to human readable code for the edit box. case 'forEdit': content = content.replace(/::001::/g, '\n'); content = content.replace(/::002::/g, '<'); content = content.replace(/::003::/g, '>'); content = content.replace(/::004::/g, '\''); content = content.replace(/::005::/g, '"');			content = content.replace(/::006::/g, '[');			content = content.replace(/::007::/g, ']');			content = content.replace(/::008::/g, '#');			content = content.replace(/::009::/g, '!');			content = content.replace(/::010::/g, '?');			content = content.replace(/::011::/g, '\\');			content = content.replace(/::012::/g, '/');			content = content.replace(/::013::/g, '|');			content = content.replace(/::014::/g, '+');			content = content.replace(/::015::/g, '{');			content = content.replace(/::016::/g, '}');			content = content.replace(/::017::/g, '(');			content = content.replace(/::018::/g, ')');			break;		// forSaving converts human readable edit code to machine-friendly code to be wiki-saved.		case 'forSaving':			content = content.replace(/\n/g, '::001::');			content = content.replace(/</g, '::002::');			content = content.replace(/>/g, '::003::'); content = content.replace(/'/g, '::004::'); content = content.replace(/"/g, '::005::');			content = content.replace(/\[/g, '::006::');			content = content.replace(/\]/g, '::007::');			content = content.replace(/#/g, '::008::');			content = content.replace(/!/g, '::009::');			content = content.replace(/\?/g, '::010::');			content = content.replace(/\\/g, '::011::');			content = content.replace(/\//g, '::012::');			content = content.replace(/\|/g, '::013::');			content = content.replace(/\+/g, '::014::');			content = content.replace(/\{/g, '::015::');			content = content.replace(/\}/g, '::016::');			content = content.replace(/\(/g, '::017::');			content = content.replace(/\)/g, '::018::');			break;		// forDisplay simply returns the HTML that the saved code refers to. It is never saved; it is simply altered into the display code on-the-fly.		case 'forDisplay':			content = content.replace(/::001::/g, ' ');			content = content.replace(/::002::/g, '&lt;'); content = content.replace(/::003::/g, '&gt;'); content = content.replace(/::004::/g, '\''); content = content.replace(/::005::/g, '"');			content = content.replace(/::006::/g, '[');			content = content.replace(/::007::/g, ']');			content = content.replace(/::008::/g, '#');			content = content.replace(/::009::/g, '!');			content = content.replace(/::010::/g, '?');			content = content.replace(/::011::/g, '\\');			content = content.replace(/::012::/g, '/');			content = content.replace(/::013::/g, '|');			content = content.replace(/::014::/g, '+');			content = content.replace(/::015::/g, '{');			content = content.replace(/::016::/g, '}');			content = content.replace(/::017::/g, '(');			content = content.replace(/::018::/g, ')');			break;	}	return content; }

/* =========================================================== *\ \* =========================================================== */ function ajaxPrep(currentContent, summary, flags) { var page_request = false; if (window.XMLHttpRequest) page_request = new XMLHttpRequest; else if (window.ActiveXObject){ try { page_request = new ActiveXObject("Msxml2.XMLHTTP"); } 		catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP"); }			catch (e){} }	}	else {		return false; }	var url = window.location.href; var wikipage = wgPageName; var useurl = setup_wikiUrl + '/index.php?action=edit&title=' + wikipage; page_request.onreadystatechange = function { if (page_request.readyState == 4) { if (page_request.status == 200) { var editpage = page_request.responseXML; ajaxSave(editpage, currentContent, wikipage, summary, flags); } else { alert('AJAX: There was a problem with the HTTP request, code received: ' + page_request.status); return false; }		 }	}	page_request.overrideMimeType('text/xml'); page_request.open('GET', useurl, true); page_request.send(null); }
 * AJAX HANDLING FUNCTIONS                               **

function ajaxGetWikiContents(wikipage, installing) { var url = setup_wikiUrl + '/index.php?title='+wikipage+'&action=edit'; var page_request = false; if (window.XMLHttpRequest) page_request = new XMLHttpRequest; else if (window.ActiveXObject){ try { page_request = new ActiveXObject("Msxml2.XMLHTTP"); } 		catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP"); }			catch (e){} }	}	else {		return false; }	page_request.onreadystatechange = function { if (page_request.readyState == 4) { if (page_request.status == 200) { var resxml = page_request.responseXML; var obj = resxml.getElementById('wpTextbox1'); if (installing == 'ins') { wikiNotesInstallChange('install', obj.value); }				else if (installing == 'unins') { wikiNotesInstallChange('uninstall', obj.value); }				else {					return (obj.value); }			 } else { alert('AJAX: There was a problem with the HTTP request, code received: ' + page_request.status); return false; }		 }	}	page_request.overrideMimeType('text/xml'); page_request.open('GET', url, true); page_request.send(null); }

function ajaxSave(contents, newcontents, wikipage, summary, flags) { var editpage = contents.getElementById('editform'); var input   = newcontents; if (flags == null) flags = ''; var starttime	= editpage.wpStarttime.value; var edittime	= editpage.wpEdittime.value; var edittoken	= editpage.wpEditToken.value; var autosum		= editpage.wpAutoSummary.value; var wpSection    = ''; var wpStarttime  = starttime; var wpEdittime   = edittime; var wpScrolltop  = ''; var wpTextbox1   = newcontents; var wpSummary    = summary; var wpMinoredit  = 0; var wpAutoSummary = autosum; var wpEditToken  = edittoken; wpTextbox1 = escape(wpTextbox1); wpEditToken = encodeURIComponent(wpEditToken); var postTo = setup_wikiUrl + '/index.php?action=submit&title=' + wikipage; var params = 'wpSection=' + encodeURI(wpSection) + '&wpStarttime=' + encodeURI(wpStarttime) + '&wpEdittime=' + encodeURI(wpEdittime) + '&wpScrolltop=' + encodeURI(wpScrolltop) + '&wpTextbox1=' + wpTextbox1 + '&wpSummary=' + encodeURI(wpSummary) + '&wpMinoredit=' + encodeURI(wpMinoredit) + '&wpEditToken=' + wpEditToken + '&wpAutoSummary=' + wpAutoSummary; page_request2 = false; if (window.XMLHttpRequest) page_request2 = new XMLHttpRequest; else if (window.ActiveXObject){ try { page_request2 = new ActiveXObject("Msxml2.XMLHTTP"); } 		catch (e){ try{ page_request2 = new ActiveXObject("Microsoft.XMLHTTP"); }			catch (e){} }	}	else {		return false; }	page_request2.onreadystatechange = function { if (page_request2.readyState == 4) { if (page_request2.status == 200) { //document.getElementById('outputending').innerHTML = page_request2.responseText; if (flags.indexOf('redirect') > -1) { window.location = window.location.href; }				if (document.getElementById('cpanel186354') != null) { controls.setMode('default', 'cpanel186354'); }				//var page2 = page_request2.responseText; //page2 = page2.replace(/</g, "&lt;"); //page2 = page2.replace(/>/g, "&gt;"); //document.body.innerHTML = page2; } 			else {				alert('AJAX: There was a problem with the HTTP request, code received: ' + page_request2.status); return false; }		}	}	page_request2.open('POST', postTo, true); page_request2.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); page_request2.setRequestHeader("Content-length", params.length); page_request2.setRequestHeader("Connection", "close"); page_request2.send(params); }

/* =========================================================== *\ \* =========================================================== */ hookEvent('load', wikiNotesLoad);
 * RUN PROGRAM                                           **