מדיה ויקי:PageNumbers.js

מתוך ויקיטקסט, מאגר הטקסטים החופשי

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*********************************
* page numbers for proofreadpage
* by [user:ThomasV]  31 Aug 2012
* fixes by [User:Inkbug] 15 Mar 2013
**********************************/
 
//[Hebrew Fix]
self.proofreadpage_source_href = true;

function hide_pagenumbers(){
   var ml = get_elements_by_classname( 'pagenumber', 'span' );
   for(var i=0; i<ml.length; i++) {
     ml[i].style.display="none";
   }
   o_a = document.getElementById("option-pageNumbers");
   if(o_a) {
     o_a.innerHTML = "<a href='javascript:show_pagenumbers();'>"+ws_msg('show_page_numbers')+"</a>"; 
   }
   $.cookie("pagenum","0") ;
}
 
function show_pagenumbers(){
   var ml = get_elements_by_classname( 'pagenumber', 'span' );
   for(var i=0; i<ml.length; i++) {
     ml[i].style.display="";
   }
   o_a = document.getElementById("option-pageNumbers");
   if(o_a){
     o_a.innerHTML = "<a href='javascript:hide_pagenumbers();'>"+ws_msg('hide_page_numbers')+"</a>"; 
   }
   $.cookie("pagenum","1") ;
}
 
function pagenum_over(ox,oy,prev_ox,prev_oy,h,w) {
  if(self.proofreadpage_disable_highlighting) return true;
  var ct = document.getElementById("ct-popup");
  if(!ct) return true;
  var dd = h/10;
  ct.style.top = (oy-h+dd)+"px";
  ct.style.height= "";
 
  //ct.firstChild.style.width = (w-ox)+"px";
  ct.firstChild.style.width = (ox==0?w:ox)+"px";//RTL
  ct.firstChild.nextSibling.style.height = (prev_oy-oy-h)+"px";
  //ct.firstChild.nextSibling.nextSibling.style.width = prev_ox+"px";
  ct.firstChild.nextSibling.nextSibling.style.width = (w-prev_ox)+"px";//RTL
  return true;
 
}
 
function pagenum_out(){
  if(self.proofreadpage_disable_highlighting) return true;
  var ct = document.getElementById("ct-popup");
  if(!ct) return true;
  ct.style.height= "0px";
  ct.firstChild.style.width = "0px";
  ct.firstChild.nextSibling.style.height = "0px";
  ct.firstChild.nextSibling.nextSibling.style.width = "0px";
  return true;
}



