Make WordPress Core

Ticket #37427: 37427.patch

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

     
    33 */
    44( function( tinymce, wp ) {
    55        tinymce.PluginManager.add( 'wpview', function( editor ) {
     6                var scrolled = false;
     7
    68                function noop () {}
    79
    810                if ( ! wp || ! wp.mce || ! wp.mce.views ) {
     
    1113                        };
    1214                }
    1315
     16                /**
     17                 * Returns the node or a parent of the node that has the passed className.
     18                 * Doing this directly is about 40% faster
     19                 */
     20                function getParent( node, className ) {
     21                        while ( node && node.parentNode ) {
     22                                if ( node.className && ( ' ' + node.className + ' ' ).indexOf( ' ' + className + ' ' ) !== -1 ) {
     23                                        return node;
     24                                }
     25
     26                                node = node.parentNode;
     27                        }
     28
     29                        return false;
     30                }
     31
     32                function getView( node ) {
     33                        return getParent( node, 'wpview' );
     34                }
     35
    1436                // Check if a node is a view or not.
    1537                function isView( node ) {
    1638                        return editor.dom.hasClass( node, 'wpview' );
     
    125147                        }
    126148                } );
    127149
     150                if ( tinymce.Env.ie || ( 'ontouchend' in document ) ) {
     151                        editor.on( 'init', function() {
     152                                editor.dom.bind( editor.getDoc(), 'touchmove', function() {
     153                                        scrolled = true;
     154                                });
     155
     156                                editor.on( 'mousedown mouseup click touchend', function( event ) {
     157                                        var view = getView( event.target );
     158
     159                                        if ( view ) {
     160                                                event.stopImmediatePropagation();
     161                                                event.preventDefault();
     162
     163                                                if ( event.type === 'touchend' && scrolled ) {
     164                                                        scrolled = false;
     165                                                } else {
     166                                                        editor.selection.select( view );
     167                                                }
     168                                        } else {
     169                                                if ( event.type === 'touchend' || event.type === 'mousedown' ) {
     170                                                        editor.selection.collapse();
     171                                                }
     172                                        }
     173
     174                                        if ( event.type === 'touchend' && scrolled ) {
     175                                                scrolled = false;
     176                                        }
     177                                }, true );
     178                        });
     179                }
     180
    128181                editor.addButton( 'wp_view_edit', {
    129182                        tooltip: 'Edit ', // trailing space is needed, used for context
    130183                        icon: 'dashicon dashicons-edit',