MediaWiki:Gadget-annotationPair.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
 /// Gadget-annotationPair.js
 // Connect related markers and annotation.
 // PerfektesChaos@de.wikipedia 2024
 /// @license: CC-by-sa/4.0 GPLv3
 // <nowiki>
 /* global window: false */
 /* jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
  laxbreak:true,
  nocomma:true, strict:true, undef:true, unused:true */
 (function(mw,$){
 "use strict";

 varGLOBAL={signature:"annotationPair",
 signA:"a",
 signM:"m",
 k:0,
 recent:false
 };



 functionflip(event){
 // Handler for annotation click
 // Precondition:
 // event -- Event object
 // event.data -- (Array) [ pair name, fallback id ]
 // Uses:
 // > GLOBAL.recent
 vari,shift,stem;
 if(typeofevent==="object"&&event){
 if(typeofevent.preventDefault==="function"){
 event.preventDefault();
 }
 if(typeofevent.stopPropagation==="function"){
 event.stopPropagation();
 }
 }
 if(GLOBAL.recent&&
 event.data[0]===GLOBAL.recent[0]){
 shift=GLOBAL.recent[1];
 }
 shift=shift||event.data[1];
 stem=window.location.href;
 i=stem.indexOf("#");
 if(i>0){
 stem=stem.substring(0,i);
 }
 window.location.href=stem+"#"+shift;
 }// flip()



 functionfired(event){
 // Handler for marker click
 // Precondition:
 // event -- Event object
 // event.data -- (Array) [ pair name, back id ]
 // Uses:
 // < GLOBAL.recent
 GLOBAL.recent=[event.data[0],event.data[1]];
 }// fired()



 functionfriends(apply){
 // Process one group
 // Precondition:
 // apply -- object, mapping ID to Array of elements
 // Uses:
 // > GLOBAL.signA
 // > GLOBAL.signM
 // >< GLOBAL.k
 // (flip)
 // (fired)
 vari,s,s0,set,si,sign,start,t,$a,$e;
 GLOBAL.k++;
 start=GLOBAL.k+"-";
 for(sinapply){
 t=apply[s];
 $e=t[0];
 if($e&&
 typeoft[1]==="object"){
 set=start+s;
 sign=GLOBAL.sign+set+"-";
 s0=sign+"0";
 si=sign+"1";
 $a=$("<a>");
 $a.addClass(GLOBAL.signA)
 .attr({"href":"#"})
 .on("click",
 [set,si],
 flip);
 $e.before($a);
 $e.detach();
 $a.append($e);
 $a.parent().attr({"id":s0});
 s0="#"+s0;
 for(i=1;i<t.length;i++){
 $e=t[i];
 $a=$("<a>");
 si=sign+i;
 $a.addClass(GLOBAL.signM)
 .attr({"href":s0,
 "id":si})
 .on("click",
 [set,si],
 fired);
 $e.before($a);
 $e.detach();
 $a.append($e);
 }// for i
 }
 }// for s in apply
 }// friends()



 functionfull($all){
 // Process elements
 // Precondition:
 // $all -- all elements in scope
 // Uses:
 // > GLOBAL.signM
 // > GLOBAL.signA
 // friends()
 varn=$all.length,
 $e=$all.eq(0),
 start=($e.data(GLOBAL.signM)?GLOBAL.signM
 :GLOBAL.signA),
 targets={},
 i,lead,loop,s,sign,t;
 for(i=0;i<n;i++){
 $e=$all.eq(i);
 sign=($e.data(GLOBAL.signM)?GLOBAL.signM
 :GLOBAL.signA);
 if(sign===start){
 if(!lead){
 loop=false;
 }
 }else{
 lead=false;
 }
 if(!loop){
 if(i){
 friends(targets);
 targets={};
 }
 lead=true;
 loop=true;
 }
 s=$e.data(sign);
 if(typeofs==="string"){
 s=s.trim();
 }
 if(s){
 if(typeoftargets[s]==="object"){
 t=targets[s];
 }else{
 t=[false];
 }
 if(sign===GLOBAL.signA){
 if(!t[0]){
 t[0]=$e;
 }
 }else{
 t.push($e);
 }
 targets[s]=t;
 }
 $e.attr("data-"+sign,null);
 }// for i
 friends(targets);
 }// full()



 functionfurnish(){
 // Start execution
 // Precondition:
 // DOM ready
 // Uses:
 // > GLOBAL.signature
 // >< GLOBAL.signA
 // >< GLOBAL.signM
 // < GLOBAL.sign
 // full()
 var$got;
 GLOBAL.sign=GLOBAL.signature.toLowerCase()+"-";
 GLOBAL.signA=GLOBAL.sign+GLOBAL.signA;
 GLOBAL.signM=GLOBAL.sign+GLOBAL.signM;
 $got=$("[ data-"+GLOBAL.signA+"], "+
 "[ data-"+GLOBAL.signM+"]");
 if($got.length){
 full($got);
 }
 }// furnish()



 $(furnish);
 }(window.mediaWiki,window.jQuery));
 // </nowiki>
Abgerufen von „https://de.wikipedia.org/w/index.php?title=MediaWiki:Gadget-annotationPair.js&oldid=250123203"