Make WordPress Core

Ticket #28322: 28322.patch

File 28322.patch, 2.7 KB (added by azaozz, 9 years ago)
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    8686        }
    8787
    8888        function select( viewNode ) {
    89                 var clipboard,
    90                         dom = editor.dom;
     89                var clipboard;
    9190
    9291                if ( ! viewNode ) {
    9392                        return;
     
    9493                }
    9594
    9695                if ( viewNode !== selected ) {
    97                         // Make sure that the editor is focused.
    98                         // It is possible that the editor is not focused when the mouse event fires
    99                         // without focus, the selection will not work properly.
    100                         editor.getBody().focus();
    101 
    10296                        deselect();
    10397                        selected = viewNode;
    104                         dom.setAttrib( viewNode, 'data-mce-selected', 1 );
     98                        $( viewNode ).attr( 'data-mce-selected', 1 );
    10599
    106                         clipboard = dom.create( 'div', {
     100                        clipboard = editor.dom.create( 'div', {
    107101                                'class': 'wpview-clipboard',
    108102                                'contenteditable': 'true'
    109103                        }, wp.mce.views.getText( viewNode ) );
    110104
    111                         editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard );
     105                        $( '.wpview-body', viewNode ).append( clipboard );
    112106
    113107                        // Both of the following are necessary to prevent manipulating the selection/focus
    114                         dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
    115                         dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
     108                        $( clipboard ).on( 'beforedeactivate focusin focusout', _stop );
     109                        $( selected ).on( 'beforedeactivate focusin focusout', _stop );
    116110
    117                         // select the hidden div
     111                        // Make sure that the editor is focused.
     112                        // It is possible that the editor is not focused when the mouse event fires
     113                        // without focus, the selection will not work properly.
     114                        // Need to select the (visible) wpView wrap node first to prevent Chrome from jumping to the top.
     115                        editor.selection.select( viewNode );
     116                        editor.focus();
     117
     118                        // Select the hidden clipboard div so when the users try to copy the selection,
     119                        // they will copy the string used to create the wpView.
    118120                        if ( isios ) {
    119121                                editor.selection.select( clipboard );
    120122                        } else {
     
    130132         * Deselect a selected view and remove clipboard
    131133         */
    132134        function deselect() {
    133                 var clipboard,
    134                         dom = editor.dom;
    135 
    136135                if ( selected ) {
    137                         clipboard = editor.dom.select( '.wpview-clipboard', selected )[0];
    138                         dom.unbind( clipboard );
    139                         dom.remove( clipboard );
    140 
    141                         dom.unbind( selected, 'beforedeactivate focusin focusout click mouseup', _stop );
    142                         dom.setAttrib( selected, 'data-mce-selected', null );
     136                        $( selected ).off( 'beforedeactivate focusin focusout click mouseup', _stop )
     137                                .removeAttr( 'data-mce-selected' )
     138                                .find( '.wpview-clipboard' ).off().remove();
    143139                }
    144140
    145141                selected = null;