MediaWiki:Common.js

From Pandora Wiki
Revision as of 12:08, 23 January 2011 by EvilDragon (talk | contribs)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function mouseOver(e, imgUrl)
{
        var body = document.getElementById('bodyContent');
        
        var image = new Image();
        image.src = imgUrl;
        
        var previewImage = document.createElement('img');
        previewImage.setAttribute('src', imgUrl);
        previewImage.setAttribute('id', 'previewImage');

        var scrolledHeight = 0;

        if (document.documentElement.scrollTop)
                scrolledHeight = document.documentElement.scrollTop;
        else if (document.body.scrollTop)
                scrolledHeight = document.body.scrollTop;
        else
                scrolledHeight = window.pageYOffset;

        previewStyle = "position: absolute; left: " + (e.clientX - image.width - 200) + "px; top: " + (e.clientY + scrolledHeight - 30) + "px; border: 1px solid grey;";
        previewImage.setAttribute('style', previewStyle);
        
        body.appendChild(previewImage);
}


function mouseOut()
{
        var body = document.getElementById('bodyContent');
        var previewImage = document.getElementById('previewImage');
        
        body.removeChild(previewImage);
}

function createScreenshotLinks()
{
    var spanIndex = 0;
    var Spans = document.getElementsByTagName( "span" );
    var CurrentSpan = new Object();

    for ( var i = 0; i < Spans.length; i++ ) 
    {
        if ( hasClass( Spans[i], "previewScreenshot" ) ) 
        {
            CurrentSpan = Spans[i];

            var wikiLinks = new Object(); // This is needed because the wiki automatically turns urls into links.
            wikiLinks = CurrentSpan.getElementsByTagName( "a" );
            var imgURL = wikiLinks[0].innerHTML;

            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( "[ss]" );

            ButtonLink.setAttribute("href", imgURL);
            ButtonLink.setAttribute("target", "_" + imgURL);
            ButtonLink.appendChild( ButtonText );

            Button.appendChild(document.createTextNode( " " ));
            Button.appendChild(ButtonLink);
            Button.setAttribute( "onmouseover", "mouseOver(event, '" + imgURL + "');");
            Button.setAttribute( "onmouseout", "mouseOut();");

            CurrentSpan.parentNode.insertBefore( Button, CurrentSpan.nextSibling );
            CurrentSpan.style.display="none";

            spanIndex++;
        }
    }
}

addOnloadHook( createScreenshotLinks );