jqueryToolTip.js 1.73 KB
Newer Older
1 2 3 4 5 6 7 8
$(function () {
    var distance = 10;
    var time = 250;
    var hideDelay = 200;
    var hideDelayTimer = null;
    var beingShown = false;
    var shown = false;
    $('.popup').css('opacity', 0);
Alain Takoudjou's avatar
Alain Takoudjou committed
9
    $('a[rel=tooltip], a[rel=tooltip-min], .popup').mouseover(function () {
10
        var height = $(this).height();
Alain Takoudjou's avatar
Alain Takoudjou committed
11
        var top = $(this).offset().top + height;
12
        var left = $(this).offset().left +($(this).width()/2)-30;
Alain Takoudjou's avatar
Alain Takoudjou committed
13
        var content = "#tooltip-" + $(this).attr('id');
14 15 16
        if (hideDelayTimer) clearTimeout(hideDelayTimer);
        if (beingShown || shown) {
            return;
17
        } else {
Alain Takoudjou's avatar
Alain Takoudjou committed
18 19 20 21
            $('#jqtooltip').empty();
            var contentValue = $(content).clone(true, true);
            $(contentValue).appendTo('#jqtooltip');
            $('#jqtooltip ' + content).show();
22
            // reset position of info box
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
            beingShown = true;
            $('.popup').css({
                top: top,
                left: left,
                display: 'block'
            }).animate({
                top: '-=' + distance + 'px',
                opacity: 1
            }, time, 'swing', function() {
                beingShown = false;
                shown = true;
            });
        }
        return false;
    }).mouseout(function () {
        if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                $('.popup').animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
44
                }, time, 'swing', function () {
45
                    $('.popup').css('display', 'none');
Alain Takoudjou's avatar
Alain Takoudjou committed
46
                    shown = false;
47
                });
Alain Takoudjou's avatar
Alain Takoudjou committed
48
            }, hideDelay);
49 50 51
        return false;
    });
});