Jump to content

User:PerfektesChaos/js/logidTooltip/r.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// Gadget/logidTooltip/r.js
/// 2020-08-01 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#41407F27#
/// Documentation:[[w:en:User:PerfektesChaos/js/logidTooltip]]
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.3,LIT={signature:"logidTooltip",source:"0f/Arrow Blue UpperRight 001.svg",search:"&action=edit&redlink=1",selector:"data-mw-logid",npx:16,$body:false,$img:false
},OO;
function filepath(assign){
var s="[a-z0-9]";
if(typeof assign==="string"){
if(typeof LIT.reFile!=="object"){
LIT.reFile=new RegExp("^"+s+s+"/[^a-z][^/#<>{}]+\\.[a-zA-Z]*$");}
if(LIT.reFile.test(assign)){
LIT.source=assign;}}}
function fire(){
var signature="ext.gadget."+LIT.signature,env,launch,rls;
if(mw.loader.getState(signature)!=="ready"){
rls={};
rls[signature]="ready";
mw.loader.state(rls);
LIT.vsn=Version;
LIT.doc="w:en:User:PerfektesChaos/js/"+LIT.signature;
LIT.doc="[["+LIT.doc+"]]";
env=mw.config.get(["wgCanonicalSpecialPageName","wgFormattedNamespaces"]);
switch(env.wgCanonicalSpecialPageName){
case "Log":
case "Recentchanges":
case "Watchlist":
launch=true;
break;
default:
launch=(window.location.search.indexOf(LIT.search)>=0);}
if(launch){
LIT.signed=LIT.signature+"-handle";
LIT.special=env.wgFormattedNamespaces["-1"];
mw.hook(LIT.signature+"-icon").add(filepath);
mw.hook("wikipage.content").add(LIT.furnish);}}}
LIT.$factory=function(assigned,$anchor){
var illusive=0.75,offset=$anchor.offset(),options={anchor:true,padded:true,position:"below",verticalPosition:"below",$floatableContainer:$anchor},shift=LIT.special+":Redirect/logid/"+assigned,$a=$("<a>"),r;
options.width=(12+assigned.length*0.7)+"em";
if(offset.left<0.5*window.innerWidth){
options.align="forwards";
options.horizontalPosition="start";
}else{
options.align="backwards";
options.horizontalPosition="end";}
$a.addClass(LIT.signature+"-text plainlinks").attr({"dir":"ltr",
"href":"/wiki/"+shift,
"id":LIT.signature+"-text-"+assigned,
"lang":"en"}).css({"font-family":"sans-serif",
"font-size":"medium",
"font-style":"normal",
"font-variant":"normal",
"font-weight":"normal",
"white-space":"nowrap"}).text("[["+shift+"]]");
options.$content=$a;
r=new OO.ui.PopupWidget(options);
r.$floatable.attr({"role":"tooltip"}).css({"opacity":illusive,
"padding":"2px",
"text-align":"center"});
LIT.$body.append(r.$floatable);
return r;
};
LIT.fiat=function(){
var $li=$(this),id,re,src,$e;
if(!$li.find("."+LIT.signed).length){
id=$li.attr(LIT.selector);
if(id){
if(!LIT.$img){
re=new RegExp(" +","g");
LIT.source=LIT.source.substr(0,1)+"/"+LIT.source.replace(re,"_");
src="https://upload.wikimedia.org/wikipedia/commons/thumb/"+LIT.source+"/"+LIT.npx+"px-"+LIT.source.substr(5)+".png";
LIT.$img=$("<img>").attr({src:src,height:LIT.npx+"px",width:LIT.npx+"px"});}
$e=LIT.$img.clone().addClass(LIT.signed).attr("title","logidTooltip "+id).css("padding-"+(LIT.ltr?"left":"right"),"6px").click(function(){LIT.fired(id,$e);
});
$li.append($e);}}
};
LIT.fired=function(assigned,$anchor){
if(LIT.$body){
LIT.flip(assigned,$anchor);
}else{
LIT.$body=$("body");
mw.loader.using(["oojs","oojs-ui-core","oojs-ui-widgets"],function(){
LIT.flip(assigned,$anchor);});}
};
LIT.flip=function(assigned,$anchor){
var entry,popup;
if(!OO){
OO=window.OO;
LIT.popups={};}
if(typeof LIT.popups[assigned]==="object"){
entry=LIT.popups[assigned];
popup=entry[0];
}else{
popup=LIT.$factory(assigned,$anchor);
entry=[popup,false];
LIT.popups[assigned]=entry;}
entry[1]=!entry[1];
popup.toggle(entry[1]);
};
LIT.furnish=function($area){
var $entries=$area.find("li["+LIT.selector+"]");
if($entries.length){
if(typeof LIT.ltr!=="boolean"){
LIT.ltr=($("html").attr("dir")!=="rtl");}
$entries.each(LIT.fiat);}
};
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>logidTooltip/r.js