User:PerfektesChaos/js/fragmentAnchors/r.js: Difference between revisions

Content deleted Content added
1.0
 
2.7
 
(15 intermediate revisions by the same user not shown)
Line 1:
/// Gadget-/fragmentAnchors/?r.js
/// 20162021-0207-2630 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#F836EFC3378F0A71#
/// Documentation:[[w:en:User:PerfektesChaos/js/fragmentAnchors]]
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=12.07,FANCY="fragmentAnchors",FASC={cfg:{},siblings:"error-repeated-id",source0:"6/62/Anchor_pictogram.svg",source1:"d/d6/Anchor_pictogram_red.svg",unStart:["wpTextbox","/maplink/","Anker:"],vsn:Version
},EXPORT={},OO;
};
function facet($area){
mw.hook("wikipage.content").remove(facet);
FASC.$content=$area;
if(FASC.locked){
FASC.$exclude=false;
}else{
FASC.$exclude=FASC.$content.find("form");}
FASC.furnish();}
function facility(){
OO=window.OO;
if(FASC.large){
FASC.$content=false;
FASC.$exclude=false;
FASC.furnish();
}else{
mw.hook("wikipage.content").add(facet);}}
function fiat(){
FASC.cfg.live=false;
if(typeof FASC.cfg.$portlet==="object"){
FASC.cfg.$portlet.hide();}
mw.loader.using(["oojs","oojs-ui-core","oojs-ui-widgets"],facility);}
function fire(){
var signature="ext.gadget."+FANCY,env,rls;
if(mw.loader.getState(signature)!=="ready"){
rls={};
rls[signature]="ready";
mw.loader.state(rls);
if(typeof mw.libs[FANCY]!=="object"||!mw.libs[FANCY]){
mw.libs[FANCY]={};}
mw.libs[FANCY].type=FANCY;
FANCY=mw.libs[FANCY];
FANCY.fetchvsn=function(){Version;
FANCY.doc="w:en:User:PerfektesChaos/js/"+FANCY.type;
FANCY.doc="[["+FANCY.doc+"]]";
FANCY.fetch=EXPORT.fetch;
FANCY.fire=EXPORT.fire;
env=mw.config.get(["wgAction","wgPageContentModel"]);
FASC.cfg.live=false;
if(env.wgPageContentModel==="wikitext"){
FASC.locked=(env.wgAction==="view");
FASC.sign=FANCY.type;
mw.loader.using(["user","mediawiki.util"],FASC.fire);}}}
function freshed(){
FASC.cfg.live=true;
FASC.cfg.$portlet.show();}
EXPORT.fetch=function(){
var dup,r,s;
if(FASC.cfg.live){
FASC.furnish(learn=false,true);
fiat();
if(FASC.dup){
dup={};
Line 21 ⟶ 65:
}else{
dup=false;}
r=[FASC.total,dup,FASC.want];
}else{
r=false;}
return r;
};
EXPORT.fire=function fiat(){
var r=FASC.cfg.$portlet.hide()live;
if(r){
mw.hook("wikipage.content").add(FASC.furnish);}
fiat();}
function fire(){
return r;
FANCY.vsn=Version;
};
FANCY.doc="[[w:en:User:PerfektesChaos/js/"+FANCY.type+"]]";
FASC.cfg.escape=function(anchor){
mw.loader.state("ext.gadget."+FANCY.type,"ready");
return mw.html.escape(anchor);
FASC.sign=FANCY.type;
};
FASC.cfg.live=false;
FASC.cfg.fair=function(anchor,allow){
mw.loader.using(["user","mediawiki.util","jquery.tipsy"],FASC.fire);}
var r,s;
FASC.cfg.fair=function(anchor){
if(allow){
var r=anchor.replace(/_/g," "),s;
r=anchor;
if(typeof FASC.wikiAnchor!=="object"){
}else{
r=anchor.replace(/_/g," ");}
if(typeof FASC.cfg.wikiAnchor!=="object"){
s="[0-9A-Fa-f]";
s="\\.("+s+s+")";
FASC.cfg.wikiAnchor=new RegExp(s,"g");}
try{
s=r.replace(FASC.cfg.wikiAnchor,"%$1");
r=decodeURIComponent(s);
}catch(e){
}
return r;
};
FASC.cfg.familiar=function(anchor,$at){
var s=FASC.cfg.fair(anchor,true),r,$e;
if(s!==anchor&&$at.is("span")){
$e=$at.next();
r=($e.is("span")&&"#"+$e.attr("id")===s);
if(!r){
$e=$at.prev();
r=($e.is("span")&&"#"+$e.attr("id")===s);}}
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 launch,lock,portlet;
var portlet=mw.util.addPortletLink("p-tb","#",String.fromCharCode(8201),"t-"+FASC.sign);
FASC.$body=$("body");
if(typeof FANCY.large==="boolean"){
FASC.large=FANCY.large;}
if(typeof FANCY.launch==="boolean"){
launch=FANCY.launch;}
if(typeof FANCY.lock==="boolean"){
lock=FANCY.lock;}
FASC.learn=true;
if(!(lock||launch)){
portlet=mw.util.addPortletLink("p-tb","#"," ","t-"+FASC.sign);
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("wikipage.content").add(freshed);}
mw.hook(FANCY.type+".ready").fire(FANCY);
if(launch){
FASC.cfg.live=true;
fiat();
}else{
FASC.cfg.live=true;}
};
FASC.cfg.$flag=function(){
return $("h1").eq(0);
};
FASC.$facet=function(alert,augment){
var m=(alert||augment?1:0),n=(alert?20:12),s=FASC["source"+(alert?1:0)m],$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"});},
"padding":"1px"});}
return $r;
};
FASC.$factory=function(anchor,alertabout){
var mode=(alert?1:0),$rbadge=FASC.badges[about.mode],$i,$sr;
if(!$rbadge){
badge={};
$i=FASC.$facet(alert);
badge.$i=FASC.$facet((about.mode===1),(about.mode===2));
$i.addClass(FASC.show);
badge.$i.addClass(FASC.show);
if(alert){
if(about.mode===1){
$i.addClass(FASC.siblings);}
badge.$i.addClass(FASC.siblings);}
$i.attr({rel:"tipsy"});
badge.$s=$("<span>");
badge.$s.css({"font-size":"25%"}).text(" ");
badge.$r=$("<span>");
badge.$r.append(badge.$s);
FASC.badges[about.mode]=badge;}
$r=badge.$r.clone();
$i=badge.$i.clone();
$r.append($i).append(badge.$s.clone());
$i.hover(function(activity){
FASC.flip(activity,about,0,true);
return false;
},function(activity){
FASC.flip(activity,about,0,false);
return false;
});
$i.click(function(activity){
FASC.flip(activity,about,1);
return false;
});
about.$span=$r;
return $r;
};
FASC.$failure=function(anchor){
var $r=$("<span>"),$s=$("<span>");
$s.css({"white-space":"nowrap"});
$s.css({"font-size":"25%"});
$s.text(" ");
$r.append($s);
$s=$("<span>");
$s.addClass(FASC.single);
$s.css({"background-color":"#FFFF00",
"border":"#FF0000 2px solid",
"color":"#FF0000",
"font-size":"120%",
"font-weight":"bold",
"padding-left":"0.2em",
"padding-right":"0.2em"});
$s.attr({title:anchor});
$s.text("#");
$r.append($s);
$s=$("<span>");
$s.css({"widthfont-size":"1px25%"});
$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.filterfamily=function(all){
var r={},s,seek,$e;
for(s in all){
if(all[s]){
if(FASC.$content){
if(typeof FASC.reApos!=="object"){
seek="[id=\""+s.substr(1)+"\"]";
FASC.reApos=new RegExp("'","g");}
seek="[id='"+s.substr(1).replace(FASC.reApos,"\\'")+"']";
try{
$e=FASC.$content.find(seek);
if}catch($e.length){
$e=false;}
if($e&&$e.length&&!(FASC.$exclude&&FASC.$exclude.find(seek).length)){
r[s]=$e;}
}else{
r[s]=all[s];}}}
return r;
};
FASC.fiat=function(about,action){
var illusive=0.75,margin=10,options={align:"center",anchor:true,horizontalPosition:"center",padded:false,verticalPosition:"below"},show=about.sign,sign=FASC.sign+(action?"-t":"-i")+about.id,$p=$("<span>"),r;
$p.css({"left":(-0.5*about.$span.innerWidth()-1)+"px",
"position":"relative",
"top":"3px"});
about.$span.append($p);
options.$floatableContainer=$p;
$p=$("<span>");
if(show){
show=(action?"#":"")+FASC.cfg.escape(show);
}else{
show="#";}
if(about.mode===2){
$p.css({"background-color":"#FFFF00",
"color":"#FF0000",
"font-weight":"bold",
"margin":"0.2em",
"padding":"0.4em"}).text(show);
}else{
if(show){
if(action){
show=FASC.cfg.fancy(show);
illusive=0.95;}
$p.css({"color":"#000000",
"font-weight":"normal"}).text(show);
}else{
$p.css({"margin":"0.2em",
"width":"2em"}).text("  ");}}
$p.attr({"id":sign}).addClass(FASC.sign+"-text")
.css({"font-family":"sans-serif",
"font-size":"medium",
"font-style":"normal",
"font-variant":"normal",
"visibility":"hidden"});
FASC.$body.append($p);
$p=$("#"+sign);
options.width=$p.outerWidth()+margin;
$p.detach().css({"visibility":"visible"});
options.$content=$p;
r=new OO.ui.PopupWidget(options);
r.$floatable.attr({"role":"tooltip"}).css({"opacity":illusive,
"padding":"2px",
"text-align":"center"});
FASC.$body.append(r.$floatable);
return r;
};
FASC.file=function(anchor,alert,$a){
var sign=anchor.substr(1),lapse=(!FASC.fine(sign)),mode=(alert?1:(lapse?2:0)),id=FASC.bubbles.length,bubble={id:id,mode:mode,popups:[false,false],sign:sign,live:false,$a:$a,$span:false};
FASC.bubbles.push(bubble);
$a.attr({"title":null});
$a.before(FASC.$factory(bubble));
};
FASC.filter=function(anchor){
var r=true,i,s;
if(FASC.unStart){
for(i=0;i<FASC.unStart.length;i++){
s=FASC.unStart[i];
if(anchor.substr(1,s.length)===s){
r=false;
break;}}}
return r;
};
FASC.fine=function(anchor){
var r=true,i;
if(typeof FASC.reFine!=="object"){
FASC.reFine=[new RegExp("^\\s"),new RegExp("\\s$"),new RegExp("^\\d"),new RegExp("[<>'\"#%\\\\]"),new RegExp("\\?\\?")];}
for(i=0;i<FASC.reFine.length;i++){
if(FASC.reFine[i].test(anchor)){
r=false;
break;}}
return r;
};
FASC.fire=function(){
FASC.badges=[false,false,false];
if(typeof FASC.large!=="boolean"){
FASC.large=false;}
if(typeof FASC.unStart!=="object"){
FASC.unStart=false;}
FASC.reFine=false;
FASC.scope=FASC.sign+"-inner";
FASC.show=FASC.sign+"-mark";
FASC.single=FASC.show+" "+FASC.sign+"-broken";
$(FASC.cfg.fire);
};
Line 128 ⟶ 309:
for(s in FASC.dup){
dup=FASC.dup[s];
$li=$("<ulli>");
$li.text(dup.length+"× "+s);
$ul.append($li);}
for(s in FASC.want){
$box.css({"border":"#FF0000 2px solid","color":"#FF0000",
$li=$("<li>");
"margin-bottom":"1em","margin-top":"1em",
$li.text("−"+FASC.want[s]+"× "+s);
"padding":"1em"});
$ul.append($li);}
$box.attr({id:FASC.sign+"-error-multiples"});
$box.css({"border":"#FF0000 2px solid",
$box.addClass(FASC.show);
"color":"#FF0000",
"margin-bottom":"1em",
"margin-top":"1em",
"padding":"0.5em"});
$box.attr({"id":FASC.sign+"-errors"});
$box.addClass(FASC.show+" error "+FASC.sign+"-errors");
$box.append($ul);
$before.before($box);}
};
FASC.flip=function(activity,about,apply,activate){
var live=about.live,popup=about.popups[apply];
var $that=$(this),sel=$that.attr("original-title"),$img;
if(typeof activity==="object"&&activity){
if(sel){
if(typeof activity.preventDefault==="function"){
$that.attr({"rel":null,"original-title":null});
activity.preventDefault();}
sel="hide";
if(typeof activity.stopPropagation==="function"){
activity.stopPropagation();}}
if(!popup){
popup=FASC.fiat(about,apply);
about.popups[apply]=popup;
if(apply&&!about.popups[0]){
about.popups[0]=FASC.fiat(about,0);}}
if(apply){
about.popups[0].toggle(false);
live=!live;
about.live=live;
popup.toggle(live);
}else if(live){
popup.toggle(false);
}else{
popup.toggle(activate);}
$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,$minner;
FASC.bubbles=[];
FASC.dup={};
FASC.total=[];
FASC.want=false;
$("."+FASC.show).remove();
for(i=0;i<$total.length;i++){
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(FASC.cfg.familiar(s,$e)){
s=false;}
}else{
s=false;}
if(s){
if(typeof total[s]==="object"){
if(typeof FASC.dup[s]!=="object"){
FASC.dup[s]=[total[s]];
total[s]=truenull;}
FASC.dup[s].push($e);
}else{
Line 183 ⟶ 379:
FASC.total.push(s);
dup=FASC.dup[s];
$m=FASC.$factory(s,true);
for(i=0;i<dup.length;i++){
$e=dup[i];
if($e){
$e.before((i?$m.clone():$m));}
FASC.file(s,true,$e);}}
total[s]=false;}
if(!lapsus){
FASC.flag();
}else{
FASC.dup=false;}
total=if(FASC.filter(totallocked);{
$inner=$("a[href^='#']");
for(i=0;i<$inner.length;i++){
$e=$inner.eq(i);
s=$e.attr("href");
if(s!=="#"){
$e.addClass(FASC.scope);
if(typeof total[s]!=="object"&&FASC.filter(s)){
$e.before(FASC.$failure(s));
if(!FASC.want){
FASC.want={};}
if(typeof FASC.want[s]==="number"){
FASC.want[s]=FASC.want[s]+1;
}else{
FASC.want[s]=1;}}}}}
if(FASC.dup||FASC.want){
FASC.flag();}
total=FASC.family(total);
for(s in total){
$e=if(typeof total[s];==="object"){
FASC.total.push(s);
if(FASC.learn){
$m=FASC.$factoryfile(FASC.cfg.fair(s),false,total[s]);}}}
$e.before($m);}}
};
fire();