Bug Tracker

Changeset 2792

Show
Ignore:
Timestamp:
08/20/07 11:57:17 (1 year ago)
Author:
klaus.hartl
Message:

Fixed keydown handler assignments

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/thickbox_reloaded/jquery.thickbox.js

    r2631 r2792  
    9090                // reveal stuff 
    9191                dim.unbind('click').one('click', hide); // unbind should be unnecessary - WTF? 
    92                 if (dim.is(':visible')) { 
    93                     loading.show(); 
    94                     builder(); // build specific type 
    95                 } else { 
    96                     //dim.fadeIn('fast', function() { 
    97                         dim.show(); 
    98                         loading.show(); 
    99                         builder(); // build specific type 
    100                     //}); 
    101                 } 
     92                if (!dim.is(':visible')) { 
     93                    dim.show(); 
     94                } 
     95                loading.show(); 
     96                builder(); // build specific type 
     97                 
    10298                // attach keyboard event handler 
    10399                $(document).bind('keydown', keydown).bind('keypress', blockKeys); 
     
    138134            function hide(callback) { 
    139135 
     136                // abort pending xhr request 
    140137                if (request) { 
    141138                    request.abort(); 
     
    153150                $(document).unbind('keydown', keydown).unbind('keypress', blockKeys); 
    154151                $(window).unbind('scroll', blockScroll); 
     152                next = previous = function() {}; 
    155153                return false; 
    156154            } 
     
    171169            } 
    172170 
     171            var next = function() {}, previous = next; 
    173172            function keydown(e) { 
    174173                var key = e.which || e.keyCode || -1; 
    175                 if (key == 27) { 
    176                     hide(); 
    177                 } else { 
    178                     blockKeys(e); 
     174                switch (key) { 
     175                    case 27: // esc 
     176                        hide(); 
     177                        break; 
     178                    case 37: // arrow left 
     179                        previous(); 
     180                        break; 
     181                    case 39: // arrow right 
     182                        next(); 
     183                        break; 
     184                    default: 
     185                        blockKeys(e); 
    179186                } 
    180187            } 
     
    251258                                        }; 
    252259 
    253                                         var next = '<strong id="' + TB_ID.NEXT + '"><a href="#" title="' + defaultValues.i18n.next.title + '">' + defaultValues.i18n.next.text + '</a></strong>'; 
    254                                         var showNext = buildShowFunc(group[i + 1] || group[0]); 
    255  
    256                                         var prev = '<strong id="' + TB_ID.PREV + '"><a href="#" title="' + defaultValues.i18n.prev.title + '">' + defaultValues.i18n.prev.text + '</a></strong>'; 
    257                                         var showPrev = buildShowFunc(group[i - 1] || group[size - 1]); 
    258  
    259                                         // overwrite keydown handler 
    260                                         keydown = function(e) { 
    261                                             var key = e.which || e.keyCode || -1; 
    262                                             // IE requires "timeout", I assume somehow due to this being added on 
    263                                             // the existing keydown handler, that's ugly, find a way to avoid 
    264                                             // duplicate code 
    265                                             // WARNING: without timeout IE freezes occasionally when using keyboard arrows 
    266                                             setTimeout(function() { 
    267                                                 switch (key) { 
    268                                                     case 27: // esc 
    269                                                         hide(); 
    270                                                         break; 
    271                                                     case 37: // arrow left 
    272                                                         showPrev(); 
    273                                                         break; 
    274                                                     case 39: // arrow right 
    275                                                         showNext(); 
    276                                                         break; 
    277                                                     default: 
    278                                                         blockKeys(e); 
    279                                                 } 
    280                                             }, 0); 
    281                                         }; 
    282                                         $(document).unbind('keydown').bind('keydown', keydown); 
     260                                        var nextHtml = '<strong id="' + TB_ID.NEXT + '"><a href="#" title="' + defaultValues.i18n.next.title + '">' + defaultValues.i18n.next.text + '</a></strong>'; 
     261                                        next = buildShowFunc(group[i + 1] || group[0]); 
     262 
     263                                        var previousHtml = '<strong id="' + TB_ID.PREV + '"><a href="#" title="' + defaultValues.i18n.prev.title + '">' + defaultValues.i18n.prev.text + '</a></strong>'; 
     264                                        previous = buildShowFunc(group[i - 1] || group[size - 1]); 
    283265 
    284266                                    } 
     
    318300                                    $('<img src="' +  $$.attr('href') + '" alt="Image" width="' + imgWidth + '" height="' + imgHeight + '" title="' + title + '" />').appendTo(content); 
    319301                                    if (rel) { 
    320                                         $(['<p id="' + TB_ID.BROWSE + '">', (prev || ''), (next || ''), count, '</p>'].join('')).appendTo(content); 
     302                                        $(['<p id="' + TB_ID.BROWSE + '">', (previousHtml || ''), (nextHtml || ''), count, '</p>'].join('')).appendTo(content); 
    321303                                        if (size > 1) { 
    322                                             $('#' + TB_ID.NEXT + ' a').bind('click', showNext); 
    323                                             $('#' + TB_ID.PREV + ' a').bind('click', showPrev); 
     304                                            $('#' + TB_ID.NEXT + ' a').bind('click', next); 
     305                                            $('#' + TB_ID.PREV + ' a').bind('click', previous); 
    324306                                        } 
    325307                                    }