Make WordPress Core

Ticket #29841: 29841.patch

File 29841.patch, 4.5 KB (added by iseulde, 11 years ago)
  • src/wp-includes/js/mce-view.js

     
    1717                mediaWindows = [],
    1818                windowIdx = 0,
    1919                waitInterval = 50,
    20                 viewOptions = ['encodedText'];
     20                viewOptions = ['encodedText'],
     21                oEmbedProviders = [];
    2122
    2223        // Create the `wp.mce` object if necessary.
    2324        wp.mce = wp.mce || {};
    2425
     26        // Convert PHP regex to JS regex.
     27        _.each( window._wpMCEViewL10n.oEmbedProviders, function( provider, pattern ) {
     28                var match = /^([^a-z0-9\\ ])?(.*)\1([a-z]*)$/.exec( pattern );
     29
     30                if ( ! match ) {
     31                        return;
     32                }
     33
     34                pattern = match[1] ? match[2].replace( new RegExp( '\\\\' + match[1], 'g' ), match[1] ) : match[2];
     35                pattern = pattern.replace( /\//g, '\\/' );
     36                pattern = new RegExp( pattern, 'i' );
     37
     38                oEmbedProviders.push( pattern );
     39        } );
     40
    2541        /**
    2642         * wp.mce.View
    2743         *
     
    111127                setContent: function( html, option ) {
    112128                        this.getNodes( function ( editor, node, content ) {
    113129                                var el = ( option === 'wrap' || option === 'replace' ) ? node : content,
    114                                         insert = html;
     130                                        insert = html,
     131                                        view = editor.plugins.wpview.getView( editor.selection.getNode() ),
     132                                        p;
    115133
    116134                                if ( _.isString( insert ) ) {
    117135                                        insert = editor.dom.createFragment( insert );
    118136                                }
    119137
    120138                                if ( option === 'replace' ) {
    121                                         editor.dom.replace( insert, el );
     139                                        p = editor.dom.create( 'p', null, insert );
     140
     141                                        editor.dom.replace( p, el );
     142
     143                                        if ( view ) {
     144                                                editor.selection.select( p, true );
     145                                                editor.selection.collapse();
     146                                        }
    122147                                } else {
    123148                                        el.innerHTML = '';
    124149                                        el.appendChild( insert );
     150
     151                                        if ( view ) {
     152                                                editor.plugins.wpview.setViewCursor( false, view );
     153                                        }
    125154                                }
    126155                        } );
    127156                },
     
    700729
    701730                                                this.setError( this.error.message, 'admin-media' );
    702731                                        } else {
    703                                                 this.setContent( '<p>' + this.original + '</p>', 'replace' );
     732                                                this.setContent( this.original, 'replace' );
    704733                                        }
    705734                                } else if ( this.error.statusText ) {
    706735                                        this.setError( this.error.statusText, 'admin-media' );
    707736                                } else if ( this.original ) {
    708                                         this.setContent( '<p>' + this.original + '</p>', 'replace' );
     737                                        this.setContent( this.original, 'replace' );
    709738                                }
    710739                        },
    711740
     
    875904                                return;
    876905                        }
    877906
    878                         return {
    879                                 index: match.index,
    880                                 content: match[0],
    881                                 options: {
    882                                         url: match[1]
    883                                 }
    884                         };
     907                        if ( _.some( oEmbedProviders, function( re ) {
     908                                return re.exec( match[1] );
     909                        } ) ) {
     910                                return {
     911                                        index: match.index,
     912                                        content: match[0],
     913                                        options: {
     914                                                url: match[1]
     915                                        }
     916                                };
     917                        }
    885918                }
    886919        } ) );
    887920
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

     
    162162                        toolbar = editor.$( viewNode ).find( '.toolbar' ),
    163163                        editorToolbar = tinymce.$( editor.editorContainer ).find( '.mce-toolbar-grp' )[0],
    164164                        editorToolbarBottom = ( editorToolbar && editorToolbar.getBoundingClientRect().bottom ) || 0;
    165                
     165
    166166                if ( toolbar.length && editor.iframeElement ) {
    167167                        // 48 = 43 for the toolbar + 5 buffer
    168168                        delta = viewNode.getBoundingClientRect().top + editor.iframeElement.getBoundingClientRect().top - editorToolbarBottom - 48;
     
    718718        return {
    719719                getViewText: getViewText,
    720720                setViewText: setViewText,
    721                 getView: getView
     721                getView: getView,
     722                setViewCursor: setViewCursor
    722723        };
    723724});
  • src/wp-includes/script-loader.php

     
    418418        $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
    419419        $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models', 'media-audiovideo', 'wp-playlist' ), false, 1 );
    420420
     421        require_once ABSPATH . WPINC . '/class-oembed.php';
     422
     423        did_action( 'init' ) && $scripts->localize( 'mce-view', '_wpMCEViewL10n', array(
     424                'oEmbedProviders' => _wp_oembed_get_object()->providers
     425        ) );
     426
    421427        if ( is_admin() ) {
    422428                $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('jquery', 'wp-ajax-response'), false, 1 );
    423429                did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array(