|
|
Line 1: |
Line 1: |
− | /* Any JavaScript here will be loaded for all users on every page load. */
| |
| | | |
− |
| |
− | /* Test if an element has a certain class **************************************
| |
− | * Note: this is straight out of Wikipedia's Common.js (http://en.wikipedia.org/wiki/MediaWiki:Common.js)
| |
− | */
| |
− |
| |
− | var hasClass = (function () {
| |
− | var reCache = {};
| |
− | return function (element, className) {
| |
− | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
| |
− | };
| |
− | })();
| |
− |
| |
− |
| |
− | /** Hideable notes *********************************************************
| |
− | * This is based off of code from Wikipedia's Common.js (http://en.wikipedia.org/wiki/MediaWiki:Common.js)
| |
− | */
| |
− |
| |
− | function showNotes( spanIndex )
| |
− | {
| |
− | var Button = document.getElementById( "showNoteLink" + spanIndex );
| |
− | var Span = document.getElementById( "showNotes" + spanIndex );
| |
− |
| |
− | if (!Span || !Button)
| |
− | {
| |
− | return false;
| |
− | }
| |
− |
| |
− | if (Button.firstChild.data == "[show]")
| |
− | {
| |
− | Span.style.display = "inline";
| |
− | Button.firstChild.data = " [hide]";
| |
− | }
| |
− | else
| |
− | {
| |
− | Span.style.display = "none";
| |
− | Button.firstChild.data = "[show]";
| |
− | }
| |
− | }
| |
− |
| |
− | function createShowNotesLinks()
| |
− | {
| |
− | var spanIndex = 0;
| |
− | var Spans = document.getElementsByTagName( "span" );
| |
− | var CurrentSpan = new Object();
| |
− |
| |
− | for ( var i = 0; i < Spans.length; i++ )
| |
− | {
| |
− | if ( hasClass( Spans[i], "hiddenNotes" ) )
| |
− | {
| |
− | CurrentSpan = Spans[i];
| |
− | CurrentSpan.setAttribute( "id", "showNotes" + spanIndex );
| |
− |
| |
− | var Button = document.createElement( "span" );
| |
− | var ButtonLink = document.createElement( "a" );
| |
− | var ButtonText = document.createTextNode( "[show]" );
| |
− |
| |
− | ButtonLink.setAttribute( "id", "showNoteLink" + spanIndex );
| |
− | ButtonLink.setAttribute( "href", "#" );
| |
− | addHandler( ButtonLink, "click", new Function( "evt", "showNotes(" + spanIndex + " ); return killEvt( evt );") );
| |
− | ButtonLink.appendChild( ButtonText );
| |
− |
| |
− | Button.appendChild(document.createTextNode( " " ));
| |
− | Button.appendChild(ButtonLink);
| |
− |
| |
− | CurrentSpan.parentNode.insertBefore( Button, CurrentSpan.nextSibling );
| |
− | CurrentSpan.style.display="none";
| |
− |
| |
− | spanIndex++;
| |
− | }
| |
− | }
| |
− | }
| |
− |
| |
− | addonloadHook( createShowNotesLinks );
| |