User:Rahk EX/instaedit.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Rahk EX/instaedit. |
// <source lang="JavaScript">
// This is what is loaded first
function clickevent() {
var article = document.getElementById('bodyContent');
// on doubleclick go to the change function
article.addEventListener('dblclick', change, false);
}
// Make it load!
addOnloadHook(clickevent);
// Create the insertAfter function (useful)
function insertAfter(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
function cancel() {
// kill the textarea
document.getElementById('content').removeChild(theeditbox);
// 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);
// make the article visible
document.getElementById('bodyContent').style.opacity = 1;
}
function editpage() {
frame = document.createElement("IFRAME");
frame.setAttribute('src', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wgPageName + '&action=edit');
frame.setAttribute('height', '1');
frame.setAttribute('width', '1');
document.body.appendChild(frame);
// Below line may be useful, commented for now
// e = frame.contentDocument;
document.all.wpTextbox1.innerHTML = document.getElementById('editbox').innerHTML;
document.getElementById('wpSummary').value = document.getElementById('summarybox').value; // added summarybox
document.getElementById('wpSave').click();
cancel();
}
// Create the change function that is called when the article is double-clicked
function change() {
if(document.getElementById('bodyContent').style.opacity != 0.2) {
document.getElementById('bodyContent').style.opacity = 0.2;
theeditbox = document.createElement('textarea');
theeditbox.setAttribute('id', 'editbox');
theeditbox.setAttribute('rows', '25');
theeditbox.setAttribute('cols', '80');
theeditbox.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', cancel, false);
editbutton = document.createElement('button');
editbutton.setAttribute('id', 'editbutton');
editbutton.setAttribute('accesskey', 's');
editbutton.innerHTML = '<b>Save edit</b>';
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 (<a href="/wiki/Help:Minor_edit" title="Help:Minor edit">what'+"'"+'s this?</a>)';
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 = '<a href="/wiki/Help:Edit_summary" class="internal" title="Briefly describe the changes you have made" target="_blank">Edit summary</a> <small>(Briefly describe the changes you have made)</small>';
//insert the form elements
document.getElementById('content').insertBefore(theeditbox, document.getElementById('bodyContent'));
insertAfter(document.getElementById('content'), summarytext, theeditbox);
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);
a=sajax_init_object();
var request = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wgPageName + '&action=raw'; // helps debugging
a.open("GET", request, true);
a.onreadystatechange = function(){
if(a.readyState == 4){
document.getElementById('editbox').innerHTML = a.responseText;
}
}
a.send(null);
}
}
// </source>