Järjestelmäviesti:Gadget-RefHelper2.js

Wikipediasta
Siirry navigaatioon Siirry hakuun

Huomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.

  • Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
  • Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
  • Internet Explorer ja Edge: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
  • Opera: Paina Ctrl-F5.
if ((mw.config.get('wgNamespaceNumber')==0) && (mw.config.get('wgAction')=='view') && (!document.getElementById('mw-diff-otitle1'))) {

var visibleRefs=Array();
// Kopioidaan viite viitelistasta inline viitteeksi
function showhide_createInlineRef(id, span) {

   var buttons="";
   var refname="";
   var id_tmp=id.replace("inline", "note");
   var note=document.getElementById(id_tmp);

// Ne tapaukset joissa viitettä on käytetty useita kertoja
   if (note==null) {
      id_tmp=id_tmp.replace(/_([0-9]{1,3})-([0-9]{1,3})$/, "-$1");
      note=document.getElementById(id_tmp);

   }
// Ne tapaukset joissa viitettä ei ole olemassa tai niitä ei ole käytetty kertaakaan
// (haetaan virheilmoitus)
   if (note==null) {

      id_tmp=id_tmp.replace(/-([0-9]{1,3})$/, "");
      note=document.getElementById(id_tmp);
   }


   if (note==null) alert("Error: note=null id_tmp=" + id_tmp);
   refname=id_tmp.replace(/cite_note-(.*?)-[0-9]{1,3}$/, "$1");
   if (refname==id_tmp) {
      var reftitle="";    
   } else {
     refname=refname.replace(/\.3F/g, "/");
     refname=refname.replace(/\.C3\.A4/g, "ä");

     var sup=note.getElementsByTagName("sup");
     var refnum="";
     if (sup!=null && sup.length>1)  refnum=" (" + sup.length +")";
 //    buttons=" [ <a href='javascript:editRef(\"" + refname +"\" , \"" + refnum + "\")'>muokkaa</a> ]";
//     var reftitle= "Viitteen nimi: " + refname + refnum + " − ";

// Viitteen nimi lienee turhaa informaatiota, sen näkee editorissa jos sitä tarvitsee
     var reftitle="";
   }
   var html=" <small><a href='#" + id_tmp +"'>&darr;</a>  </small> " + reftitle + note.innerHTML  ;



// Siivoaa viitteistä ylimääräistä tauhkaa pois
  html=html.replace(/↑ ?/, "");
  html=html.replace(/<sup>(.*?)<\/sup>/ig, "");
  span.html(html);
  span.show();
}

// Tyhjentää tuplaklikkauksen aiheuttaman tekstin valinnan
// http://stackoverflow.com/questions/3169786/clear-text-selection-with-javascript
function clearSelection() {
  if (window.getSelection) {
    if (window.getSelection().empty) {  // Chrome
      window.getSelection().empty();
    } else if (window.getSelection().removeAllRanges) {  // Firefox
      window.getSelection().removeAllRanges();
    }
  } else if (document.selection) {  // IE?
    document.selection.empty();
  }
}

function doToggleReferences(state)
{
  if (toggling==true) {
       alert("Varoitus: uudelleenklikkasit liian nopeasti. Edellinen operaatio on vielä meneillään");
       toggling=false;
       return;
  } 

  toggling=true;
  if (state==-1) state=$.cookie("showreferences");
  if (state==0)
  {
//    $(".reference").css('visibility','hidden');
    $(".inlinereference").hide();
    $(".reference").hide();
    if (sideNotesHidden==false)
    {
       sideNotesHidden=true;
       $(".reference").each(addSideNotesHidden);
    }

    $(".visibleSideNote").hide();
    $(".hiddenSideNote").show();

    visibleRefs=Array();
  }
  else
  {
    $(".reference").show();
//    $(".reference").css('visibility','inherit');
    if (sideNotesVisible==false) {
       sideNotesVisible=true;
       $(".reference").each(addSideNotesVisible);
    }

    $(".visibleSideNote").show();
    $(".hiddenSideNote").hide();
  }
  toggling=false;
}
function doToggleAndSaveReferenceState(e) { 
  if (typeof e != "undefined") e.stopPropagation();
  var showreferences=$.cookie("showreferences") == "1" ? 0 : 1;
  $.cookie("showreferences", showreferences +"", { expires: 30, path: '/' });
  $(".customSideNote").remove();
  doToggleReferences(showreferences);
  setTimeout("clearSelection()",1);
  return false;
}

function doHideCite(id) {
   var newid=id.replace("ref", "inline");
   var inlineref=$(document.getElementById(newid));
   if (!visibleRefs[newid])
      inlineref.hide();
}

function doShowCite(id) {
   if (redraw==true) return;

   var newid=id.replace("ref", "inline");
   var inlineref=$(document.getElementById(newid));
   if (inlineref && inlineref.html() && inlineref.html() !="")
   { 
         inlineref.show();
   }
   else if (inlineref && inlineref.html()=="")
   {
      showhide_createInlineRef(newid, inlineref);
   }
   else
   {
      var inlineref=$("<span id='" + newid +"' style='background-color:#DDEEFF;padding:0.25em;padding-left:0.5em; padding-right:0.5em;'>XXXXXXXX</span>");
      inlineref.addClass('inlinereference');
      $(document.getElementById(id)).after(inlineref);
      showhide_createInlineRef(newid, inlineref);
   }
}

function doToggleSingleRef(id)
{
     var newid=id.replace("ref", "inline");
     var inlineref=$(document.getElementById(newid));
 
     if (!visibleRefs[newid])
     {

        showreferences=1;
     
        $.cookie("showreferences", showreferences +"", { expires: 30, path: '/' });
//        doToggleReferences(showreferences);

        $(".customSideNote").remove();
        $(".reference").show();  
        $(".reference").each(addSideNotesCustom);
  
        $(".hiddenSideNote").hide();
        $(".visibleSideNote").hide();
        $(".customSideNote").show();

        visibleRefs[newid]=1;
        inlineref.show();

     }
     else
     {
        $(this).css("backgroundColor", "transparent");
        visibleRefs[newid] =0;
       
        $(".customSideNote").remove();
        redraw=true;
        $(".reference").each(addSideNotesCustom);
        redraw=false;
        inlineref.hide();
      }    

    return false;
}

$("#firstHeading").click(doToggleAndSaveReferenceState);


var top=20;
var left=($("#content").offset().left - 20);
//var left="-20";
var height=$('#content').height();

side=$('<div>');
side.css({position: "absolute", top:0, zIndex: 1000, paddingLeft:"18px", paddingRight:"18px", fontWeight:1200, height:height });

$("body").append(side);

side.offset({ left: left });
side.click(doToggleAndSaveReferenceState);
side.dblclick(function(e) { e.stopPropagation(); return false; });

function addSideNotesHidden(index)
{
    span=$("<span>");
    $(this).after(span);
    heightfix=0;
    var top=$(span).offset().top - heightfix;
    var left=leftfix- 19;

    div = $("<a>").html("|");
    div.addClass("hiddenSideNote");
    div.css({position: "absolute", color: "blue", zIndex: 1500, opacity: "0.5", paddingLeft:"18px", paddingRight:"18px", fontWeight:1200 });
    div.appendTo('body');
    div.offset({ top: top, left: left });
    div.css("cursor","pointer").css("cursor","hand");
 //   div.attr("title", "Näytä tai piilota viitemerkinnät");

    var targetid=$(this).attr("id");
    div.click(doToggleAndSaveReferenceState); 
//    div.click(function() {doToggleSingleRef(targetid); });
//    div.mouseenter(function() {doShowCite(targetid); });
//    div.mouseleave(function() { doHideCite(targetid); });
}

function addSideNotesVisible(index)
{ 
    var top=$(this).offset().top ;
    var left=leftfix- 19;

    div = $("<a>").html("|");
    div.addClass("visibleSideNote");
    div.css({position: "absolute", color: "blue", zIndex: 1500, opacity: "0.5", paddingLeft:"18px", paddingRight:"18px", fontWeight:1200});
    div.appendTo('body');
    div.offset({ top: top, left: left });
    div.css("cursor","pointer").css("cursor","hand");
 //   div.attr("title", "Näytä tai piilota viitemerkinnät");

    var targetid=$(this).attr("id");
    div.click(doToggleAndSaveReferenceState);
/*    div.click(function() {  doToggleSingleRef(targetid); });
    div.mouseenter(function() {doShowCite(targetid); });
    div.mouseleave(function() { doHideCite(targetid); });*/
}

function addSideNotesCustom(index)
{
    var top=$(this).offset().top ;
    var left=leftfix- 19;

    div = $("<a>").html("|");
    div.addClass("customSideNote");
    div.css({position: "absolute", color: "blue", zIndex: 1500, opacity: "0.5", paddingLeft:"18px", paddingRight:"18px", fontWeight:1200});
    div.appendTo('body');
    div.offset({ top: top, left: left });
    div.css("cursor","pointer").css("cursor","hand");
 //   div.attr("title", "Näytä tai piilota viitemerkinnät");

    var targetid=$(this).attr("id");
   
    div.click(function() {doToggleSingleRef(targetid); });
    div.mouseenter(function() {doShowCite(targetid); });
    div.mouseleave(function() { doHideCite(targetid); });
}




var heightfix=$("#pt-preferences").height()/2;
var leftfix=$("#content").offset().left;
var sideNotesHidden=false;
var sideNotesVisible=false;
var toggling=false;
var redraw=false;

$(document).ready(function() {
  state=$.cookie("showreferences");
  if (state==0)
  {
     doToggleReferences(0);
  }
  else
  {
     doToggleReferences(1);
  }
});


}