User:AuFCL/common.js/jsleader.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// <nowiki>
//This code is not linked to from anywhere and is simply being maintained for
//the historical horror it represents.

function jsleader(){
 var AllTags=document.getElementsByTagName('*');
 for(var S=0;S<AllTags.length;S++){
  if(AllTags[S].hasAttributes('class')){
   if(/JavaScriptTagDotTestLeaderPrototype/.test(AllTags[S].getAttribute('class'))){
    var leaderProto=AllTags[S].innerHTML;
    AllTags[S].innerHTML="";
    AllTags[S].setAttribute("style",AllTags[S].getAttribute("style")+"display:inline-block;word-wrap:break-word;word-break:break-all;");
    var container=AllTags[S].parentNode,
     baseHeight=container.clientHeight;
    while(container && !baseHeight){
     container=container.parentNode;
     baseHeight=container.clientHeight;
    }
    if(container){
     var leaderFill="",
      guard=0;
     while((guard<500) && (container.clientHeight==baseHeight)){
      guard++;
      AllTags[S].innerHTML=leaderFill+leaderProto;
      if(container.clientHeight==baseHeight){
       leaderFill=AllTags[S].innerHTML;
      }
     }
     AllTags[S].innerHTML=leaderFill;
    }
   }
  }
 };
 for(var S=AllTags.length-1;S>=0;S--){
  if(AllTags[S].hasAttributes('class')){
   if(/JavaScriptTagDotTestLeaderPrototype/.test(AllTags[S].getAttribute('class'))){
    var container=AllTags[S].parentNode,
     baseHeight=container.clientHeight;
    while(container && !baseHeight){
     container=container.parentNode;
     baseHeight=container.clientHeight;
    }
    if(container){
     var guard=0,
      maxFill=0,
      leaderFill=AllTags[S].innerHTML;
     while((guard<1000) && (container.clientHeight==baseHeight)){
      guard++;
      AllTags[S].innerHTML=leaderFill+
       "<span style='display:inline-block;margin:0 0 0 0;padding:0 0 0 0;test-indent:0;width:"+
       parseInt(guard)+"px;'>&thinsp;</span>";
      if(container.clientHeight==baseHeight){
       maxFill=guard;
      }
     }
     AllTags[S].innerHTML=leaderFill+
      (maxFill?
       "<span style='display:inline-block;margin:0 0 0 0;padding:0 0 0 0;test-indent:0;width:"+
       parseInt(maxFill)+"px;'>&thinsp;</span>":
       "");
    }
   }
  }
 };
}

$(jsleader);

// </nowiki>