Jump to content

User:Mr.Z-man/refToolbar.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr.Z-man (talk | contribs) at 20:02, 30 March 2008 (move to stable page from development version @ User:Mr.Z-man/refbuttonstest.js). 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.
var numforms = 0;
function fancyButton(image, JSfunction, title) {
  button = document.createElement('a');
  button.href = JSfunction;
  button.title = title;
  buttonimage = document.createElement('img');
  buttonimage.src = image;
  buttonimage.alt = title;
  button.appendChild(buttonimage);
  document.getElementById('toolbar').appendChild(button);
}

function refbuttons() {
  if (mwCustomEditButtons && document.getElementById('toolbar')) {
    fancyButton("/media/wikipedia/commons/9/91/Button_cite_web.png", "javascript:citeWeb()", "Web citation");
    fancyButton("/media/wikipedia/commons/2/2c/Button_cite_news.png", "javascript:citeNews()", "News citation");
    fancyButton("/media/wikipedia/commons/e/ef/Button_cite_book.png", "javascript:citeBook()", "Book citation");
  }
}

function getTime() {
  var time = new Date();
  var curday = time.getDate();
  var curmonth = time.getMonth()+1;
  var nowyear = time.getYear()+1900;
  var nowday = curday.toString();
  if (curday <10) { nowday = "0"+nowday;}
  var nowmonth = curmonth.toString();
  if (curmonth <10) { nowmonth = "0"+nowmonth;}3
  newtime =  nowyear + '-' + nowmonth + '-' + nowday
  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;
  newtime = getTime();
  numforms++;
  form = '<div id=\"citediv'+numforms+'\" style= \"margin: 0 0 1em; padding: .5em 1em; vertical-align: middle; border: solid #aaaaaa 1px\"><form id=\"citeform'+numforms+'\">'+
    '<table>'+
    '<tr><td width=\"100\"><label for=\"url\">&nbsp;URL: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"url\"></td>'+
    '<td width=\"100\"><label for=\"title\">&nbsp;Title: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"title\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"last\">&nbsp;Last name: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"last\"></td>'+
    '<td width=\"100\"><label for=\"first\">&nbsp;First name: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"first\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"coauthors\">&nbsp;Coauthors: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"coauthors\"></td>'+
    '<td width=\"100\"><label for=\"date\">&nbsp;Publication date: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"work\">&nbsp;Work: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"work\"></td>'+
    '<td width=\"100\"><label for=\"publisher\">&nbsp;Publisher: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"publisher\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"pages\">&nbsp;Pages: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"pages\"></td>'+
    '<td width=\"100\"><label for=\"language\">&nbsp;Language: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"language\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"date\">&nbsp;Date: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td>'+
    '<td width=\"100\"><label for=\"accessdate\">&nbsp;Access date: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"accessdate\" value=\"'+ newtime +'\"></td></tr>'+
    '<input type=\"button\" value=\"Add citation\" onClick=\"addcites(template)\">'+
    '</table>'+
 '</form></div>';
   document.getElementById('wikiPreview').innerHTML += form;
}

function citeBook() {
  if (numforms != 0) {
    document.getElementById('citediv'+numforms).style.display = 'none';
  }
  template = "cite book";
  numforms++;
  form = '<div id=\"citediv'+numforms+'\" style= \"margin: 0 0 1em; padding: .5em 1em; vertical-align: middle; border: solid #aaaaaa 1px\"><form id=\"citeform'+numforms+'\">'+
    '<table>'+
    '<tr><td width=\"100\"><label for=\"last\">&nbsp;Last name: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"last\"></td>'+
    '<td width=\"100\"><label for=\"first\">&nbsp;First name: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"first\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"coauthors\">&nbsp;Coauthors: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"coauthors\"></td>'+
    '<td width=\"100\"><label for=\"others\">&nbsp;Others: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"others\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"title\">&nbsp;Title: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"title\"></td>'+
    '<td width=\"100\"><label for=\"editor\">&nbsp;Editor: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"editor\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"publisher\">&nbsp;Publisher: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"publisher\"></td>'+
    '<td width=\"100\"><label for=\"location\">&nbsp;Location: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"Location\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"date\">&nbsp;Publication date: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td>'+
    '<td width=\"100\"><label for=\"edition\">&nbsp;Edition: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"edition\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"series\">&nbsp;Series: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"series\"></td>'+
    '<td width=\"100\"><label for=\"volume\">&nbsp;Volume: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"volume\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"pages\">&nbsp;Pages: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"pages\"></td>'+
    '<td width=\"100\"><label for=\"chapter\">&nbsp;Chapter: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"chapter\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"isbn\">&nbsp;ISBN: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"isbn\"></td>'+
    '<td width=\"100\"><label for=\"oclc\">&nbsp;OCLC: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"oclc\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"url\">&nbsp;URL: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"url\"></td>'+
    '<td width=\"100\"><label for=\"accessdate\">&nbsp;Access date: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"accessdate\"></td></tr>'+
    '<tr><td width=\"100\"><label for=\"language\">&nbsp;Language: </label></td>'+
              '<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"language\"></td></tr>'+
    '<input type=\"button\" value=\"Add citation\" onClick=\"addcites(template)\">'+
    '</table>'+
 '</form></div>';
   document.getElementById('wikiPreview').innerHTML += form;
}

function addcites(template) {
  cites = document.getElementById('citeform'+numforms).getElementsByTagName('input');
  var insert = "<ref>{{" + template;
  for (var i=0; i<cites.length-1; i++) {
    if (cites[i].value != '') {
     insert += "|" + cites[i].id + "=" + cites[i].value;
    }
  }
  insert += "}}</ref>";
  insertTags(insert, '', '');
  document.getElementById('citediv'+numforms).style.display = 'none';
}

hookEvent("load", refbuttons);