Jump to content

User:Miles/monobook.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.
document.write('<'+'script type="text/javascript" src="http://wiki.riteme.site/w/index.php?title=User:Miles/jquery-1.1.3.js&action=raw&ctype=text/javascript"><'+'/script>');

var mk_activeFootnote;

$(function () {$('.reference a').click(function (event) {
    var id = this.href.substr(this.href.indexOf('#')+1);
    if (mk_activeFootnote) document.body.removeChild(mk_activeFootnote);
    var li = document.getElementById(id);
    var footnote = document.createElement('div');
    footnote.setAttribute('class', 'mk-footnote');
    var child = li.firstChild;
    // remove backreferences:
    if (child.nodeType == document.TEXT_NODE) { // first node is "^ "
        // next node is backreference
        child = child.nextSibling.nextSibling;
        while (child && child.nextSibling && 
               child.nextSibling.nodeName.toLowerCase() == 'a' && 
               child.nextSibling.getAttribute('href').charAt(0) == '#')
            child = child.nextSibling.nextSibling;
    } else { // first node is '<b><a href="#...">^</a></b>'
        child = child.nextSibling;
    }
    while (child) {
        footnote.appendChild(child.cloneNode(true));
        child = child.nextSibling;
    }
    mk_activeFootnote = footnote;
    document.body.appendChild(footnote);
    footnote.style.top = event.pageY + 'px';
    footnote.style.left = (event.pageX-150) + 'px';
    // Add close link:
    closeLink = document.createElement('a');
    closeLink.appendChild(document.createTextNode('[X]'));
    closeLink.setAttribute('class', 'mk-closefootnote');
    closeLink.onclick = function() {
        document.body.removeChild(mk_activeFootnote);
        mk_activeFootnote = null;
    }
    footnote.appendChild(closeLink);
    event.preventDefault()
})});