Make WordPress Core

Ticket #28258: 28258.2.patch

File 28258.2.patch, 3.8 KB (added by iseulde, 12 years ago)
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    44 */
    55tinymce.PluginManager.add( 'wpview', function( editor ) {
    66        var selected,
    7                 VK = tinymce.util.VK,
     7                Env = tinymce.Env,
    88                TreeWalker = tinymce.dom.TreeWalker,
     9                VK = tinymce.util.VK,
    910                toRemove = false;
    1011
    1112        function getParentView( node ) {
     
    2425
    2526        function createPadNode() {
    2627                return editor.dom.create( 'p', { 'data-wpview-pad': 1 },
    27                         ( tinymce.Env.ie && tinymce.Env.ie < 11 ) ? '' : '<br data-mce-bogus="1" />' );
     28                        ( Env.ie && Env.ie < 11 ) ? '' : '<br data-mce-bogus="1" />' );
    2829        }
    2930
    3031        /**
     
    289290                                event.stopPropagation();
    290291
    291292                                // Hack to try and keep the block resize handles from appearing. They will show on mousedown and then be removed on mouseup.
    292                                 if ( tinymce.Env.ie <= 10 ) {
     293                                if ( Env.ie <= 10 ) {
    293294                                        deselect();
    294295                                }
    295296
     
    309310
    310311                                // Fix issue with deselecting a view in IE8. Without this hack, clicking content above the view wouldn't actually deselect it
    311312                                // and the caret wouldn't be placed at the mouse location
    312                                 if ( tinymce.Env.ie && tinymce.Env.ie <= 8 ) {
     313                                if ( Env.ie && Env.ie <= 8 ) {
    313314                                        deselectEventType = 'mouseup';
    314315                                } else {
    315316                                        deselectEventType = 'mousedown';
     
    357358        });
    358359
    359360        editor.on( 'keydown', function( event ) {
    360                 var keyCode = event.keyCode,
     361                var dom = editor.dom,
    361362                        body = editor.getBody(),
     363                        keyCode = event.keyCode,
     364                        selection = editor.selection,
    362365                        view, padNode;
    363366
    364367                // If a view isn't selected, let the event go on its merry way.
     
    375378                        return;
    376379                }
    377380
    378                 view = getParentView( editor.selection.getNode() );
     381                view = getParentView( selection.getNode() );
    379382
    380383                // If the caret is not within the selected view, deselect the
    381384                // view and bail.
     
    394397                        } else if ( ! view.previousSibling ) {
    395398                                padNode = createPadNode();
    396399                                body.insertBefore( padNode, body.firstChild );
    397                                 editor.selection.setCursorLocation( body.firstChild, 0 );
     400                                selection.setCursorLocation( body.firstChild, 0 );
    398401                        // Handle default case
    399402                        } else {
    400                                 editor.selection.select( view.previousSibling, true );
    401                                 editor.selection.collapse();
     403                                selection.select( view.previousSibling, true );
     404                                selection.collapse();
    402405                        }
    403406                } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) {
    404407                        deselect();
     
    409412                        } else if ( ! view.nextSibling ) {
    410413                                padNode = createPadNode();
    411414                                body.appendChild( padNode );
    412                                 editor.selection.setCursorLocation( body.lastChild, 0 );
     415                                selection.setCursorLocation( body.lastChild, 0 );
    413416                        // Handle default case where the next node is a non-wpview
    414417                        } else {
    415                                 editor.selection.setCursorLocation( view.nextSibling, 0 );
     418                                selection.setCursorLocation( view.nextSibling, 0 );
    416419                        }
     420                // Create a new paragraph when pressing enter/return.
     421                } else if ( keyCode === VK.ENTER ) {
     422                        if ( dom.isEmpty( view.nextSibling ) && view.nextSibling.nodeName === 'P' ) {
     423                                padNode = view.nextSibling;
     424                        } else {
     425                                padNode = dom.create( 'p' );
     426                                // BR is needed in empty blocks on non IE browsers.
     427                                if ( ! ( Env.ie && Env.ie < 11 ) ) {
     428                                        padNode.innerHTML = '<br data-mce-bogus="1">';
     429                                }
     430                                dom.insertAfter( padNode, selected );
     431                        }
     432                        deselect();
     433                        selection.setCursorLocation( padNode, 0 );
     434                // If delete or backspace is pressed, delete the view.
    417435                } else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
    418                         // If delete or backspace is pressed, delete the view.
    419                         editor.dom.remove( selected );
     436                        dom.remove( selected );
    420437                }
    421438
    422439                event.preventDefault();