User:PerfektesChaos/js/fragmentAnchors/r.js

This is an old revision of this page, as edited by PerfektesChaos (talk | contribs) at 18:10, 17 April 2016 (1.0). 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.
/// Gadget-fragmentAnchors/?.js
/// 2016-02-26 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#F836EFC3#
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.0,FANCY="fragmentAnchors",FASC={cfg:{},siblings:"error-repeated-id",source0:"6/62/Anchor_pictogram.svg",source1:"d/d6/Anchor_pictogram_red.svg",vsn:Version
};
if(typeof mw.libs[FANCY]!=="object"||!mw.libs[FANCY]){
mw.libs[FANCY]={};}
mw.libs[FANCY].type=FANCY;
FANCY=mw.libs[FANCY];
FANCY.fetch=function(){
var dup,r,s;
if(FASC.cfg.live){
FASC.furnish(false,true);
if(FASC.dup){
dup={};
for(s in FASC.dup){
dup[s]=FASC.dup[s].length;}
}else{
dup=false;}
r=[FASC.total,dup];
}else{
r=false;}
return r;
};
function fiat(){
FASC.cfg.$portlet.hide();
mw.hook("wikipage.content").add(FASC.furnish);}
function fire(){
FANCY.vsn=Version;
FANCY.doc="[[w:en:User:PerfektesChaos/js/"+FANCY.type+"]]";
mw.loader.state("ext.gadget."+FANCY.type,"ready");
FASC.sign=FANCY.type;
FASC.cfg.live=false;
mw.loader.using(["user","mediawiki.util","jquery.tipsy"],FASC.fire);}
FASC.cfg.fair=function(anchor){
var r=anchor.replace(/_/g," "),s;
if(typeof FASC.wikiAnchor!=="object"){
s="[0-9A-Fa-f]";
s="\\.("+s+s+")";
FASC.wikiAnchor=new RegExp(s,"g");}
try{
s=r.replace(FASC.wikiAnchor,"%$1");
r=decodeURIComponent(s);
}catch(e){
}
return r;
};
FASC.cfg.fancy=function(anchor){
return "[["+anchor+"]]";
};
FASC.cfg.filter=function(anchor){
return(anchor.substr(0,7)!=="#Anker:");
};
FASC.cfg.fire=function(){
var portlet=mw.util.addPortletLink("p-tb","#",String.fromCharCode(8201),"t-"+FASC.sign);
if(typeof FANCY.large==="boolean"){
FASC.large=FANCY.large;}
FASC.cfg.$portlet=$(portlet);
FASC.cfg.$portlet.append(FASC.$facet());
FASC.cfg.$portlet.click(fiat);
FASC.cfg.$portlet.attr({title:FASC.sign+" "+FASC.vsn});
mw.hook(FANCY.type+".ready").fire(FANCY);
FASC.cfg.live=true;
};
FASC.cfg.$flag=function(){
return $("h1").eq(0);
};
FASC.$facet=function(alert){
var n=(alert?20:12),s=FASC["source"+(alert?1:0)],$r=$("<img />");
$r.attr({alt:"id?",src:"https://upload.wikimedia.org/wikipedia/commons/thumb/"+s+"/"+n+"px-"+s.substr(5)+".png"});
$r.css({"height":n,"width":n});
if(alert){
$r.css({"background-color":"#FFFF00","border":"#FF0000 2px solid"});}
return $r;
};
FASC.$factory=function(anchor,alert){
var mode=(alert?1:0),$r=FASC.badges[mode],$i,$s;
if(!$r){
$i=FASC.$facet(alert);
$i.addClass(FASC.show);
if(alert){
$i.addClass(FASC.siblings);}
$i.attr({rel:"tipsy"});
$s=$("<span>");
$s.css({"width":"1px"});
$s.text(" ");
$r=$("<a>");
$r.attr({href:"#"});
$r.append($s);
$r.append($i);
$r.append($s.clone());
FASC.badges[mode]=$r;}
$r=$r.clone();
$i=$r.children();
$i.attr({title:anchor.substr(1)});
$i.tipsy({gravity:"s",opacity:0.8});
$r.click(FASC.flip);
return $r;
};
FASC.filter=function(all){
var r={},s,seek,$e;
for(s in all){
if(all[s]){
if(FASC.$content){
seek="[id=\""+s.substr(1)+"\"]";
$e=FASC.$content.find(seek);
if($e.length){
r[s]=$e;}
}else{
r[s]=all[s];}}}
return r;
};
FASC.fire=function(){
FASC.badges=[false,false];
if(typeof FASC.large!=="boolean"){
FASC.large=false;}
FASC.show=FASC.sign+"-mark";
$(FASC.cfg.fire);
};
FASC.flag=function(){
var $before=FASC.cfg.$flag(),dup,s,$box,$li,$ul;
if($before){
$box=$("<div>");
$ul=$("<ul>");
for(s in FASC.dup){
dup=FASC.dup[s];
$li=$("<ul>");
$li.text(dup.length+"× "+s);
$ul.append($li);}
$box.css({"border":"#FF0000 2px solid","color":"#FF0000",
"margin-bottom":"1em","margin-top":"1em",
"padding":"1em"});
$box.attr({id:FASC.sign+"-error-multiples"});
$box.addClass(FASC.show);
$box.append($ul);
$before.before($box);}
};
FASC.flip=function(){
var $that=$(this),sel=$that.attr("original-title"),$img;
if(sel){
$that.attr({"rel":null,"original-title":null});
sel="hide";
}else{
$img=$that.children().eq(0);
$img.trigger($.Event("mouseleave"));
sel=$img.attr("original-title");
sel=FASC.cfg.fancy("#"+sel);
$that.attr({"rel":"tipsy","title":sel});
$that.tipsy({gravity:"n",opacity:0.9,trigger:"manual"});
sel="show";}
$that.tipsy(sel);
return false;
};
FASC.furnish=function($area,absent){
var learn=(!absent),total={},$total=$("[id]"),n=$total.length,dup,i,lapsus,s,$e,$m;
FASC.dup={};
FASC.total=[];
$("."+FASC.show).remove();
if(!FASC.large&&$area){
FASC.$content=$area;
}else{
FASC.$content=false;}
for(i=0;i<n;i++){
$e=$total.eq(i);
s="#"+$e.attr("id");
if(FASC.cfg.filter(s)){
if(typeof total[s]==="object"){
if(typeof FASC.dup[s]!=="object"){
FASC.dup[s]=[total[s]];
total[s]=true;}
FASC.dup[s].push($e);
}else{
total[s]=$e;}}}
$total=false;
if(typeof total["#"]==="object"){
FASC.dup["#"]=[total["#"]];
total["#"]=true;}
for(s in FASC.dup){
lapsus=true;
FASC.total.push(s);
dup=FASC.dup[s];
$m=FASC.$factory(s,true);
for(i=0;i<dup.length;i++){
$e=dup[i];
$e.before((i?$m.clone():$m));}
total[s]=false;}
if(lapsus){
FASC.flag();
}else{
FASC.dup=false;}
total=FASC.filter(total);
for(s in total){
$e=total[s];
FASC.total.push(s);
if(learn){
$m=FASC.$factory(FASC.cfg.fair(s),false);
$e.before($m);}}
};
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>fragmentAnchors/r.js