User:Thisisborin9/refToolbarModified.js

var numforms = 0; var wikEdAutoUpdateUrl;

function refbuttons { if (mwCustomEditButtons && document.getElementById('toolbar') && wikEdAutoUpdateUrl == null) { button = document.createElement('a'); button.href = "javascript:easyCiteMain"; button.title = "Insert Citation"; buttonimage = document.createElement('img'); buttonimage.src = "http://upload.wikimedia.org/wikipedia/commons/e/ea/Button_easy_cite.png"; buttonimage.alt = "Insert Citation"; button.appendChild(buttonimage); document.getElementById('toolbar').appendChild(button); if (navigator.userAgent.indexOf('MSIE') == -1) { citemain = document.createElement('div'); citemain.style.display = 'none'; citemain.setAttribute('Id', 'citeselect'); citemain.appendChild( addOption("citeWeb", "Web") ); citemain.appendChild( addOption("citeNews", "News") ); citemain.appendChild( addOption("citeBook", "Book") ); citemain.appendChild( addOption("citeJournal", "Journal") ); citemain.appendChild( addOption("citeNamedRef", "Named references") ); citemain.appendChild( addOption("hideInitial", "Cancel") ); document.getElementById('wpTextbox1').parentNode.insertBefore(citemain, document.getElementById('wpTextbox1')); }   else { selection = ' '+ ''+ ''+ ''+ ''+ ' '; document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML; } } }

function addOption(script, text) { option = document.createElement('input'); option.setAttribute('type', 'button'); option.setAttribute('onclick', script); option.setAttribute("value", text); return option; }

function hideInitial { document.getElementById('citeselect').style.display = 'none'; if (document.getElementById('citediv1') ) { document.getElementById('citediv'+numforms).style.display = 'none'; } }

function easyCiteMain { document.getElementById('citeselect').style.display = ''; }

function getTime { var time = new Date; var nowdate = time.getUTCDate; if (nowdate<10) { nowdate = "0"+ nowdate.toString; } var nowmonth = time.getUTCMonth+1; if (nowmonth<10) { nowmonth = "0"+ nowmonth.toString; } var nowyear = time.getUTCFullYear; newtime = nowyear + '-' + nowmonth + '-' + nowdate; return (newtime); }

function citeWeb { citeNewsWeb("cite web"); } function citeNews { citeNewsWeb("cite news"); }

function citeNewsWeb(templatename) { if (numforms != 0) { document.getElementById('citediv'+numforms).style.display = 'none'; } template = templatename; var legend; if (template="cite web") { legend = "Cite web source"; } else { legend = "Cite news source"; } newtime = getTime; numforms++; form = ''+ ' '+legend+' '+ ' '+   ''+ ' ';  document.getElementById('citeselect').innerHTML += form; }

function citeBook { if (numforms != 0) { document.getElementById('citediv'+numforms).style.display = 'none'; } template = "cite book"; numforms++; form = ''+ ' Cite book source '+ ' '+   ''+ ' ';  document.getElementById('citeselect').innerHTML += form; }

function citeJournal { if (numforms != 0) { document.getElementById('citediv'+numforms).style.display = 'none'; } template = "cite journal"; numforms++; form = ''+ ' Cite journal source '+ ' '+   ''+ ' ';  document.getElementById('citeselect').innerHTML += form; }

function addcites(template) { cites = document.getElementById('citediv'+numforms).getElementsByTagName('input'); var citebegin = '{{' + cites[i].value; } }  cite = citebegin + citename + citeinner + "}} "; insertTags(cite, , ); document.getElementById('citediv'+numforms).style.display = 'none'; }

function getNamedRefs { text = document.getElementById('wpTextbox1').value; regex = /<\s*?ref\s+?name\s*?=\s*?(('([^']*?)')|("([^"]*?)"))\s*?>/gi //' var namedrefs = new Array;  var i=0;  var nr=true;  do {    ref = regex.exec(text);    if(ref != null){      namedrefs[i] = ref[5];      i++;    } else {      nr=false;    }  } while (nr==true);  return namedrefs; }

function citeNamedRef { namedrefs = getNamedRefs; if (namedrefs == '') { if (numforms != 0) { document.getElementById('citediv'+numforms).style.display = 'none'; }   numforms++; out = ' '+ ' References in text There are no named refs (&lt;ref name="Name"&gt;) in the text '; document.getElementById('citeselect').innerHTML += out; } else { if (numforms != 0) { document.getElementById('citediv'+numforms).style.display = 'none'; }   numforms++; form = '<div id="citediv'+numforms+'">'+ ' References in article '+ ' '+     '<input type="button" value="Add citation" onClick="addnamedcite">'+ ' ';    document.getElementById('citeselect').innerHTML += form; } }

function addnamedcite { name = document.getElementById('citediv'+numforms).getElementsByTagName('select')[0].value; ref = ' '; insertTags(ref, , ); document.getElementById('citediv'+numforms).style.display = 'none'; }

hookEvent("load", refbuttons);