Jump to content

User:Jrajav/myskin.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jrajav (talk | contribs) at 22:27, 5 November 2012. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*jslint regexp: true, browser: true */
/*global $: false */

var iWantThumbnailPreviews = true,
    andAnimateThem = true, // Doesn't perform well in most browsers
    andPreloadThem = true;

$(function () {
    'use strict';

    if (iWantThumbnailPreviews) {
        var setupPreviews = function (anchor, position) {
            var originalImage = anchor.find('img').first(),
                overlayImage = $('<img/>');

            overlayImage
                .hide()
                .css({
                    'position': 'absolute',
                    'max-width': originalImage.width() + 'px'
                })
                .css(position)
                .addClass('jrajav-image-overlay')
                .load(function () {
                    overlayImage.show();
                });

            if (andAnimateThem) {
                overlayImage.addClass('jrajav-image-overlay-animate');
            }

            anchor.prepend(overlayImage);

            function loadOverlay() {
                overlayImage.attr('src', originalImage.attr('src').replace('/thumb/', '/').replace(/\/\d*px.*$/, ''));
            }

            if (andPreloadThem) {
                loadOverlay();
            } else {
                originalImage.one('mouseenter', loadOverlay);
            }
        };

        $('div.tright div.thumbinner a').each(function () { setupPreviews($(this), {'right': '0px'}); });
        $('div.tleft div.thumbinner a').each(function () { setupPreviews($(this), {'left': '0px'}); });
    }

    $('#searchInput').attr('tabindex', 1);
});