User:DatRoot/Scripts/RichRefTooltips.js
Appearance
< User:DatRoot | Scripts
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:DatRoot/Scripts/RichRefTooltips. |
/*
RichRefTooltips
Adds rich html tooltips to reference subscripts in mainspace articles.
It takes the html from the corresponding footnote, therefore giving
clickable links.
This script is still in beta but seems to work ok. Works for me in latest versions of IE, Firefox & Opera.
To use add:
importScript("User:DatRoot/Scripts/RichRefTooltips.js");
to your js file. You can also customise the delay for showing/hiding the tooltip by adding underneath:
addOnloadHook(function() {
DatRoot.RichRefTooltips.showDelay = 400;
DatRoot.RichRefTooltips.hideDelay = 400;
});
substituting in the values you want (defaults are 400ms).
*/
importScript("User:DatRoot/Scripts/Common.js");
addOnloadHook(function(){ DatRoot.RichRefTooltips = function()
{
var obj = DatRoot.createContextFloater();
if(wgNamespaceNumber == 0 && wgAction == "view")
{
obj.onShow = function()
{
var linkElem = obj.sourceElement.getElementsByTagName("a")[0];
if(linkElem)
{
linkElem.title = "";
// Get footnote id from link href and add html content to link tooltip
var linkHref = linkElem.href;
var noteElem =
document.getElementById(linkHref.substr(linkHref.indexOf("#") + 1));
if(noteElem)
{
var dispElem = obj.displayElement;
dispElem.innerHTML = noteElem.innerHTML;
// Remove the first child, which is always the caret
dispElem.removeChild(dispElem.firstChild);
// Remove from the front all superscript links
// (actually just hide them for ease & to save time)
for(var node = dispElem.firstChild; node != null; node = node.nextSibling)
{
if(node.nodeType == 3) continue;
if(node.firstChild && node.firstChild.nodeName == "SUP")
node.style.display = "none";
else break;
}
}
}
};
DatRoot.addOnloadHook(function()
{
var refElems =
getElementsByClassName(DatRoot.getArticleElement(), "SUP", "reference");
for(var i = 0; i < refElems.length; i++)
{
obj.applyToElement(refElems[i]);
}
}, "RichRefToolTips");
}
return obj;
}();});