User:DatRoot/Scripts/RichRefTooltips.js

/*
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;
}();});

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.