User:Yair rand/editsection.js

mw.config.get('wgNamespaceNumber')==0 && jQuery(document).ready(function{ for(var a=jQuery("h3 .mw-editsection a,h4 .mw-editsection a,h5 .mw-editsection a"), i=0; i < a.length; i++){ b(a[i])  } function b(c){  c.onclick=function{   function fh(w_,q){    var ll=w_.search(/(^|\n)=/)+1, l=0;    while(++l < q){     ll = w_.indexOf("\n=", ll+1)     }    return w_.indexOf("=\n", ll+1)+2    }   var q = c.href.split("&section=")[1], qq = c.parentNode.parentNode, backup = document.createDocumentFragment, theform, ll;   while(qq.nextSibling && qq.nextSibling.nodeName.substr(0,1).toLowerCase != 'h' && qq.nextSibling.className != "catlinks"){    backup.appendChild(qq.nextSibling)    }   editor=new Editor;   editor.withCurrentText(function(wikitext){ new AdderWrapper(editor, {    'createForm':function{      var t, ll = fh(wikitext, q), wt=wikitext.substr(ll);      wt=wt.substr(0, wt.indexOf("\n=")==-1?undefined:wt.indexOf("\n="));      return theform = newNode('form', newNode('textarea',wt,{'name':'wt','rows':wt.match(/\n/g).length}), newNode('input',{'type':'submit','value':'Preview'}), newNode('input',{'type':'button','value':'Cancel','click':function{       theform.parentNode.insertBefore(backup,theform);theform.parentNode.removeChild(theform)}}))      },     'fields':{'wt':function(txt){return txt}},     'onsubmit':function(values,render){      render(values.wt,function(newhtml){ var newp = newNode('p');newp.innerHTML=newhtml; editor.addEdit({       'edit':function(wikitext){         var ll=fh(wikitext,q), wt=wikitext.substr(ll);wt=wt.indexOf("\n=");         return ccc=wikitext.substr(0,ll)+values.wt.replace(/\n=/g,'\n{\{subst:blank}}=')+(wt==-1?"":wikitext.substr(ll+wt))},        'redo':function{qq.parentNode.insertBefore(newp, theform);theform.style.display='none'},        'undo':function{qq.parentNode.removeChild(newp);theform.style.display='block'},        'summary':'edit section '+qq.getElementsByTagName("span")[1].innerHTML        },newp) })     }     },qq.parentNode, qq.nextSibling) theform.firstChild.focus })  return false;   }  } })