MediaWiki:Gadget-popolnipomocnik.js

Iz Wikivira, proste knjižnice besedil v javni lasti

Opomba: Da bodo spremembe prišle do veljave, po objavi izpraznite predpomnilnik svojega brskalnika.

  • Firefox/Safari: Držite Shift in kliknite Znova naloži (Reload) ali pritisnite Ctrl + Shift + R ali Ctrl + R (⌘ + R v sistemu Mac)
  • Internet Explorer/Edge: Držite Ctrl + F5 in kliknite Osveži (Refresh) ali pritisnite Ctrl + F5
  • Google Chrome: Pritisnite Ctrl + Shift + R (⌘ + Shift + R v sistemu Mac)
  • Opera: Pritisnite Ctrl + F5.
// Popolni pomočnik - ko urejanje Wikivira postane preprosto
//  _______________________________________________________________________________________
// |                                                                                       |
// |                  == POZOR: OSREDNJA DATOTEKA VTIČNIKA ==                              |
// |            Spremembe te datoteke vplivajo na veliko uporabnikov.                      |
// |      Pred urejanjem se posvetujte na pogovorni strani [[Wikivir:Pod lipo]].           |
// |_______________________________________________________________________________________|
//
// Mihael Simonič <[[Uporabnik:Smihael]]>, 2009
// Temelji na [[:w:en:User:Mr.Z-man/refToolbar]]
// Za opis glej [[Uporabnik:Smihael/Popolni pomočnik]]

// alternativa: //sl.wikisource.org/w/index.php?title=MediaWiki%3AGumbi.js&diff=19242&oldid=18084

var numforms = 0;
var wikEdAutoUpdateUrl;
function pomocnikGumbi() {
  if (mwCustomEditButtons && document.getElementById('toolbar') ) {
    button = document.createElement('a');
    button.href = "javascript:popolniPomocnikGlavno()";
    button.title = "Popolni pomočnik";
    buttonimage = document.createElement('img');
    buttonimage.src = "//upload.wikimedia.org/wikipedia/commons/2/28/Button_info.png";
    buttonimage.alt = "Popolni pomočnik";
    button.appendChild(buttonimage);
    var toolbar = document.getElementById('toolbar');
    if (navigator.userAgent.indexOf('MSIE') == -1) {
      if (toolbar.style != null) {
        toolbar.style.height = 'auto';
      }
      else {
      	toolbar.setAttribute('style', 'margin-bottom: 6px; height: auto;');
      }
      toolbar.appendChild(button);
      pomocnikglavno = document.createElement('div');
      pomocnikglavno.style.display = 'none';
      pomocnikglavno.style.margin = '0.2em 0 -0.2em 0';
      pomocnikglavno.setAttribute('Id', 'pomocnikizbira');
      pomocnikglavno.appendChild( dodajMoznost("predlogaNaslov()", "Vstavi predlogo naslov") );
      pomocnikglavno.appendChild( dodajMoznost("predlogaAvtor()", "Vstavi predlogo avtor") );
      pomocnikglavno.appendChild( dodajMoznost("predlogaCOBISS()", "Vstavi predlogo COBISS") );
      //pomocnikglavno.appendChild( dodajMoznost("predlogaPesem()", "Vstavi pesem") );
      //pomocnikglavno.appendChild( dodajMoznost("predlogaProzaS()", "Vstavi prozno besedilo") );
      //pomocnikglavno.appendChild( dodajMoznost("navediVir()", "Navedi vir") );
      //pomocnikglavno.appendChild( dodajMoznost("dispErrors()", "Prikaži napake") );
      pomocnikglavno.appendChild( dodajMoznost("skrijPopolnegaPomocnika()", "Zapri Popolnega pomočnika") );
      toolbar.appendChild(pomocnikglavno);
    }
    else {
      toolbar.appendChild(button);
      selection = '<div id="pomocnikizbira" style="display:none"><input type="button" value="Podatki o knjigi" onclick="predlogaNaslov()" />'+
      '<input type="button" value="Podatki o avtorju" onclick="predlogaAvtor()" />'+
      '<input type="button" value="COBISS-ID" onclick="predlogaCOBISS()" />'+
      //'<input type="button" value="Pesem" onclick="predlogaPesem()" />'+
      //'<input type="button" value="Proza" onclick="predlogaProza()" />'+
      //'<input type="button" value="Navedi vir" onclick="navediVir()" />'+
      //'<input type="button" value="Prikaži napake" onclick="dispErrors()" />'+
      '<input type="button" value="Prekliči" onclick="skrijPopolnegaPomocnika()" /></div>';
      document.getElementById('editform').innerHTML = selection + document.getElementById('editform').innerHTML;
    }
  }
}

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

