Make WordPress Core

Changeset 29187


Ignore:
Timestamp:
07/16/2014 03:39:05 PM (12 years ago)
Author:
wonderboymusic
Message:

Cleanup after [29179]:

  • _WP_Editors::editor_settings() no longer needs to load MEjs styles
  • Make sure each identical shortcode with multiple instances also has an iframe sandbox for each instance
  • For the time being, make audio and video shortcodes bypass the loading placeholder to avoid whiplash visually

Props avryl, wonderboymusic.
See #28905.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-editor.php

    r29177 r29187  
    504504                                $version = 'ver=' . $GLOBALS['wp_version'];
    505505                                $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
    506                                 $mediaelement = includes_url( "js/mediaelement/mediaelementplayer.min.css?$version" );
    507                                 $wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" );
    508506
    509507                                // WordPress default stylesheet and dashicons
    510508                                $mce_css = array(
    511509                                        $dashicons,
    512                                         $mediaelement,
    513                                         $wpmediaelement,
    514510                                        self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
    515511                                );
  • trunk/src/wp-includes/js/mce-view.js

    r29184 r29187  
    7070                },
    7171                unbind: function() {},
    72                 setContent: function( html, callback, option ) {
     72                getNodes: function( callback ) {
     73                        var nodes = [];
     74
    7375                        _.each( tinymce.editors, function( editor ) {
    74                                 var self = this;
    7576                                if ( editor.plugins.wpview ) {
    7677                                        $( editor.getBody() )
    7778                                        .find( '[data-wpview-text="' + this.encodedText + '"]' )
    78                                         .each( function ( i, element ) {
    79                                                 var contentWrap = $( element ).find( '.wpview-content' ),
    80                                                         wrap = element;
    81 
    82                                                 if ( contentWrap.length && option !== 'wrap' ) {
    83                                                         element = contentWrap = contentWrap[0];
     79                                        .each( function ( i, node ) {
     80                                                if ( callback ) {
     81                                                        callback( editor, node );
    8482                                                }
    8583
    86                                                 if ( _.isString( html ) ) {
    87                                                         if ( option === 'replace' ) {
    88                                                                 element = editor.dom.replace( editor.dom.createFragment( html ), wrap );
    89                                                         } else {
    90                                                                 editor.dom.setHTML( element, html );
    91                                                         }
    92                                                 } else {
    93                                                         if ( option === 'replace' ) {
    94                                                                 element = editor.dom.replace( html, wrap );
    95                                                         } else {
    96                                                                 $( element ).empty().append( html );
    97                                                         }
    98                                                 }
    99 
    100                                                 if ( _.isFunction( callback ) ) {
    101                                                         callback( self, editor, $( element ).find( '.wpview-content' )[0] );
     84                                                nodes.push( node );
     85                                        } );
     86                                }
     87                        }, this );
     88
     89                        return nodes;
     90                },
     91                setContent: function( html, callback, option ) {
     92                        var self = this;
     93
     94                        this.getNodes( function ( editor, element ) {
     95                                var contentWrap = $( element ).find( '.wpview-content' ),
     96                                        wrap = element;
     97
     98                                if ( contentWrap.length && option !== 'wrap' ) {
     99                                        element = contentWrap = contentWrap[0];
     100                                }
     101
     102                                if ( _.isString( html ) ) {
     103                                        if ( option === 'replace' ) {
     104                                                element = editor.dom.replace( editor.dom.createFragment( html ), wrap );
     105                                        } else {
     106                                                editor.dom.setHTML( element, html );
     107                                        }
     108                                } else {
     109                                        if ( option === 'replace' ) {
     110                                                element = editor.dom.replace( html, wrap );
     111                                        } else {
     112                                                $( element ).empty().append( html );
     113                                        }
     114                                }
     115
     116                                if ( _.isFunction( callback ) ) {
     117                                        callback( self, editor, $( element ).find( '.wpview-content' )[0] );
     118                                }
     119                        } );
     120                },
     121
     122                /* jshint scripturl: true */
     123                createIframe: function ( content ) {
     124                        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
     125
     126                        if ( content.indexOf( '<script' ) !== -1 ) {
     127                                this.getNodes( function ( editor, node ) {
     128                                        var dom = editor.dom,
     129                                                iframe, iframeDoc, i, resize;
     130
     131                                        node = $( node ).find( '.wpview-content' )[0];
     132
     133                                        node.innerHTML = '';
     134
     135                                        iframe = dom.add( node, 'iframe', {
     136                                                src: tinymce.Env.ie ? 'javascript:""' : '',
     137                                                frameBorder: '0',
     138                                                allowTransparency: 'true',
     139                                                scrolling: 'no',
     140                                                style: {
     141                                                        width: '100%',
     142                                                        display: 'block'
    102143                                                }
    103144                                        } );
    104                                 }
    105                         }, this );
    106                 },
    107 
    108                 /* jshint scripturl: true */
    109                 createIframe: function ( content ) {
    110                         var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
    111                                 iframe, iframeDoc, i, resize,
    112                                 dom = tinymce.DOM;
    113 
    114                         if ( content.indexOf( '<script' ) !== -1 ) {
    115                                 iframe = dom.create( 'iframe', {
    116                                         src: tinymce.Env.ie ? 'javascript:""' : '',
    117                                         frameBorder: '0',
    118                                         allowTransparency: 'true',
    119                                         scrolling: 'no',
    120                                         style: {
    121                                                 width: '100%',
    122                                                 display: 'block'
    123                                         }
    124                                 } );
    125 
    126                                 this.setContent( iframe );
    127                                 iframeDoc = iframe.contentWindow.document;
    128 
    129                                 iframeDoc.open();
    130                                 iframeDoc.write(
    131                                         '<!DOCTYPE html>' +
    132                                         '<html>' +
    133                                                 '<head>' +
    134                                                         '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
    135                                                 '</head>' +
    136                                                 '<body style="padding: 0; margin: 0;" class="' + dom.doc.body.className + '">' +
    137                                                         content +
    138                                                 '</body>' +
    139                                         '</html>'
    140                                 );
    141                                 iframeDoc.close();
    142 
    143                                 resize = function() {
    144                                         $( iframe ).height( $( iframeDoc.body ).height() );
    145                                 };
    146 
    147                                 if ( MutationObserver ) {
    148                                         new MutationObserver( _.debounce( function() {
    149                                                 resize();
    150                                         }, 100 ) )
    151                                         .observe( iframeDoc.body, {
    152                                                 attributes: true,
    153                                                 childList: true,
    154                                                 subtree: true
    155                                         } );
    156                                 } else {
    157                                         for ( i = 1; i < 6; i++ ) {
    158                                                 setTimeout( resize, i * 700 );
    159                                         }
    160                                 }
     145
     146                                        iframeDoc = iframe.contentWindow.document;
     147
     148                                        iframeDoc.open();
     149                                        iframeDoc.write(
     150                                                '<!DOCTYPE html>' +
     151                                                '<html>' +
     152                                                        '<head>' +
     153                                                                '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
     154                                                        '</head>' +
     155                                                        '<body style="padding: 0; margin: 0;" class="' + /* editor.getBody().className + */ '">' +
     156                                                                content +
     157                                                        '</body>' +
     158                                                '</html>'
     159                                        );
     160                                        iframeDoc.close();
     161
     162                                        resize = function() {
     163                                                $( iframe ).height( $( iframeDoc.body ).height() );
     164                                        };
     165
     166                                        if ( MutationObserver ) {
     167                                                new MutationObserver( _.debounce( function() {
     168                                                        resize();
     169                                                }, 100 ) )
     170                                                .observe( iframeDoc.body, {
     171                                                        attributes: true,
     172                                                        childList: true,
     173                                                        subtree: true
     174                                                } );
     175                                        } else {
     176                                                for ( i = 1; i < 6; i++ ) {
     177                                                        setTimeout( resize, i * 700 );
     178                                                }
     179                                        }
     180                                });
    161181                        } else {
    162182                                this.setContent( content );
     
    479499         */
    480500        wp.mce.av = {
    481                 loaded: false,
    482 
    483501                View: {
    484502                        overlay: true,
     
    538556
    539557                        /**
    540                          * Pass data to the View's Underscore template and return the compiled output
     558                         * Return parsed response
    541559                         *
    542560                         * @returns {string}
     
    544562                        getHtml: function() {
    545563                                if ( ! this.parsed ) {
    546                                         return '';
     564                                        return ' ';
    547565                                }
    548566                                return this.parsed;
     
    640658                                _.bindAll( this, 'createIframe', 'setNode', 'fetch' );
    641659                                $( this ).on( 'ready', this.setNode );
     660                        },
     661
     662                        /**
     663                         * Return parsed response
     664                         *
     665                         * @returns {string}
     666                         */
     667                        getHtml: function() {
     668                                if ( ! this.parsed ) {
     669                                        return '';
     670                                }
     671                                return this.parsed;
    642672                        }
    643673                } ),
Note: See TracChangeset for help on using the changeset viewer.