Make WordPress Core

Changeset 27080


Ignore:
Timestamp:
02/03/2014 05:30:12 AM (11 years ago)
Author:
azaozz
Message:

Consolidate "close on Escape" in the media modal, DFW, wpLink and Thickbox. Props kovshenin, fixes #26854.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/common.js

    r27011 r27080  
    702702})();
    703703
    704 // internal use
    705 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
    706     if ( typeof(data.cb) != 'function' )
    707         return;
    708 
    709     if ( typeof(data.condition) != 'function' || data.condition() )
    710         data.cb();
    711 
    712     return true;
    713 });
    714 
    715704}( jQuery, window ));
  • trunk/src/wp-admin/js/wp-fullscreen.js

    r26966 r27080  
    478478                }
    479479
    480                 if ( 27 == c ) { // Esc
    481                     data = {
    482                         event: e,
    483                         what: 'dfw',
    484                         cb: api.off,
    485                         condition: function(){
    486                             if ( $('#TB_window').is(':visible') || $('.wp-dialog').is(':visible') )
    487                                 return false;
    488                             return true;
    489                         }
    490                     };
    491 
    492                     if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [data] ) ) {
    493                         api.off();
    494                     }
    495                 }
    496 
    497480                if ( a && (61 == c || 107 == c || 187 == c) ) { // +
    498481                    api.dfwWidth( 25 );
     
    508491                    api.dfwWidth( 0 );
    509492                    e.preventDefault();
     493                }
     494            });
     495
     496            $document.on( 'keydown.wp-fullscreen', function( event ) {
     497                if ( 27 === event.which && s.visible ) { // Esc
     498                    api.off();
     499                    event.stopImmediatePropagation();
    510500                }
    511501            });
  • trunk/src/wp-includes/js/media-views.js

    r27051 r27080  
    23482348        keydown: function( event ) {
    23492349            // Close the modal when escape is pressed.
    2350             if ( 27 === event.which ) {
    2351                 event.preventDefault();
     2350            if ( 27 === event.which && this.$el.is(':visible') ) {
    23522351                this.escape();
    2353                 return;
     2352                event.stopImmediatePropagation();
    23542353            }
    23552354        }
  • trunk/src/wp-includes/js/thickbox/thickbox.js

    r23518 r27080  
    157157
    158158            jQuery(document).bind('keydown.thickbox', function(e){
    159                 e.stopImmediatePropagation();
    160 
    161159                if ( e.which == 27 ){ // close
    162                     if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [{ event: e, what: 'thickbox', cb: tb_remove }] ) )
    163                         tb_remove();
     160                    tb_remove();
    164161
    165162                } else if ( e.which == 190 ){ // display previous image
     
    245242
    246243        if(!params['modal']){
    247             jQuery(document).bind('keyup.thickbox', function(e){
    248 
     244            jQuery(document).bind('keydown.thickbox', function(e){
    249245                if ( e.which == 27 ){ // close
    250                     e.stopImmediatePropagation();
    251                     if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [{ event: e, what: 'thickbox', cb: tb_remove }] ) )
    252                         tb_remove();
    253 
     246                    tb_remove();
    254247                    return false;
    255248                }
  • trunk/src/wp-includes/js/wplink.js

    r27071 r27080  
    305305            var fn, key = $.ui.keyCode;
    306306
     307            if ( key.ESCAPE === event.which ) {
     308                wpLink.close();
     309                event.stopImmediatePropagation();
     310            }
     311
    307312            if ( event.which !== key.UP && event.which !== key.DOWN ) {
    308313                return;
     
    318323        keyup: function( event ) {
    319324            var key = $.ui.keyCode;
    320 
    321             if ( event.which === key.ESCAPE ) {
    322                 event.stopImmediatePropagation();
    323                 if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) )
    324                     wpLink.close();
    325                 return false;
    326             }
    327325
    328326            if ( event.which === key.UP || event.which === key.DOWN ) {
Note: See TracChangeset for help on using the changeset viewer.