Make WordPress Core

Changeset 27786


Ignore:
Timestamp:
03/27/2014 06:06:13 PM (12 years ago)
Author:
nacin
Message:

Remove the TinyMCE image toolbar when the image is deleted via the keyboard.

props gcorne.
fixes #27527.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js

    r27777 r27786  
    11/* global tinymce */
    22tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
     3        var toolbarActive = false;
     4
    35        function parseShortcode( content ) {
    46                return content.replace( /(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function( a, b, c ) {
     
    103105
    104106                        if ( out.indexOf('[caption') !== 0 ) {
    105                                 // the caption html seems brocken, try to find the image that may be wrapped in a link
     107                                // the caption html seems broken, try to find the image that may be wrapped in a link
    106108                                // and may be followed by <p> with the caption text.
    107109                                out = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
     
    340342                        editor.dom.remove( node );
    341343                }
     344                removeToolbar();
    342345        }
    343346
     
    372375                        left: rectangle.x
    373376                });
     377
     378                toolbarActive = true;
    374379        }
    375380
     
    382387
    383388                editor.dom.setAttrib( editor.dom.select( 'img[data-wp-imgselect]' ), 'data-wp-imgselect', null );
     389
     390                toolbarActive = false;
    384391        }
    385392
     
    754761                var node, wrap, P, spacer,
    755762                        selection = editor.selection,
     763                        keyCode = event.keyCode,
    756764                        dom = editor.dom;
    757765
    758                 if ( event.keyCode === tinymce.util.VK.ENTER ) {
     766                if ( keyCode === tinymce.util.VK.ENTER ) {
    759767                        // When pressing Enter inside a caption move the caret to a new parapraph under it
    760768                        node = selection.getNode();
     
    783791                                selection.setCursorLocation( P, 0 );
    784792                        }
    785                 } else if ( event.keyCode === tinymce.util.VK.DELETE || event.keyCode === tinymce.util.VK.BACKSPACE ) {
     793                } else if ( keyCode === tinymce.util.VK.DELETE || keyCode === tinymce.util.VK.BACKSPACE ) {
    786794                        node = selection.getNode();
    787795
     
    797805                                return false;
    798806                        }
     807
     808                        removeToolbar();
     809                }
     810
     811                // Key presses will replace the image so we need to remove the toolbar
     812                if ( toolbarActive ) {
     813                        if ( event.ctrlKey || event.metaKey || event.altKey ||
     814                                ( keyCode < 48 && keyCode > 90 ) || keyCode > 186 ) {
     815                                return;
     816                        }
     817
     818                        removeToolbar();
    799819                }
    800820        });
     
    829849                                if ( dom.hasClass( node, 'remove' ) ) {
    830850                                        removeImage( image );
    831                                         removeToolbar();
    832851                                } else if ( dom.hasClass( node, 'edit' ) ) {
    833852                                        editImage( image );
Note: See TracChangeset for help on using the changeset viewer.