function skrijPopolnegaPomocnika() {
  document.getElementById('pomocnikizbira').style.display = 'none';
  skrijStarObrazec();
}

function skrijStarObrazec() {
  if (numforms != 0) {
    document.getElementById('pomocnikdiv'+numforms).style.display = 'none';
  }
  if (document.getElementById('errorform') != null) {
    document.getElementById('pomocnikizbira').removeChild(document.getElementById('errorform'));
  }
}

function popolniPomocnikGlavno() {
  document.getElementById('pomocnikizbira').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 predlogaNaslov() {
  skrijStarObrazec();
  predloga = "naslov";
  numforms++;
  form = '<div id="pomocnikdiv'+numforms+'">'+
    '<table style="border: 1px solid rgb(170, 221, 170); width: 100%; margin-bottom: 5px; background-color: rgb(228, 242, 228); text-align: center; font-size: 0.9em;">'+
    '<input type="hidden" value="'+predloga+'" id="predloga"><tr>'+
    '<td style="width: 20%; text-align: left; font-size: 0.9em;"><input type="text" tabindex=1 style="width:100%" id="prejsnji"><br /><label for="prejsnji">← <small>(prejšnji naslov v zbirki - neobvezno)</small></label></td>'+
    '<td style="width: 60%;"><input type="text" tabindex=1 style="width:100%" id="naslov"><br /><label for="naslov"><small>(naslov dela)</small></label><br>'+
    '<input type="text" tabindex=1 style="width:100%" id="poglavje"><br /><label for="poglavje"><small>(poglavje ali zbirka - neobvezno)</small></label><br>'+
    '<input type="text" tabindex=1 style="width:100%" id="avtor"><br/><label for="avtor"><small>(avtor; če je besedilo ljudsko pusti prazno)</small></label></td>'+
    '<td style="width: 20%; text-align: right; font-size: 0.9em;"><input type="text" tabindex=1 style="width:100%" id="naslednji"><br /><label for="naslednji"><small>(naslednji naslov v zbirki - neobvezno)</small> →</label></td></tr>'+
    '</table>'+
    '<table style="border-bottom: 1px solid rgb(170, 136, 136); background: rgb(250, 250, 255); width: 100%; font-size: 0.9em;">'+
    '<tr><td><input type="text" tabindex=1 style="width:100%" id="opombe"><br /><label for="opombe"><small>(opombe)</small></label>'+
    '<table style="width: 100%; background-color: rgb(250, 250, 255); font-size: 90%;">'+
    '<tr><td></td></tr><tr>'+
    '<td><label for="spisano"><b>Spisano:</b></label></td>'+
    '<td><input type="text" tabindex=1 style="width:100%" id="spisano"><br /><label for="spisano"><small>(ime in priimek osebe, ki nalaga besedilo na Wikivir)</small></label></td>'+
    '</tr><tr>'+
    '<td><label for="izdano"><b>Izdano:</b></label></td>'+
    '<td><input type="text" tabindex=1 style="width:100%" id="izdano"><br /><label for="izdano"><small>(v kateri publikaciji je bilo delo prvič izdano)</small></label></td>'+
    '</tr><tr>'+
    '<td><label for="vir"><b>Vir(i):</b></label></td>'+
    '<td><input type="text" tabindex=1 style="width:100%" id="vir"><br /><label for="vir"><small>(iz katere publikacije je besedilo za Wikivir prepisano)</small></label></td>'+
    '</tr><tr>'+
    '<td><label for="licenca"><b>Licenca:</b></label></td>'+
    '<td><input type="text" tabindex=1 style="width:100%" id="licenca"><br /><label for="licenca"><small>(pod kakšnimi pogoji je besedilo dostopno; javna last, GFDL, CC-BY-SA-3.0, CC-BY-ND-3.0, s pisnim dovoljenjem)</small></label></td>'+
    '</tr><tr>'+
    '<td><label for="obdelano"><b>Stopnja obdelave:</b></label></td>'+
    '<td><input type="text" tabindex=1 style="width:100%" id="obdelano"><br /><label for="obdelano"><small>(številčna stopnja obdelave; od 1 do 4)</small></label></td>'+
    '</tr></table></td></tr></table>'+
    '<input type="button" value="Dodaj predlogo '+predloga+'!" onClick="dodajPopolnegaPomocnika()">'+
 '</div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function predlogaAvtor() {
  skrijStarObrazec();
  predloga = "avtor";
  numforms++;
  form = '<div id="pomocnikdiv'+numforms+'">'+
    '<input type="hidden" value="'+predloga+'" id="predloga"><tr>'+ 
    '<table style="border: 1px solid rgb(190, 162, 162); background: rgb(228, 216, 216); width: 100%; margin-bottom: 5px; text-align: center; font-size: 0.9em;"><tr>'+
    '<td style="width: 20%; font-size: 0.9em;">← Seznam avtorjev: <input type="text" tabindex=1 style="width:10px" id="zadnja_zacetnica"><br/><label><small>(začetnica priimka)</small></label></td>'+
    '<td style="width: 60%; text-align: center;"><input type="text" tabindex=1 style="width:100%" id="ime"><br /><label><small>(ime in priimek avtorja)</small></label><br>'+
    '(<input type="text" tabindex=1 style="width:50px" id="leto_rojstva">–<input type="text" tabindex=1 style="width:50px" id="leto_smrti">)<br /><label><small>(leto rojstva in leto smrti)</small></label></td>'+
    '<td style="width: 20%;"></td></tr></table>'+
    '<table style="border-bottom: 1px solid rgb(170, 136, 136); background: rgb(255, 251, 252); width: 100%; font-size: 0.9em;"><tr>'+
    '<td>Glej tudi: (1) <input type="text" tabindex=1 style="width:30%" id="wikipedija">, (2) <input type="text" tabindex=1 style="width:30%" id="wikinavedek">, (3) <input type="text" tabindex=1 style="width:30%" id="zbirka">.<br /><label><small>(naslovi člankov (vpiši samo, če obtsjajo) na (1) Wikipediji, (2) Wikinavedku in (3) Zbirki)</small></label>'+
    '</span><input type="text" tabindex=1 style="width:100%" id="opis"><br /><label><small>(kratek opis avtorja)</small></label></td>'+
    '</tr></table><br/><b>Slika:</b><br />'+
    '<input type="text" tabindex=1 style="width:100%" id="slika"><br /><label><small>(ime slike s končnico - Ime_slike.jpg)</small></label>'+
    '<input type="text" tabindex=1 style="width:100%" id="napis_slike"><br /><label><small>(napis pod sliko)</small></label><br />'+
    '<input type="button" value="Dodaj predlogo '+predloga+'!" onClick="dodajPopolnegaPomocnika()">'+
 '</div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function navediVir() {
  skrijStarObrazec();
  predloga = "navedi knjigo";
  numforms++;
  form = '<div id="citediv'+numforms+'">'+
    '<fieldset><legend>Navedi knjižni vir</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+predloga+'" id="predloga">'+
    '<tr><td width="120"><label for="last">&nbsp;Priimek: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="last"></td>'+
    '<td width="120"><label for="first">&nbsp;Ime: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="first"></td></tr>'+
    '<tr><td width="120"><label for="coauthors">&nbsp;Sodelavci: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="coauthors"></td>'+
    '<td width="120"><label for="others">&nbsp;Ostali: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="others"></td></tr>'+
    '<tr><td width="120"><label for="title">&nbsp;Naslov: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="title"></td>'+
    '<td width="120"><label for="editor">&nbsp;Urednik: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="editor"></td></tr>'+
    '<tr><td width="120"><label for="publisher">&nbsp;Založnik: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="publisher"></td>'+
    '<td width="120"><label for="location">&nbsp;Kraj: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>'+
    '<tr><td width="120"><label for="date">&nbsp;Datum izdaje: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="date"></td>'+
    '<td width="120"><label for="edition">&nbsp;Izdaja: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="edition"></td></tr>'+
    '<tr><td width="120"><label for="series">&nbsp;Serija: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="series"></td>'+
    '<td width="120"><label for="volume">&nbsp;Številka: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="volume"></td></tr>'+
    '<tr><td width="120"><label for="pages">&nbsp;Strani: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="pages"></td>'+
    '<td width="120"><label for="chapter">&nbsp;Poglavje: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="chapter"></td></tr>'+
    '<tr><td width="120"><label for="isbn">&nbsp;ISBN: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="isbn"></td>'+
    '<td width="120"><label for="oclc">&nbsp;OCLC: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="oclc"></td></tr>'+
    '<tr><td width="120"><label for="url">&nbsp;URL: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="url"></td>'+
    '<td width="120"><label for="accessdate">&nbsp;Datum navedbe: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="accessdate"></td></tr>'+
    '<tr><td width="120"><label for="language">&nbsp;Jezik: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="language"></td>'+
    '<td width="120"><label for="refname">&nbsp;Ime reference: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="refname"></td></tr>'+
    '</table>'+
    '<input type="button" value="Dodaj navedbo vira!" onClick="dodajPopolnegaPomocnika()">'+
 '</fieldset></div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function predlogaCOBISS() {
  skrijStarObrazec();
  predloga = "COBISS";
  numforms++;
  form = '<div id="pomocnikdiv'+numforms+'">'+
    '<fieldset><legend>Vstavi predlogo COBISS</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+predloga+'" id="predloga">'+
    '<tr><td width="120"><label for="ID">&nbsp;COBISS-ID: </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%" id="ID"></td>'+
    '</table>'+
    '<input type="button" value="Dodaj predlogo!" onClick="dodajPopolnegaPomocnika()">'+
 '</fieldset></div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function predlogaPesem() {
  skrijStarObrazec();
  predloga = "Pesem";
  numforms++;
  form = '<div id="pomocnikdiv'+numforms+'">'+
    '<fieldset><legend>Vstavi predlogo pesem</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+predloga+'" id="predloga">'+
    '<tr><td width="120"><label for="1">&nbsp;Besedilo pesmi (vsak verz v novo vrstico): </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%; height:400px;" id="1"></td>'+
    '</table>'+
    '<input type="button" value="Dodaj predlogo!" onClick="dodajPopolnegaPomocnika()">'+
 '</fieldset></div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function predlogaProza() {
  skrijStarObrazec();
  predloga = "Proza";
  numforms++;
  form = '<div id="pomocnikdiv'+numforms+'">'+
    '<fieldset><legend>Vstavi predlogo pesem</legend>'+
    '<table cellspacing="5">'+
    '<input type="hidden" value="'+predloga+'" id="predloga">'+
    '<tr><td width="120"><label for="1">&nbsp;Besedilo (odlomke ločite s prazno vrstico): </label></td>'+
      '<td width="400"><input type="text" tabindex=1 style="width:100%; height:400px;" id="1"></td>'+
    '</table>'+
    '<input type="button" value="Dodaj predlogo!" onClick="dodajPopolnegaPomocnika()">'+
 '</fieldset></div>';
   document.getElementById('pomocnikizbira').innerHTML += form;
}

function dodajPopolnegaPomocnika(predloga) {
  pomocniks = document.getElementById('pomocnikdiv'+numforms).getElementsByTagName('input');
  var pomocnikbegin = '<!-- Vstavljeno s popolnim pomočnikom -->';
  var pomocnikname = '';
  var pomocnikinner = '';
  for (var i=0; i<pomocniks.length-1; i++) {
    if (pomocniks[i].value != '' && pomocniks[i].id != "refname" && pomocniks[i].id != "predloga") {
      pomocnikinner += "|" + pomocniks[i].id + "=" + pomocniks[i].value;
    }
    else if (pomocniks[i].value != '' && pomocniks[i].id == "refname" && pomocniks[i].id != "predloga") {
      pomocnikbegin += ' name="' + pomocniks[i].value + '"';
    }
    else if (pomocniks[i].value != '' && pomocniks[i].id != "refname" && pomocniks[i].id == "predloga") {
      pomocnikname = '{{' + pomocniks[i].value;
    }
  }
  pomocnik = pomocnikbegin + pomocnikname + pomocnikinner + "}}";
  insertTags(pomocnik, '', '');
  document.getElementById('pomocnikdiv'+numforms).style.display = 'none';
}


function addnamedpomocnik() {
  name = document.getElementById('pomocnikdiv'+numforms).getElementsByTagName('select')[0].value;
  ref = '<ref name="'+name+'" />';
  insertTags(ref, '', '');
  document.getElementById('pomocnikdiv'+numforms).style.display = 'none';
}

function dobiVsePredloge() {
  if (typeof(wikEdUseWikEd) != 'undefined') {
    if (wikEdUseWikEd == true) {
      WikEdUpdateTextarea();
    }
  }
  text = document.getElementById('wpTextbox1').value;
  regex = /{{((.|\n)*?)*?}}/gim //"
  var vsepredloge = new Array();
  var i=0;
  var nr=true;
  do {
    ref = regex.exec(text);
    if(ref != null){
      if (ref[0].search(/[^\s]{150}/) != -1) {
        ref[0] = ref[0].replace(/\|([^\s])/g, "| $1");
      }
      ref[0] = ref[0].replace(/</g, "&lt;");
      ref[0] = ref[0].replace(/>/g, "&gt;");
      vsepredloge[i] = ref[0];
      i++;
    } else {
      nr=false;
    }
  } while (nr==true);
  return vsepredloge;
}


hookEvent("load", pomocnikGumbi);