Ero sivun ”Käyttäjä:Erkkimon/monobook.js” versioiden välillä
ApoWikistä
p (testataan) |
p (Erkkimon siirsi sivun Käyttäjä:Tom Himanen/monobook.js uudelle nimelle Käyttäjä:Erkkimon/monobook.js luomatta ohjausta: Siirretty automaattisesti tunnukselta ”Tom Himanen” tunnukselle ”Erkkimon”) |
||
(2 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 1: | Rivi 1: | ||
function showFootnote(evnt) { | |||
var e = window.event ? window.event : evnt; | |||
var obj = window.event ? window.event.srcElement : evnt.target; | |||
// Is this link a ref tag | |||
if(obj.tagName != "A") return; | |||
if(!obj.hash) return; | |||
if(obj.hash.substr(0,11) != "#_note-") return; | |||
if(obj.parentNode.className != "reference") return; | |||
// Is there's a footnote to display? | |||
// Someone may have forgotten the <references/> tag | |||
var footnote_id = obj.hash.substr(1); | |||
if(!document.getElementById(footnote_id)) return; | |||
// Good, hide the popup, if it isn't already | |||
footnote.style.display = "none"; | |||
// Decide where to put the popup | |||
var window_width = document.body.clientWidth; | |||
var horizontal_position = e.clientX; | |||
var vertical_position = e.clientY; | |||
var horizontal_scroll, vertical_scroll; | |||
if (document.all) { | |||
var dObj = typeof document.documentElement.scrollLeft == 'undefined' ? | |||
document.body : document.documentElement; | |||
horizontal_scroll = dObj.scrollLeft; | |||
vertical_scroll = dObj.scrollTop; | |||
} else { | |||
horizontal_scroll = window.pageXOffset; | |||
vertical_scroll = window.pageYOffset; | |||
} | |||
footnote.style.top = (vertical_scroll + vertical_position - 13) + "px"; | |||
if(horizontal_position > (window_width / 2)) { | |||
footnote.style.right = (horizontal_scroll + window_width - horizontal_position - 13) + "px"; | |||
footnote.style.left = ""; | |||
} else { | |||
footnote.style.right = ""; | |||
footnote.style.left = (horizontal_position - 13) + "px"; | |||
} | |||
// Fetch the footnote text and remove the unnecessary back link(s) | |||
// This is a little messy as there's no containing tags | |||
var fn_text = document.getElementById(footnote_id).innerHTML; | |||
fn_text = fn_text.replace(/^.*<a[^>]*href="#cite_ref-.*?<\/a> */i, ""); // " | |||
// Insert the footnote text | |||
footnote.innerHTML = fn_text; | |||
//Make the popup visible | |||
footnote.style.display = ""; | |||
} | |||
function hideFootnote(evnt) { | |||
var obj = window.event ? window.event.srcElement : evnt.target; | |||
// No point in going on if popup is already hidden | |||
if(footnote.style.display == "none") return; | |||
// Search the tree to see where the curser is | |||
var depth = 0; // no need to search too much | |||
while(obj && obj.parentNode) { | |||
if(obj.id == "footnote" || obj.id.substr(0, 9) == "cite_ref-") { return; } | |||
if(depth > 3) break; | |||
obj = obj.parentNode; | |||
depth++; | |||
} | |||
footnote.style.display = "none"; | |||
} | |||
// Set up the float element | |||
var footnote = document.createElement("DIV"); | |||
footnote.id = "footnote"; | |||
footnote.style.display = "none"; | |||
footnote.style.position = "absolute"; | |||
footnote.style.zIndex = 500; | |||
footnote.style.border = "1px solid black"; | |||
footnote.style.backgroundColor = "lightyellow"; | |||
footnote.style.maxWidth = "450px"; | |||
footnote.style.textAlign = "justify"; | |||
footnote.style.padding = "5px"; | |||
footnote.style.fontSize = "10pt"; | |||
addOnloadHook( function () { document.body.appendChild(footnote) } ); | |||
// Add events | |||
addHandler(document, "mouseover", showFootnote); | |||
addHandler(document, "mousemove", hideFootnote); |
Nykyinen versio 8. joulukuuta 2014 kello 22.08
function showFootnote(evnt) {
var e = window.event ? window.event : evnt;
var obj = window.event ? window.event.srcElement : evnt.target;
// Is this link a ref tag
if(obj.tagName != "A") return;
if(!obj.hash) return;
if(obj.hash.substr(0,11) != "#_note-") return;
if(obj.parentNode.className != "reference") return;
// Is there's a footnote to display?
// Someone may have forgotten the <references/> tag
var footnote_id = obj.hash.substr(1);
if(!document.getElementById(footnote_id)) return;
// Good, hide the popup, if it isn't already
footnote.style.display = "none";
// Decide where to put the popup
var window_width = document.body.clientWidth;
var horizontal_position = e.clientX;
var vertical_position = e.clientY;
var horizontal_scroll, vertical_scroll;
if (document.all) {
var dObj = typeof document.documentElement.scrollLeft == 'undefined' ?
document.body : document.documentElement;
horizontal_scroll = dObj.scrollLeft;
vertical_scroll = dObj.scrollTop;
} else {
horizontal_scroll = window.pageXOffset;
vertical_scroll = window.pageYOffset;
}
footnote.style.top = (vertical_scroll + vertical_position - 13) + "px";
if(horizontal_position > (window_width / 2)) {
footnote.style.right = (horizontal_scroll + window_width - horizontal_position - 13) + "px";
footnote.style.left = "";
} else {
footnote.style.right = "";
footnote.style.left = (horizontal_position - 13) + "px";
}
// Fetch the footnote text and remove the unnecessary back link(s)
// This is a little messy as there's no containing tags
var fn_text = document.getElementById(footnote_id).innerHTML;
fn_text = fn_text.replace(/^.*<a[^>]*href="#cite_ref-.*?<\/a> */i, ""); // "
// Insert the footnote text
footnote.innerHTML = fn_text;
//Make the popup visible
footnote.style.display = "";
}
function hideFootnote(evnt) {
var obj = window.event ? window.event.srcElement : evnt.target;
// No point in going on if popup is already hidden
if(footnote.style.display == "none") return;
// Search the tree to see where the curser is
var depth = 0; // no need to search too much
while(obj && obj.parentNode) {
if(obj.id == "footnote" || obj.id.substr(0, 9) == "cite_ref-") { return; }
if(depth > 3) break;
obj = obj.parentNode;
depth++;
}
footnote.style.display = "none";
}
// Set up the float element
var footnote = document.createElement("DIV");
footnote.id = "footnote";
footnote.style.display = "none";
footnote.style.position = "absolute";
footnote.style.zIndex = 500;
footnote.style.border = "1px solid black";
footnote.style.backgroundColor = "lightyellow";
footnote.style.maxWidth = "450px";
footnote.style.textAlign = "justify";
footnote.style.padding = "5px";
footnote.style.fontSize = "10pt";
addOnloadHook( function () { document.body.appendChild(footnote) } );
// Add events
addHandler(document, "mouseover", showFootnote);
addHandler(document, "mousemove", hideFootnote);