User:PerfektesChaos/js/catTreeToggling/r.js

/// Toggle all CategoryTree elements /// 2024-02-27 PerfektesChaos@de.wikipedia /// Documentation:w:en:User:PerfektesChaos/js/catTreeToggling /// Fingerprint:#0#C241B151# /// @license:CC-by-sa/4.0 GPLv3 /// (function(mw,$){ "use strict"; var Version=1.1,Signature="catTreeToggling",THIS={ct:{sect:".CategoryTreeSection",sel:".CategoryTreeToggleHandlerAttached",stta:"aria-expanded",sttc:"false",stte:"true" },doc:{site:"w:en",support:"User:PerfektesChaos/js/"+Signature},gui:{box:{"background-color":"#D0D0D0", "border-color":"#808080", "border-radius":"6px", "border-style":"solid", "border-width":"3px", "display":"inline-block", "margin-bottom":"1em", "margin-left":"1em", "margin-right":"1em", "padding":"0.3em"}, clp:["54","Blue_Fire.svg","collapse"],exp:["6d","Blue_Fire_upsidedown.svg","expand"],img:18 } }; function $file(address,appearance){ var $r=$(" "); $r.attr({"src":"https://upload.wikimedia.org/wikipedia/commons/thumb/"+address[0].substr(0,1)+"/"+address[0]+"/"+address[1]+"/"+appearance+"px-"+address[1]+".png"}); return $r;} function fake(ask){ var $do=THIS.$ct.find(THIS.ct.sel+":visible"),i,$h; for(i=$do.length-1;i>=0;i--){ $h=$do.eq(i); if($h.attr(THIS.ct.stta)===ask){ $h.click;}}} function feed{ fake(THIS.ct.sttc);} function fewer{ fake(THIS.ct.stte);} function fiat($area){ var $e=$(" "),hdls=[feed,fewer],pics=["exp","clp"],i,s,$img; if(typeof THIS.ltr!=="boolean"){ THIS.ltr=($("html").attr("dir")!=="rtl");} for(i=0;i<2;i++){ s=pics[i]; $img=$file(THIS.gui[s],THIS.gui.img); $img.attr({id:THIS.sel+s.substr(0,1),role:"button",title:THIS.gui[s][2]}).click(hdls[i]).css({"cursor":"pointer"}); $e.append($img);} $e.attr({id:THIS.sel+"box",title:Signature+" "+Version}).css(THIS.gui.box).css("float",(THIS.ltr?"right":"left")); $area.prepend($e);} function fire($area){ THIS.$ct=$area.find(THIS.ct.sect); if(THIS.$ct.length){ if(typeof THIS.sel!=="string"){ THIS.sign=Signature.toLowerCase; THIS.sel="gadget-"+THIS.sign+"-";} fiat($area);}} function first{ var env,rls,launch; THIS.signature="ext.gadget."+Signature; if(mw.loader.getState(THIS.signature)!=="ready"){ rls={}; rls[THIS.signature]="ready"; mw.loader.state(rls); env=mw.config.get(["wgAction","wgCanonicalSpecialPageName","wgNamespaceNumber","wgPageContentModel"]); switch(env.wgAction){ case "edit": case "submit": case "view": if(env.wgPageContentModel==="wikitext"){ if(env.wgNamespaceNumber<-1){ launch=(env.wgCanonicalSpecialPageName==="CategoryTree"); }else{ launch=true;}} break;} if(launch){ mw.hook("wikipage.content").add(fire);} THIS.pub={doc:""+THIS.doc.site+":"+THIS.doc.support+"",type:Signature,vsn:Version}; mw.hook(Signature+".ready").fire(THIS.pub);}} first; }(window.mediaWiki,window.jQuery)); /// EOF catTreeToggling.js