Make WordPress Core

Changeset 40019


Ignore:
Timestamp:
01/27/2017 04:24:58 AM (7 years ago)
Author:
azaozz
Message:

TinyMCE: improve the previews for embedded WordPress posts:

  • Add option to force a sandbox iframe in wpview.
  • Use it to show the embedded post preview.
  • Remove the deprecated wpembed plugin.js

Fixes #39513.

Location:
trunk/src
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r39934 r40019  
    30053005    }
    30063006
    3007 
    30083007    if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) ||
    30093008        preg_match( '%<link [^>]*href="http://%', $parsed ) ) ) ) {
     
    30153014    }
    30163015
    3017     wp_send_json_success( array(
     3016    $return = array(
    30183017        'body' => $parsed,
    30193018        'attr' => $wp_embed->last_attr
    3020     ) );
     3019    );
     3020
     3021    if ( strpos( $parsed, 'class="wp-embedded-content' ) ) {
     3022        if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
     3023            $script_src = includes_url( 'js/wp-embed.js' );
     3024        } else {
     3025            $script_src = includes_url( 'js/wp-embed.min.js' );
     3026        }
     3027
     3028        $return['head'] = '<script src="' . $script_src . '"></script>';
     3029        $return['sandbox'] = true;
     3030    }
     3031
     3032    wp_send_json_success( $return );
    30213033}
    30223034
  • trunk/src/wp-includes/class-wp-editor.php

    r39678 r40019  
    418418                        'wptextpattern',
    419419                        'wpview',
    420                         'wpembed',
    421420                    );
    422421
  • trunk/src/wp-includes/js/mce-view.js

    r39903 r40019  
    469469         */
    470470        setContent: function( content, callback, rendered ) {
    471             if ( _.isObject( content ) && content.body.indexOf( '<script' ) !== -1 ) {
     471            if ( _.isObject( content ) && ( content.sandbox || content.head || content.body.indexOf( '<script' ) !== -1 ) ) {
    472472                this.setIframes( content.head || '', content.body, callback, rendered );
    473473            } else if ( _.isString( content ) && content.indexOf( '<script' ) !== -1 ) {
     
    585585                                    'content: "";' +
    586586                                '}' +
     587                                'iframe {' +
     588                                    'max-width: 100%;' +
     589                                '}' +
    587590                            '</style>' +
    588591                        '</head>' +
     
    624627
    625628                function reload() {
    626                     $( node ).data( 'rendered', null );
    627 
    628                     setTimeout( function() {
    629                         wp.mce.views.render();
    630                     } );
    631                 }
    632 
    633                 $( iframeWin ).on( 'load', resize ).on( 'unload', reload );
    634 
    635                 MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver;
    636 
    637                 if ( MutationObserver ) {
     629                    if ( ! editor.isHidden() ) {
     630                        $( node ).data( 'rendered', null );
     631
     632                        setTimeout( function() {
     633                            wp.mce.views.render();
     634                        } );
     635                    }
     636                }
     637
     638                function addObserver() {
    638639                    observer = new MutationObserver( _.debounce( resize, 100 ) );
    639640
     
    643644                        subtree: true
    644645                    } );
     646                }
     647
     648                $( iframeWin ).on( 'load', resize ).on( 'unload', reload );
     649
     650                MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver;
     651
     652                if ( MutationObserver ) {
     653                    if ( ! iframeDoc.body ) {
     654                        iframeDoc.addEventListener( 'DOMContentLoaded', addObserver, false );
     655                    } else {
     656                        addObserver();
     657                    }
    645658                } else {
    646659                    for ( i = 1; i < 6; i++ ) {
Note: See TracChangeset for help on using the changeset viewer.