Make WordPress Core

Changeset 41985


Ignore:
Timestamp:
10/24/2017 04:06:23 AM (9 years ago)
Author:
westonruter
Message:

Editor: Specify maxwidth in parse-embed requests based on width of editor iframe so that TinyMCE view embeds fit, particularly in Text widgets.

See #40854, #34115.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r41980 r41985  
    29942994 * @global WP_Embed   $wp_embed   Embed API instance.
    29952995 * @global WP_Scripts $wp_scripts
     2996 * @global int        $content_width
    29962997 */
    29972998function wp_ajax_parse_embed() {
    2998         global $post, $wp_embed;
     2999        global $post, $wp_embed, $content_width;
    29993000
    30003001        if ( empty( $_POST['shortcode'] ) ) {
    … …  
    30353036                if ( ! $parsed ) {
    30363037                        $no_ssl_support = true;
     3038                }
     3039        }
     3040
     3041        // Set $content_width so any embeds fit in the destination iframe.
     3042        if ( isset( $_POST['maxwidth'] ) && is_numeric( $_POST['maxwidth'] ) && $_POST['maxwidth'] > 0 ) {
     3043                if ( ! isset( $content_width ) ) {
     3044                        $content_width = intval( $_POST['maxwidth'] );
     3045                } else {
     3046                        $content_width = min( $content_width, intval( $_POST['maxwidth'] ) );
    30373047                }
    30383048        }
  • trunk/src/wp-includes/js/mce-view.js

    r41395 r41985  
    8686                 *
    8787                 * @param {String} content The string to scan.
     88                 * @param {tinymce.Editor} editor The editor.
    8889                 *
    8990                 * @return {String} The string with markers.
    9091                 */
    91                 setMarkers: function( content ) {
     92                setMarkers: function( content, editor ) {
    9293                        var pieces = [ { content: content } ],
    9394                                self = this,
    … …  
    116117                                                }
    117118
     119                                                result.options.editor = editor;
    118120                                                instance = self.createInstance( type, result.content, result.options );
    119121                                                text = instance.loader ? '.' : instance.text;
    … …  
    851853
    852854                initialize: function() {
    853                         var self = this;
     855                        var self = this, maxwidth = null;
    854856
    855857                        if ( this.url ) {
    … …  
    860862                        }
    861863
     864                        // Obtain the target width for the embed.
     865                        if ( self.editor ) {
     866                                maxwidth = self.editor.iframeElement.clientWidth - 20; // Minus the sum of horizontal margins and borders.
     867                        }
     868
    862869                        wp.ajax.post( this.action, {
    863870                                post_ID: media.view.settings.post.id,
    864871                                type: this.shortcode.tag,
    865                                 shortcode: this.shortcode.string()
     872                                shortcode: this.shortcode.string(),
     873                                maxwidth: maxwidth
    866874                        } )
    867875                        .done( function( response ) {
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r40583 r41985  
    8989                        }
    9090
    91                         event.content = wp.mce.views.setMarkers( event.content );
     91                        event.content = wp.mce.views.setMarkers( event.content, editor );
    9292                } );
    9393
Note: See TracChangeset for help on using the changeset viewer.