User:Paranomia/samepageedit.js

addOnloadHook(clickevent); // This is what is loaded first function clickevent { // on doubleclick go to the change function if(wgAction == 'view' && wgNamespaceNumber != -1 && document.getElementById('ca-edit')) document.getElementById('bodyContent').addEventListener('dblclick', render, false); } function insertAfter(parent, node, referenceNode) { parent.insertBefore(node, referenceNode.nextSibling); } // function qPreview{ //	if (!divPreview) return; //	a = sajax_init_object; //	a.open('POST', wgScriptPath+'/index.php?title='+wgPageName+'&action=submit' + '&live', true); //	var Boundary = 'p1415'; //	a.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+Boundary); //	var PostData = '--' + Boundary //		+ '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' //		+ document.getElementById('editbox').value + '\n--'+Boundary; //	if (a.overrideMimeType) a.overrideMimeType('text/html'); //	a.send(PostData); //	a.onreadystatechange = function{ //		if (a.readyState != 4) return; //		var html = a.responseText; //		html = html.replace(/&gt;/g,'>').replace(/&lt;/g,'<').replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&apos;/g,"'"); //		divPreview.innerHTML = html; //	}; // } function simpleAJAXEdit(page, newtext, summary, minor, watch, callback){ xmlhttp = sajax_init_object; xmlhttp.query = { 'title': page,  'action': 'submit' } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function {  form = this.responseXML.getElementById( 'editform' );  var text = form.wpTextbox1.value;  var postData = {   'wpMinoredit': minor,   'wpWatchthis': watch,   'wpStarttime': form.wpStarttime.value,   'wpEdittime': form.wpEdittime.value,   'wpAutoSummary': form.wpAutoSummary.value,   'wpEditToken': form.wpEditToken.value,   'wpSummary': summary,   'wpTextbox1': newtext }; var xmlhttp = sajax_init_object; xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( this.query ), true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function { if(callback){ setTimeout(callback, 100); } };  xmlhttp.send( QueryString.create( postData ) ); } xmlhttp.send( null ); } function simpleAJAXGetPageContent(page){ xmlhttp = sajax_init_object; xmlhttp.query = { 'title': page, 'action': 'submit' } // if(startsum){ // document.getElementById('contentSub').innerHTML = startsum; // } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function { document.getElementById('editbox').value = this.responseXML.getElementById( 'editform' ).wpTextbox1.value } xmlhttp.send(null); } function editpage{ simpleAJAXEdit(wgPageName, document.getElementById('editbox').value, document.getElementById('summarybox').value, document.getElementById('minoreditbox').checked ? 1 : undefined, false, cancel); } function render { if(document.getElementById('bodyContent').style.display != 'none') { document.getElementById('bodyContent').style.display = 'none'; editbox = document.createElement('textarea'); editbox.setAttribute('id', 'editbox'); editbox.setAttribute('rows', '25'); editbox.setAttribute('cols', '80'); //     editbox.setAttribute('innerHTML', 'A BUG IS PRESENT, PLEASE CONTACT THE CREATOR(S) OF THIS SCRIPT. SORRY FOR THE INCONVENIENCE.'); cancelbutton = document.createElement('button'); cancelbutton.setAttribute('id', 'cancelbutton'); cancelbutton.innerHTML = 'Cancel'; cancelbutton.addEventListener('click', realcancel, false); editbutton = document.createElement('button'); editbutton.setAttribute('id', 'editbutton'); editbutton.setAttribute('accesskey', 's'); editbutton.innerHTML = 'Save edit'; editbutton.addEventListener('click', editpage, false); summarybox = document.createElement('input'); summarybox.setAttribute('id', 'summarybox'); summarybox.setAttribute('type', 'text'); summarybox.setAttribute('maxlength', '200'); summarybox.setAttribute('size', '60'); minoreditbox = document.createElement('input'); minoreditbox.setAttribute('id', 'minoreditbox'); minoreditbox.setAttribute('type', 'checkbox'); minoredittext = document.createElement('label'); minoredittext.setAttribute('for', 'minoreditbox'); minoredittext.setAttribute('accesskey', 'i'); minoredittext.setAttribute('title', 'Mark this as a minor edit [i]'); minoredittext.innerHTML = ' This is a minor edit (what'+"'"+'s this?)'; br = document.createElement('br'); // br element br2 = document.createElement('br'); // br element space = document.createElement('span'); // nbsp hack space.innerHTML = ' '; summarytext = document.createElement('p'); summarytext.innerHTML = 'Edit summary (Briefly describe the changes you have made) '; //insert the form elements document.getElementById('content').insertBefore(editbox, document.getElementById('bodyContent')); insertAfter(document.getElementById('content'), summarytext, editbox); insertAfter(document.getElementById('content'), summarybox, summarytext); insertAfter(document.getElementById('content'), br2, summarybox); insertAfter(document.getElementById('content'), minoreditbox, br2); insertAfter(document.getElementById('content'), minoredittext, minoreditbox); insertAfter(document.getElementById('content'), br, minoredittext); insertAfter(document.getElementById('content'), editbutton, br); insertAfter(document.getElementById('content'), space, editbutton); insertAfter(document.getElementById('content'), cancelbutton, space); //	divPreview = document.createElement('div'); //	divPreview.setAttribute('id', 'wikiPreview'); //	insertAfter(document.getElementById('content'), divPreview, document.getElementById('cancelbutton')); //	document.getElementById('editbox').addEventListener('keyup', qPreview, false); oldtitle = document.getElementById('content').getElementsByTagName('h1')[0].innerHTML; document.getElementById('content').getElementsByTagName('h1')[0].innerHTML = 'Editing ' + document.getElementById('content').getElementsByTagName('h1')[0].innerHTML; simpleAJAXGetPageContent(wgPageName); //	document.getElementById('editbox').addEventListener('keyup', qPreview, false); } } function cancel { window.location.reload; } function realcancel { // kill the textarea document.getElementById('content').removeChild(editbox); // kill the cancel button document.getElementById('content').removeChild(cancelbutton); // kill the save button document.getElementById('content').removeChild(editbutton); // kill the edit summary box document.getElementById('content').removeChild(summarybox); // kill the space document.getElementById('content').removeChild(space); // kill the edit summary text document.getElementById('content').removeChild(summarytext); // kill the br's   document.getElementById('content').removeChild(br); document.getElementById('content').removeChild(br2); // kill the minor edit box document.getElementById('content').removeChild(minoreditbox); // kill the text for minor edit document.getElementById('content').removeChild(minoredittext); // kill the preview // document.getElementById('content').removeChild(divPreview); // change the article name back document.getElementById('content').getElementsByTagName('h1')[0].innerHTML = oldtitle; // make the article visible document.getElementById('bodyContent').style.display = 'block'; // try this }