Jump to content

User:TheFearow/ajax.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheFearow (talk | contribs) at 22:52, 15 August 2007 (Basic framework). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// TheFearow's similair-to-ajax framework for Wikipedia

function createFrame(href){
 var frame = document.createElement('iframe');
 frame.setAttribute('src', href);
 frame.setAttribute('width', '0');
 frame.setAttribute('height', '0');
 frame.setAttribute('style', 'display:none;');
 frame.setAttribute('id', 'tfajaxframe');
 return frame;
}

function addFrame(frame){
 document.childNodes[1].appendChild(frame);
}

function getFrameDocument(){
 return document.getElementByID('tfajaxframe').contentDocument;
}

function finaliseFrame(){
 document.getElementByID('tfajaxframe') = null;
}

function getPageText(pagename){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "&action=edit");
 addFrame(frame);
 var doc = getFrameDocument();
 var content = doc.editform.wpTextbox1.value;
 finaliseFrame();
 return content;
}

function editPage(pagename, newtext, summary, minor, watch){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "&action=edit");
 addFrame(frame);
 var doc = getFrameDocument();
 doc.editform.wpTextbox1.value = newtext;
 doc.editform.wpSummary.value = summary;
 doc.editform.wpMinoredit.value = minor;
 doc.editform.wpWatchthis.value = watch;
 doc.editform.wpSave.click();
 finaliseFrame();
}