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 23:37, 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 = false, // CSS transition; Doesn't perform well in most browsers
    andPreloadThem = true;

$(function () {
    'use strict';
    
    $('#searchInput').attr('tabindex', 1);

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

            overlayImage
                .css({
                    'position': 'absolute',
                    'max-width': originalImage.width() + 'px'
                })
                .css(position)
                .addClass('jrajav-image-overlay')
                .hide()
                .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.tleft a.image').each(function () { setupPreviews($(this), {'left': '0'}); });
        $('div.tright a.image').each(function () { setupPreviews($(this), {'right': '0'}); });
    }
});