User:Jorgenev/AJAXSectionEditor.js

var editing=false; var edittoken = null; var PageName = null; function cancel {   var element = document.getElementById("editing1"); element.parentNode.removeChild(element); editing = false; }

function save(section) { section+=1 $.ajax({       url: wgScriptPath + '/api.php',        data: {            'action': 'edit',            'title': PageName,            'section': section,            'summary': document.getElementById("editsummary1").value,            'text':  document.getElementById("thesectiondata").value,            'format': 'json',            'minor' : document.getElementById("minor1").checked,            'token': edittoken        },        dataType: 'json',        type: 'POST',        success: function( data ) {            if ( data.edit && data.edit.result == 'Success' ) { cancel;                window.location.reload; // reload page if edit was successful            } else if ( data.error ) {                alert( 'Error: API returned error code' + data.error.code + ' with info ' + data.error.info );            } else {                alert( 'Error: Unknown result from API.' );            }        }, error: function( xhr ) { alert( 'Error: Edit failed.' ); }   }); }

function initsection(count) { editsection(count); setTimeout("updateheight",300); setTimeout("updateheight",500); setTimeout("updateheight",2000); }

function editsection(header) {  if(editing) {return;} editing=true;

$.getJSON(       wgScriptPath + '/api.php?',        {            action: 'query',            prop: 'info',            intoken: 'edit',            titles: PageName,            indexpageids: '',            format: 'json'        },        function( data ) {            if ( data.query.pages && data.query.pageids ) {                var pageid = data.query.pageids[0];                edittoken = data.query.pages[pageid].edittoken;            }        }    )

$.get('http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles='+PageName+'&rvprop=content&rvsection='+(header+1)+'&format=xml', function(data) {

var ccontent = $(data).find("rev").text;

document.getElementsByClassName("mw-headline")[header].innerHTML = document.getElementsByClassName("mw-headline")[header].innerHTML + " ";

})

}

function updateheight { var h1 = document.getElementById("thesectiondata").style.height.replace("px",""); var h = parseInt(h1)-25; var sh = document.getElementById("thesectiondata").scrollHeight;

if(!h1 || h < sh) {   document.getElementById("thesectiondata").style.height = 10+"px"; document.getElementById("thesectiondata").style.height = (25+document.getElementById("thesectiondata").scrollHeight)+"px"; } }

$(function { var i = 0;

while(iedit]";

i++; }

});