Ticket #28905: 28905.diff
File 28905.diff, 12.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
104 104 } 105 105 }, this ); 106 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 style: { 120 width: '100%', 121 display: 'block' 122 } 123 } ); 124 125 this.setContent( iframe ); 126 iframeDoc = iframe.contentWindow.document; 127 128 iframeDoc.open(); 129 iframeDoc.write( 130 '<!DOCTYPE html>' + 131 '<html>' + 132 '<head>' + 133 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' + 134 '</head>' + 135 '<body>' + 136 content + 137 '</body>' + 138 '</html>' 139 ); 140 iframeDoc.close(); 141 142 resize = function() { 143 $( iframe ).height( $( iframeDoc ).height() ); 144 }; 145 146 if ( MutationObserver ) { 147 new MutationObserver( _.debounce( function() { 148 resize(); 149 }, 100 ) ) 150 .observe( iframeDoc.body, { 151 attributes: true, 152 childList: true, 153 subtree: true 154 } ); 155 } else { 156 for ( i = 1; i < 6; i++ ) { 157 setTimeout( resize, i * 700 ); 158 } 159 } 160 } else { 161 this.setContent( content ); 162 } 163 }, 164 107 165 setError: function( message, dashicon ) { 108 166 this.setContent( 109 167 '<div class="wpview-error">' + … … 424 482 View: _.extend( {}, wp.media.mixin, { 425 483 overlay: true, 426 484 485 styles: [ 486 _wpmejsSettings.pluginPath + 'mediaelementplayer.min.css', 487 _wpmejsSettings.pluginPath + 'wp-mediaelement.css' 488 ], 489 490 scripts: [ 491 _wpmejsSettings.pluginPath + '../jquery/jquery.js', 492 _wpmejsSettings.pluginPath + 'mediaelement-and-player.min.js', 493 _wpmejsSettings.pluginPath + 'wp-mediaelement.js' 494 ], 495 427 496 initialize: function( options ) { 497 this.parsed = ''; 428 498 this.players = []; 429 499 this.shortcode = options.shortcode; 430 _.bindAll( this, 'setPlayer', 'pausePlayers' ); 431 $( this ).on( 'ready', this.setPlayer ); 432 $( this ).on( 'ready', function( event, editor ) { 433 editor.on( 'hide', this.pausePlayers ); 434 } ); 500 _.bindAll( this, 'pausePlayers' ); 501 $( this ).on( 'ready', this.setHtml ); 435 502 $( document ).on( 'media:edit', this.pausePlayers ); 436 503 }, 437 504 438 /** 439 * Creates the player instance for the current node 440 * 441 * @global MediaElementPlayer 442 * 443 * @param {Event} event 444 * @param {Object} editor 445 * @param {HTMLElement} node 446 */ 447 setPlayer: function( event, editor, node ) { 448 var self = this, 449 media; 505 getScripts: function() { 506 var scripts = []; 507 _.each( this.scripts, function( script ) { 508 scripts.push( '<script type="text/javascript" src="' + script + '"></script>' ); 509 } ); 510 return scripts.join( '' ); 511 }, 450 512 451 media = $( node ).find( '.wp-' + this.shortcode.tag + '-shortcode' ); 513 getStyles: function() { 514 var styles = []; 515 _.each( this.styles, function( style ) { 516 styles.push( '<link rel="stylesheet" href="' + style + '" />' ); 517 } ); 518 return styles.join( '' ); 519 }, 452 520 453 if ( ! this.isCompatible( media ) ) { 454 media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); 455 media.replaceWith( '<p>' + media.find( 'source' ).eq(0).prop( 'src' ) + '</p>' ); 456 return; 457 } else { 458 media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); 459 if ( this.ua.is( 'ff' ) ) { 460 media.prop( 'preload', 'metadata' ); 461 } else { 462 media.prop( 'preload', 'none' ); 463 } 464 } 521 setHtml: function() { 522 var template, attrs = this.shortcode.attrs.named; 523 attrs.content = this.shortcode.content; 465 524 466 media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); 467 468 setTimeout( function() { 469 wp.mce.av.loaded = true; 470 self.players.push( new MediaElementPlayer( media, self.mejsSettings ) ); 471 }, wp.mce.av.loaded ? 10 : 500 ); 525 template = this.getStyles(); 526 template += this.template( { 527 scripts: true, 528 model: _.defaults( 529 attrs, 530 wp.media[ this.shortcode.tag ].defaults 531 ) 532 } ); 533 template += this.getScripts(); 534 this.parsed = template; 535 return this.createIframe( template ); 472 536 }, 473 537 474 538 /** … … 477 541 * @returns {string} 478 542 */ 479 543 getHtml: function() { 480 var attrs = this.shortcode.attrs.named; 481 attrs.content = this.shortcode.content; 482 483 return this.template({ model: _.defaults( 484 attrs, 485 wp.media[ this.shortcode.tag ].defaults ) 486 }); 544 if ( ! this.parsed ) { 545 return this.loadingPlaceholder(); 546 } 547 return this.parsed; 487 548 }, 488 549 489 550 unbind: function() { … … 578 639 $( document ).on( 'media:edit', this.pausePlayers ); 579 640 580 641 this.fetch(); 581 582 $( this ).on( 'ready', this.setPlaylist );583 642 }, 584 643 585 644 /** … … 590 649 this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); 591 650 }, 592 651 593 setPlaylist: function( event, editor, element ) {594 if ( ! this.data.tracks ) {595 return;596 }597 598 this.players.push( new WPPlaylistView( {599 el: $( element ).find( '.wp-playlist' ).get( 0 ),600 metadata: this.data601 } ).player );602 },603 604 652 /** 605 653 * Set the data that will be used to compile the Underscore template, 606 654 * compile the template, and then return it. … … 612 660 model = wp.media.playlist, 613 661 options, 614 662 attachments, 615 tracks = []; 663 tracks = [], 664 template; 616 665 617 666 // Don't render errors while still fetching attachments 618 667 if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { … … 680 729 681 730 options.tracks = tracks; 682 731 this.data = options; 732 template = this.template( options ); 683 733 684 return this. template( options);734 return this.createIframe( template ); 685 735 }, 686 736 687 737 unbind: function() { … … 708 758 this.shortcode = options.shortcode.string(); 709 759 } 710 760 711 _.bindAll( this, ' setHtml', 'setNode', 'fetch' );761 _.bindAll( this, 'createIframe', 'setNode', 'fetch' ); 712 762 $( this ).on( 'ready', this.setNode ); 713 763 }, 714 764 unbind: function() { … … 721 771 }, 722 772 setNode: function () { 723 773 if ( this.parsed ) { 724 this.setHtml( this.parsed ); 725 this.parseMediaShortcodes(); 774 this.createIframe( this.parsed ); 726 775 } else if ( ! this.fetching ) { 727 776 this.fetch(); 728 777 } … … 744 793 .done( function( response ) { 745 794 if ( response ) { 746 795 self.parsed = response; 747 self. setHtml( response );796 self.createIframe( response ); 748 797 } 749 798 } ) 750 799 .fail( function( response ) { … … 760 809 self.setError( response.statusText, 'admin-media' ); 761 810 } 762 811 } ); 763 },764 /* jshint scripturl: true */765 setHtml: function ( content ) {766 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,767 iframe, iframeDoc, i, resize,768 dom = tinymce.DOM;769 770 if ( content.indexOf( '<script' ) !== -1 ) {771 iframe = dom.create( 'iframe', {772 src: tinymce.Env.ie ? 'javascript:""' : '',773 frameBorder: '0',774 allowTransparency: 'true',775 style: {776 width: '100%',777 display: 'block'778 }779 } );780 781 this.setContent( iframe );782 iframeDoc = iframe.contentWindow.document;783 784 iframeDoc.open();785 iframeDoc.write(786 '<!DOCTYPE html>' +787 '<html>' +788 '<head>' +789 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +790 '</head>' +791 '<body>' +792 content +793 '</body>' +794 '</html>'795 );796 iframeDoc.close();797 798 resize = function() {799 $( iframe ).height( $( iframeDoc ).height() );800 };801 802 if ( MutationObserver ) {803 new MutationObserver( _.debounce( function() {804 resize();805 }, 100 ) )806 .observe( iframeDoc.body, {807 attributes: true,808 childList: true,809 subtree: true810 } );811 } else {812 for ( i = 1; i < 6; i++ ) {813 setTimeout( resize, i * 700 );814 }815 }816 } else {817 this.setContent( content );818 }819 820 this.parseMediaShortcodes();821 },822 parseMediaShortcodes: function () {823 var self = this;824 $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).each( function ( i, element ) {825 self.players.push( new MediaElementPlayer( element, self.mejsSettings ) );826 } );827 812 } 828 813 } ); 829 814 -
src/wp-includes/media.php
1531 1531 'src' => '', 1532 1532 'loop' => '', 1533 1533 'autoplay' => '', 1534 'preload' => 'none' 1534 'preload' => 'none', 1535 'scripts' => false 1535 1536 ); 1536 1537 foreach ( $default_types as $type ) { 1537 1538 $defaults_atts[$type] = ''; … … 1573 1574 array_unshift( $default_types, 'src' ); 1574 1575 } 1575 1576 1577 $scripts = ''; 1576 1578 /** 1577 1579 * Filter the media library used for the audio shortcode. 1578 1580 * … … 1582 1584 */ 1583 1585 $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); 1584 1586 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 1585 wp_enqueue_style( 'wp-mediaelement' ); 1586 wp_enqueue_script( 'wp-mediaelement' ); 1587 if ( $atts['scripts'] ) { 1588 ob_start(); 1589 wp_print_styles( 'wp-mediaelement' ); 1590 wp_print_scripts( 'wp-mediaelement' ); 1591 $scripts = ob_get_clean(); 1592 } else { 1593 wp_enqueue_style( 'wp-mediaelement' ); 1594 wp_enqueue_script( 'wp-mediaelement' ); 1595 } 1587 1596 } 1588 1597 1589 1598 /** … … 1637 1646 $html .= wp_mediaelement_fallback( $fileurl ); 1638 1647 } 1639 1648 $html .= '</audio>'; 1640 1649 if ( ! empty( $scripts ) ) { 1650 $html .= $scripts; 1651 } 1641 1652 /** 1642 1653 * Filter the audio shortcode output. 1643 1654 * … … 1736 1747 'preload' => 'metadata', 1737 1748 'width' => 640, 1738 1749 'height' => 360, 1750 'scripts' => false, 1739 1751 ); 1740 1752 1741 1753 foreach ( $default_types as $type ) { … … 1796 1808 array_unshift( $default_types, 'src' ); 1797 1809 } 1798 1810 1811 $scripts = ''; 1799 1812 /** 1800 1813 * Filter the media library used for the video shortcode. 1801 1814 * … … 1805 1818 */ 1806 1819 $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); 1807 1820 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 1808 wp_enqueue_style( 'wp-mediaelement' ); 1809 wp_enqueue_script( 'wp-mediaelement' ); 1821 if ( $atts['scripts'] ) { 1822 ob_start(); 1823 wp_print_styles( 'wp-mediaelement' ); 1824 wp_print_scripts( 'wp-mediaelement' ); 1825 $scripts = ob_get_clean(); 1826 } else { 1827 wp_enqueue_style( 'wp-mediaelement' ); 1828 wp_enqueue_script( 'wp-mediaelement' ); 1829 } 1810 1830 } 1811 1831 1812 1832 /** … … 1873 1893 $html .= wp_mediaelement_fallback( $fileurl ); 1874 1894 } 1875 1895 $html .= '</video>'; 1896 if ( ! empty( $scripts ) ) { 1897 $html .= $scripts; 1898 } 1876 1899 1877 1900 $output = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $atts['width'], $html ); 1878 1901 … … 2324 2347 * @return string The embed HTML. 2325 2348 */ 2326 2349 function wp_embed_handler_audio( $matches, $attr, $url, $rawattr ) { 2327 $audio = sprintf( '[audio src="%s" /]', esc_url( $url ) ); 2350 if ( defined( 'DOING_AJAX' ) && DOING_AJAX && 'parse-embed' === $_REQUEST['action'] ) { 2351 $audio = sprintf( '[audio scripts="1" src="%s"]', esc_url( $url ) ); 2352 } else { 2353 $audio = sprintf( '[audio src="%s"]', esc_url( $url ) ); 2354 } 2328 2355 2329 2356 /** 2330 2357 * Filter the audio embed output. … … 2356 2383 $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] ); 2357 2384 $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] ); 2358 2385 } 2359 $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) ); 2386 if ( defined( 'DOING_AJAX' ) && DOING_AJAX && 'parse-embed' === $_REQUEST['action'] ) { 2387 $video = sprintf( '[video scripts="1" %s src="%s"]', $dimensions, esc_url( $url ) ); 2388 } else { 2389 $video = sprintf( '[video %s src="%s"]', $dimensions, esc_url( $url ) ); 2390 } 2360 2391 2361 2392 /** 2362 2393 * Filter the video embed output.