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

$(function () {
    'use strict';

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

    $('pre[class*="source-"]').addClass('jrajav-code');

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

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

            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'); });
        $('div.tright a.image').each(function () { setupPreviews($(this), 'right'); });
    }
});