function init_page_numbers() {
 
    if(document.URL.indexOf("match=") > 0 ) return;

    self.pagenum_ml = get_elements_by_classname( 'pagenum', 'span' );
 
    if( !self.proofreadpage_source_href || self.pagenum_ml.length==0) return;
 
    //Disabled for Hebrew:
    //var optlist = get_optlist();
    //mw.util.addPortletLink ('p-displayOptions', 'javascript:hide_pagenumbers();', ws_msg('hide_page_numbers'), 'option-pageNumbers', '', 'n' );

    var cs = document.getElementById("mw-content-text");
 
    /* Measure the line height and the height of an empty span */
    var ct = document.createElement("div");
    ct.setAttribute("id","my-ct");
    cs.insertBefore(ct,cs.firstChild);
    var ss = document.createElement("div"); /*we need a div, not a span*/
    ss.innerHTML="&nbsp;<span></span>";     /*empty span following some text */
    ss.setAttribute("id","my-ss");
    cs.appendChild(ss);
 
    /* container for page numbers */
    var div_pagenums = document.createElement("div"); 
    div_pagenums.setAttribute("id","ct-pagenums");
    /* insert the container in the grandparent node, or parent, or self */
    var mcs = document.getElementById("text-wrap");
    if(!mcs) {
      if(cs.parentNode.parentNode.style.position=="relative") mcs = cs.parentNode.parentNode;
      else if(cs.parentNode.style.position=="relative") mcs = cs.parentNode; 
      else { mcs = cs; mcs.style.position = "relative"; }
    }
    //added
    mcs.style.marginRight = "2em";
    mcs.appendChild(div_pagenums);
 
    /* container for the highlight */
    var div_popup = document.createElement("div"); 
    var opacity="background-color:#000000;opacity:0.2;-ms-filter:alpha(opacity=20);filter:alpha(opacity=20);";
    div_popup.setAttribute("id","ct-popup");
    div_popup.style.cssText = "position:absolute;width:100%;";
    div_popup.innerHTML = "<div style=\""+opacity+"float:left;width:0px;\" >&nbsp;</div>"
      +"<div style=\""+opacity+"width:100%;height:0px;clear:both;\"></div>"
      +"<div style=\""+opacity+"width:0px;\">&nbsp;</div>";
    cs.appendChild(div_popup);
 
    refresh_pagenumbers();
}
 
 
function refresh_pagenumbers() {
    var ct = document.getElementById("my-ct");
    if(!ct) return;
 
    var ss = document.getElementById("my-ss");
 
    var cs = ct.parentNode;
    /* set it to relative because the highlight is of width 100% */
    cs.style.position = "relative"; /* fixme : this interacts with layouts */
 
    var lineheight = ss.offsetHeight; 
    var offset_h = ss.lastChild.offsetHeight;
 
    var linewidth = cs.offsetWidth; 
    var ct_o = $(ct).position();
    var ct_ox = ct_o.left; 
    var ct_oy = ct_o.top;
    var oo = $(ss).position(ss);
    var ox = oo.left - ct_ox; var oy = oo.top - ct_oy;
 
    var oh ="";
    for(var i=self.pagenum_ml.length-1; i>=0; i--) {
        var a = self.pagenum_ml[i];
        var num = decodeURI( a.id );
        if(num.match(/^.CE.9E/)) num="Ξ";
        if(num.match(/^.E2.80.93/)) num="—";
        if(num.match(/^.E2.80.94/)) num="—";
        var page = a.title;
        var pagetitle = decodeURI( page );
        var page_url = mw.config.get('wgArticlePath').replace("$1", encodeURIComponent( pagetitle.replace(/ /g,"_") ) );
        // encodeURIComponent encodes '/', which breaks subpages
        page_url = page_url.replace(/%2F/g, '/');
        var ll = a.parentNode.nextSibling;
        if(ll && ll.tagName=="A" && ll.className=="new") class_str=" class=\"new\" "; else class_str="";
        var link_str = "<a href=\""+page_url+"\"" + class_str + " title=\""+mw.html.escape(pagetitle)+"\">"+mw.html.escape(num)+"</a>" 
        if(self.proofreadpage_numbers_inline){
                a.innerHTML = "&#x0020;<span class=\"pagenumber noprint\" style=\"color:#666666; display:inline; margin:0px; padding:0px;\">[<b>"+link_str+"</b>]</span>&#x0020;";
        }
        else { 
            prev_ox = ox;
            prev_oy = oy;
            a_o = $(a).position(); 
            ox = a_o.left - ct_ox;
            oy = a_o.top - ct_oy + offset_h;
 
            if(prev_oy - oy > 5) {
                  //[Hebrew Fix] removed text-align:left; and +cs.offsetTop and replaced left:-4em with right:-4em
                  oh = oh + "<div class=\"pagenumber noprint\" onmouseover=\"pagenum_over("+ ox + "," + oy + "," + prev_ox + "," + prev_oy + "," + lineheight + "," + linewidth + ");\" onmouseout=\"pagenum_out();\" style=\"position:absolute; right:-4em; top:"+(oy-lineheight)+"px; text-indent:0em; font-size:80%; font-weight:normal; font-style: normal;\">["+link_str+"]</div>";
            }
        }
     }
     if(!self.proofreadpage_numbers_inline) {
        var ct_pagenums = document.getElementById("ct-pagenums");
        ct_pagenums.innerHTML = oh;
    }
    pagenum_out();
    if( parseInt($.cookie("pagenum")) == 0 ) hide_pagenumbers();
}
 
if ($.inArray(mw.config.get('wgAction'), [ 'view', 'submit' ]) != -1) {
    //fixme : this is sensitive to order (detection of containers with "relative" position)
	//[Hebrew Fix]
	//$(init_page_layout);
    $(init_page_numbers);
}