Ero sivun ”Käyttäjä:Erkkimon/monobook.js” versioiden välillä

ApoWikistä
p (referenssisydeemi)
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”)
 
(9 välissä olevaa versiota samalta käyttäjältä ei näytetä)
Rivi 1: Rivi 1:
{{subst:Käyttäjä:Mzlla/getextrabuttons}}
function showFootnote(evnt) {
function showFootnote(evnt) {
var e = window.event ? window.event : evnt;
var e = window.event ? window.event : evnt;
var obj = window.event ? window.event.srcElement : evnt.target;
var obj = window.event ? window.event.srcElement : evnt.target;
 
// Is this link a ref tag
// Is this link a ref tag
if(obj.tagName != "A") return;
if(obj.tagName != "A") return;
if(!obj.hash) return;
if(!obj.hash) return;
if(obj.hash.substr(0,11) != "#cite_note-") return;
        if(obj.hash.substr(0,11) != "#_note-") return;
if(obj.parentNode.className != "reference") return;
if(obj.parentNode.className != "reference") return;
 
 
// Is there's a footnote to display?
// Is there's a footnote to display?
// Someone may have forgotten the <references/> tag
// Someone may have forgotten the <references/> tag
var footnote_id = obj.hash.substr(1);
var footnote_id = obj.hash.substr(1);
if(!document.getElementById(footnote_id)) return;
if(!document.getElementById(footnote_id)) return;
 
// Good, hide the popup, if it isn't already
// Good, hide the popup, if it isn't already
footnote.style.display = "none";
footnote.style.display = "none";
// Decide where to put the popup
// Decide where to put the popup
var window_width = document.body.clientWidth;
var window_width = document.body.clientWidth;
Rivi 23: Rivi 24:
var vertical_position = e.clientY;
var vertical_position = e.clientY;
var horizontal_scroll, vertical_scroll;
var horizontal_scroll, vertical_scroll;
 
if (document.all) {
if (document.all) {
var dObj = typeof document.documentElement.scrollLeft == 'undefined' ?
var dObj = typeof document.documentElement.scrollLeft == 'undefined' ?
Rivi 33: Rivi 34:
vertical_scroll = window.pageYOffset;
vertical_scroll = window.pageYOffset;
}
}
 
footnote.style.top = (vertical_scroll + vertical_position - 13) + "px";
footnote.style.top = (vertical_scroll + vertical_position - 13) + "px";
 
if(horizontal_position > (window_width / 2)) {
if(horizontal_position > (window_width / 2)) {
footnote.style.right = (horizontal_scroll + window_width - horizontal_position - 13) + "px";
footnote.style.right = (horizontal_scroll + window_width - horizontal_position - 13) + "px";
Rivi 43: Rivi 44:
footnote.style.left = (horizontal_position - 13) + "px";
footnote.style.left = (horizontal_position - 13) + "px";
}
}
// Fetch the footnote text and remove the unnecessary back link(s)
// Fetch the footnote text and remove the unnecessary back link(s)
// This is a little messy as there's no containing tags
// This is a little messy as there's no containing tags
var fn_text = document.getElementById(footnote_id).innerHTML;
var fn_text = document.getElementById(footnote_id).innerHTML;
fn_text = fn_text.replace(/^.*<a[^>]*href="#cite_ref-.*?<\/a> */i, ""); // "
fn_text = fn_text.replace(/^.*<a[^>]*href="#cite_ref-.*?<\/a> */i, ""); // "
// Insert the footnote text
// Insert the footnote text
footnote.innerHTML = fn_text;
footnote.innerHTML = fn_text;
 
//Make the popup visible
//Make the popup visible
footnote.style.display = "";
footnote.style.display = "";
}
}
 
function hideFootnote(evnt) {
function hideFootnote(evnt) {
var obj = window.event ? window.event.srcElement : evnt.target;
var obj = window.event ? window.event.srcElement : evnt.target;
// No point in going on if popup is already hidden
// No point in going on if popup is already hidden
if(footnote.style.display == "none") return;
if(footnote.style.display == "none") return;
// Search the tree to see where the curser is
// Search the tree to see where the curser is
var depth = 0; // no need to search too much
var depth = 0; // no need to search too much
Rivi 70: Rivi 71:
depth++;
depth++;
}
}
footnote.style.display = "none";
footnote.style.display = "none";
}
}
 
// Set up the float element
// Set up the float element
var footnote = document.createElement("DIV");
var footnote = document.createElement("DIV");
Rivi 86: Rivi 87:
footnote.style.padding = "5px";
footnote.style.padding = "5px";
footnote.style.fontSize = "10pt";
footnote.style.fontSize = "10pt";
 
addOnloadHook( function () { document.body.appendChild(footnote) } );
addOnloadHook( function () { document.body.appendChild(footnote) } );
 
// Add events
// Add events
addHandler(document, "mouseover", showFootnote);
addHandler(document, "mouseover", showFootnote);
addHandler(document, "mousemove", hideFootnote);
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);