User:Omegatron/monobook.js/audiopops.js
Appearance
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:Omegatron/monobook.js/audiopops. |
/* <pre> <nowiki> */
/* Popup audio help links */
document.write(
'<st' + 'yle type="text/css"> ' +
' div.audiolinkbox { ' +
' border: 1px solid rgb(170,170,170); ' +
' -moz-border-radius: 1em; ' +
' background-color: white; ' +
' position: absolute; ' +
' margin: -1.2em; ' +
' padding: 0.5em; ' +
' width: 250px; ' +
' display: none; ' +
' /* Just override for now: */ ' +
' font-weight: normal; ' +
' text-decoration: none; ' +
' } ' +
'<' + '/style>'
);
$(function () {
/* Should be renamed */
function lightup () {
this.audioPop.style.display="inline";
}
/* Should be renamed */
function lightout () {
var savedThis=this;
clearInterval(this.lightTimer);
this.lightTimer=setInterval(function(){hideAudioPop(savedThis);}, 2000);
}
function hideAudioPop (caller) {
clearInterval(caller.lightTimer);
caller.audioPop.style.display="none";
caller.audioPop.onmouseout = null;
}
function mouseoverAudioPop () {
var hotspot = this.hotspot;
if (!hotspot) { return; }
clearInterval(hotspot.lightTimer);
this.onmouseout = function () {
hotspot.lightTimer=setInterval(function(){hideAudioPop(hotspot);},2000);
};
}
/* Get all the span tags */
spans = document.getElementsByTagName('span');
/* go through them all */
for (i=0;i<spans.length;i++) {
/* If the span is class audiolinkinfo */
if (spans[i].className.indexOf("audiolinkinfo") != -1) {
/* Put the span in a box */
box = document.createElement('div');
box.className="audiolinkbox";
spans[i].parentNode.insertBefore(box,spans[i]);
box.appendChild(spans[i]);
/* And replace the standard template text with expanded description */
/* (This only works with the template of May 18th, 2006. */
/* Any changes to the template would require the script to change.) */
insidebox = spans[i].firstChild
for (j=0;j<insidebox.childNodes.length;j++) {
if (insidebox.childNodes[j].nodeValue == "(") {
insidebox.childNodes[j].nodeValue = " This is an audio file. See ";
/* Label the first node so a speaker icon can be placed before it */
firstnode = insidebox.childNodes[j];
}
if (insidebox.childNodes[j].href && insidebox.childNodes[j].text == "help") {
insidebox.childNodes[j].firstChild.nodeValue = "Media help";
}
if (insidebox.childNodes[j].nodeValue == "·") {
insidebox.childNodes[j].nodeValue = " for information on listening in your player. See the ";
}
if (insidebox.childNodes[j].href && insidebox.childNodes[j].text == "info") {
insidebox.childNodes[j].firstChild.nodeValue = "file's description page";
}
if (insidebox.childNodes[j].textContent == ")") {
insidebox.childNodes[j].nodeValue = " for more details about the recording, creator, and license.";
}
}
/* Add the speaker icon after going through all the nodes, since it changes the number of nodes */
speakerimage = document.createElement('img');
speakerimage.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/15px-Loudspeaker.svg.png";
firstnode.parentNode.insertBefore(speakerimage,firstnode);
/* Add the hover thing to the audiolink span */
var hotspot = spans[i-1];
hotspot.onmouseout=lightout;
hotspot.onmouseover=lightup;
hotspot.audioPop=box;
box.hotspot = hotspot;
box.onmouseover = mouseoverAudioPop;
}
}
});
/* </nowiki></pre> */