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

Content deleted Content added
1.4
2.7
 
(11 intermediate revisions by the same user not shown)
Line 1:
/// Gadget/fragmentAnchors/r.js
/// 20162021-0407-2030 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#883B23B1378F0A71#
/// Documentation:[[w:en:User:PerfektesChaos/js/fragmentAnchors]]
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=12.47,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){
if(typeof mw.libs[FANCY]!=="object"||!mw.libs[FANCY]){
mw.hook("wikipage.content").remove(facet);
mw.libs[FANCY]={};}
FASC.$content=$area;
mw.libs[FANCY].type=FANCY;
if(FASC.locked){
FANCY=mw.libs[FANCY];
FASC.$exclude=false;
function feed(){
}else{
mw.hook("wikipage.content").add(FASC.furnish);}
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(["jquery.tipsyoojs","oojs-ui-core","oojs-ui-widgets"],feedfacility);}
function fire(){
var signature="ext.gadget."+FANCY.type,env,rls;
FANCY.doc="[[w:en:User:PerfektesChaos/js/"+FANCY.type+"]]";
if(mw.loader.getState(signature)!=="ready"){
rls={};
mw.loader.state(signature,"ready");
rls[signature]="ready";
env=mw.config.get(["wgAction","wgPageContentModel"]);
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.vsn=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;
FASC.cfg.live=false;
mw.loader.using(["user","mediawiki.util"],FASC.fire);}}}
FANCY.fetch=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 45 ⟶ 70:
return r;
};
FANCYEXPORT.fire=function(){
var r=FASC.cfg.live;
if(r){
fiat();}
return r;
};
FASC.cfg.element=function(attend,attributes,anchor){
return mw.html.element(attend,attributes,anchor);
};
FASC.cfg.escape=function(anchor){
return mw.html.escape(anchor);
};
FASC.cfg.fair=function(anchor,allow){
var r=anchor.replace(/_/g," "),s;
if(allow){
if(typeof FASC.wikiAnchor!=="object"){
r=anchor;
}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;
FASC.$body=$("body");
if(typeof FANCY.large==="boolean"){
FASC.large=FANCY.large;}
Line 84 ⟶ 118:
if(typeof FANCY.lock==="boolean"){
lock=FANCY.lock;}
FASC.learn=true;
if(!(lock||launch)){
portlet=mw.util.addPortletLink("p-tb","#"," ","t-"+FASC.sign);
Line 89 ⟶ 124:
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){
Line 102 ⟶ 138:
var m=(alert||augment?1:0),n=(alert?20:12),s=FASC["source"+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 sign=anchor.substr(1),lapse=(!FASC.fine(sign)),mode=(alert?1:(lapse?2:0)),$rbadge=FASC.badges[about.mode],show,$i,$sr;
if(!$rbadge){
badge={};
$i=FASC.$facet(alert,lapse);
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(" ");
$sbadge.text$r=$(" <span>");
badge.$r.append(badge.$s);
$r=$("<a>");
FASC.badges[about.mode]=badge;}
$r.attr({href:"#"});
$r=badge.append($sr.clone();
$ri=badge.append($i.clone();
$r.append($i).append(badge.$s.clone());
$i.hover(function(activity){
FASC.badges[mode]=$r;}
FASC.flip(activity,about,0,true);
$r=$r.clone();
return false;
$i=$r.children();
},function(activity){
if(lapse){
FASC.flip(activity,about,0,false);
show=FASC.cfg.element("span",{style:"background-color:#FFFF00;color:#FF0000;font-weight:bold;margin:0.2em;padding:0.4em;"},sign);
return false;
}else{
});
if(sign){
$i.click(function(activity){
show=FASC.cfg.escape(sign);
FASC.flip(activity,about,1);
}else{
return false;
show=FASC.cfg.element("span",{style:"margin:0.2em;width:2em;"},"  ");}}
});
$i.attr({"data-id":sign,"title":show});
about.$span=$r;
$i.tipsy({gravity:"s",html:true,opacity:0.8});
$r.click(FASC.flip);
return $r;
};
Line 147 ⟶ 184:
$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});
Line 160 ⟶ 200:
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;
};
Line 176 ⟶ 283:
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)){
Line 187 ⟶ 294:
if(typeof FASC.large!=="boolean"){
FASC.large=false;}
if(typeof FASC.unStart!=="object"){
FASC.unStart=false;}
FASC.reFine=false;
FASC.scope=FASC.sign+"-inner";
Line 207 ⟶ 316:
$li.text("−"+FASC.want[s]+"× "+s);
$ul.append($li);}
$box.css({"border":"#FF0000 2px solid",
"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(1);
$img.trigger($.Event("mouseleave"));
sel=$img.attr("data-id");
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]"),dup,i,lapsus,s,$e,$inner,$m;
FASC.bubbles=[];
FASC.dup={};
FASC.total=[];
FASC.want=false;
$("."+FASC.show).remove();
if(!FASC.large&&$area){
FASC.$content=$area;
}else{
FASC.$content=false;}
for(i=0;i<$total.length;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 263 ⟶ 382:
$e=dup[i];
if($e){
$m=FASC.$factoryfile(s,true,$e);}}
$e.before($m);}}
total[s]=false;}
if(!lapsus){
Line 275 ⟶ 393:
if(s!=="#"){
$e.addClass(FASC.scope);
if(typeof total[s]!=="object"&&FASC.filter(s)){
$e.before(FASC.$failure(s));
if(!FASC.want){
Line 285 ⟶ 403:
if(FASC.dup||FASC.want){
FASC.flag();}
total=FASC.filterfamily(total);
for(s in total){
if(typeof total[s]==="object"){
FASC.total.push(s);
if(FASC.learn){
FASC.file(FASC.cfg.fair(s),false,total[s]);}}}
$e=total[s];
$m=FASC.$factory(FASC.cfg.fair(s),false);
$e.before($m);}}}
};
fire();