Index: trunk/extensions/CodeReview/modules/ext.codereview.tooltips.js |
— | — | @@ -1,5 +1,9 @@ |
2 | 2 | var CodeTooltipsInit = function() { |
3 | 3 | $( 'a[href]' ).each( function() { |
| 4 | + if ( $( this ).parent().is( '.TablePager_col_cr_id' ) ) { |
| 5 | + // Tooltips are unnecessary and annoying in revision lists |
| 6 | + return; |
| 7 | + } |
4 | 8 | var link = this.getAttribute( 'href' ); |
5 | 9 | if ( !link ) { |
6 | 10 | return; |
— | — | @@ -8,7 +12,8 @@ |
9 | 13 | if ( !matches ) { |
10 | 14 | return; |
11 | 15 | } |
12 | | - $( this ).mouseenter( function( e ) { |
| 16 | + |
| 17 | + function showTooltip() { |
13 | 18 | var $el = $( this ); |
14 | 19 | if ( $el.data('codeTooltip') ) { |
15 | 20 | return; // already processed |
— | — | @@ -49,11 +54,31 @@ |
50 | 55 | } |
51 | 56 | } |
52 | 57 | ); |
53 | | - }); |
| 58 | + } |
| 59 | + |
| 60 | + // We want to avoid doing API calls just because someone accidentally moves the mouse |
| 61 | + // over a link, so we only want to do an API call after the mouse has been on a link |
| 62 | + // for 250ms. |
| 63 | + $( this ).mouseenter( function( e ) { |
| 64 | + var that = this; |
| 65 | + var timerID = $( this ).data( 'codeTooltipTimer' ); |
| 66 | + if ( typeof timerID != 'undefined' ) { |
| 67 | + // Clear the running timer |
| 68 | + clearTimeout( timerID ); |
| 69 | + } |
| 70 | + timerID = setTimeout( function() { showTooltip.apply( that ); }, 250 ); |
| 71 | + $( this ).data( 'codeTooltipTimer', timerID ); |
| 72 | + } ); |
54 | 73 | // take care of cases when louse leaves our link while we load stuff from API. |
55 | 74 | // We shouldn't display the tooltip in such case. |
56 | 75 | $( this ).mouseleave( function( e ) { |
57 | 76 | var $el = $( this ); |
| 77 | + var timerID = $el.data( 'codeTooltipTimer' ); |
| 78 | + if ( typeof timerID != 'undefined' ) { |
| 79 | + // Clear the running timer |
| 80 | + clearTimeout( timerID ); |
| 81 | + } |
| 82 | + |
58 | 83 | if ( $el.data( 'codeTooltip' ) || !$el.data( 'codeTooltipLoading' ) ) { |
59 | 84 | return; |
60 | 85 | } |