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

Content deleted Content added
1.5
1.6
Line 1:
/// Gadget/fragmentAnchors/r.js
/// 2016-04-20 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#3BBAC2F1255EAC38#
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.56,FANCY="fragmentAnchors",FASC={cfg:{},siblings:"error-repeated-id",source0:"6/62/Anchor_pictogram.svg",source1:"d/d6/Anchor_pictogram_red.svg",unStart:["Anker:","wpTextbox"],vsn:Version
};
if(typeof mw.libs[FANCY]!=="object"||!mw.libs[FANCY]){
Line 11:
mw.libs[FANCY].type=FANCY;
FANCY=mw.libs[FANCY];
function feedfacet($area){
mw.hook("wikipage.content").addremove(FASC.furnishfacet);}
FASC.$content=$area;
FASC.furnish();}
function facility(){
if(!FASC.large&&$area){
FASC.$content=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.tipsy"],feedfacility);}
function fire(){
var signature="ext.gadget."+FANCY.type,env;
Line 30 ⟶ 38:
FASC.cfg.live=false;
mw.loader.using(["user","mediawiki.util"],FASC.fire);}}}
function freshed(){
FASC.cfg.live=true;
FASC.cfg.$portlet.show();}
FANCY.fetch=function(){
var dup,r,s;
if(FASC.cfg.live){
FASC.furnish(learn=false,true);
fiat();
if(FASC.dup){
dup={};
Line 72 ⟶ 84:
FASC.cfg.fancy=function(anchor){
return "[["+anchor+"]]";
};
FASC.cfg.filter=function(anchor){
return(anchor.substr(0,7)!=="#Anker:"&&anchor.substr(0,10)!=="#wpTextbox");
};
FASC.cfg.fire=function(){
Line 84 ⟶ 93:
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 ⟶ 99:
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 160 ⟶ 171:
return $r;
};
FASC.filterfamily=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){
Line 171 ⟶ 182:
}else{
r[s]=all[s];}}}
return r;
};
FASC.cfg.filter=function(anchor){
var r=true,i;
if(FASC.blockStart){
for(i=0;i<FASC.blockStart.length;i++){
r=FASC.blockStart[i];
if(anchor.substr(1,r[1])===r[0]){
r=false;
break;}}}
return r;
};
Line 176 ⟶ 197:
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 184 ⟶ 205:
};
FASC.fire=function(){
var i;
FASC.badges=[false,false,false];
if(typeof FASC.large!=="boolean"){
FASC.large=false;}
if(typeof FASC.unStart==="object"){
FASC.blockStart=[];
for(i=0;i<FASC.unStart.length;i++){
FASC.blockStart.push([FASC.unStart[i],FASC.unStart[i].length+1]);}
}else{
FASC.blockStart=false;}
FASC.reFine=false;
FASC.scope=FASC.sign+"-inner";
Line 231 ⟶ 259:
return false;
};
FASC.furnish=function($area,absent){
var learn=(!absent),total={},$total=$("[id]"),dup,i,lapsus,s,$e,$inner,$m;
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(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 285 ⟶ 309:
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){
$e=total[s];
$m=FASC.$factory(FASC.cfg.fair(s),false);