Ticket #28905: 28905.3.diff
File 28905.3.diff, 18.3 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-editor.php
516 516 517 517 // load editor_style.css if the current theme supports it 518 518 if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { 519 $editor_styles = $GLOBALS['editor_styles']; 520 521 $editor_styles = array_unique( array_filter( $editor_styles ) ); 522 $style_uri = get_stylesheet_directory_uri(); 523 $style_dir = get_stylesheet_directory(); 524 525 // Support externally referenced styles (like, say, fonts). 526 foreach ( $editor_styles as $key => $file ) { 527 if ( preg_match( '~^(https?:)?//~', $file ) ) { 528 $mce_css[] = esc_url_raw( $file ); 529 unset( $editor_styles[ $key ] ); 519 $editor_styles = get_editor_stylesheets(); 520 if ( ! empty( $editor_styles ) ) { 521 foreach ( $editor_styles as $style ) { 522 $mce_css[] = $style; 530 523 } 531 524 } 532 533 // Look in a parent theme first, that way child theme CSS overrides.534 if ( is_child_theme() ) {535 $template_uri = get_template_directory_uri();536 $template_dir = get_template_directory();537 538 foreach ( $editor_styles as $key => $file ) {539 if ( $file && file_exists( "$template_dir/$file" ) )540 $mce_css[] = "$template_uri/$file";541 }542 }543 544 foreach ( $editor_styles as $file ) {545 if ( $file && file_exists( "$style_dir/$file" ) )546 $mce_css[] = "$style_uri/$file";547 }548 525 } 549 526 550 527 /** -
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 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;">' + 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 } 161 } else { 162 this.setContent( content ); 163 } 164 }, 165 107 166 setError: function( message, dashicon ) { 108 167 this.setContent( 109 168 '<div class="wpview-error">' + … … 111 170 '<p>' + message + '</p>' + 112 171 '</div>' 113 172 ); 173 }, 174 175 getScripts: function() { 176 var scripts = []; 177 _.each( this.scripts, function( script ) { 178 scripts.push( '<script type="text/javascript" src="' + script + '"></script>' ); 179 } ); 180 return scripts.join( '' ); 181 }, 182 183 getStyles: function() { 184 var styles = []; 185 _.each( [ this.styles, _wpmejsSettings.editorStylesheets ], function( stylesheets ) { 186 _.each( stylesheets, function( style ) { 187 styles.push( '<link rel="stylesheet" href="' + style + '" />' ); 188 } ); 189 } ); 190 return styles.join( '' ); 114 191 } 115 192 } ); 116 193 … … 424 501 View: _.extend( {}, wp.media.mixin, { 425 502 overlay: true, 426 503 504 styles: [ 505 _wpmejsSettings.pluginPath + 'mediaelementplayer.min.css', 506 _wpmejsSettings.pluginPath + 'wp-mediaelement.css' 507 ], 508 509 scripts: [ 510 _wpmejsSettings.includesPath + 'jquery/jquery.js', 511 _wpmejsSettings.pluginPath + 'mediaelement-and-player.min.js', 512 _wpmejsSettings.pluginPath + 'wp-mediaelement.js' 513 ], 514 427 515 initialize: function( options ) { 516 this.parsed = ''; 428 517 this.players = []; 429 518 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 } ); 519 _.bindAll( this, 'pausePlayers' ); 520 $( this ).on( 'ready', this.setHtml ); 435 521 $( document ).on( 'media:edit', this.pausePlayers ); 436 522 }, 437 523 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; 524 setHtml: function() { 525 var template, attrs = this.shortcode.attrs.named; 526 attrs.content = this.shortcode.content; 450 527 451 media = $( node ).find( '.wp-' + this.shortcode.tag + '-shortcode' ); 452 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 } 465 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 ); 528 template = this.getStyles(); 529 template += this.template( { 530 scripts: true, 531 model: _.defaults( 532 attrs, 533 wp.media[ this.shortcode.tag ].defaults 534 ) 535 } ); 536 template += this.getScripts(); 537 this.parsed = template; 538 return this.createIframe( template ); 472 539 }, 473 540 474 541 /** … … 477 544 * @returns {string} 478 545 */ 479 546 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 }); 547 if ( ! this.parsed ) { 548 return this.loadingPlaceholder(); 549 } 550 return this.parsed; 487 551 }, 488 552 489 553 unbind: function() { … … 571 635 this.data = {}; 572 636 this.attachments = []; 573 637 this.shortcode = options.shortcode; 638 this.dfd = false; 639 this.fetching = false; 574 640 575 $( this ).on( 'ready', function( event, editor ) { 576 editor.on( 'hide', this.pausePlayers ); 577 } ); 578 $( document ).on( 'media:edit', this.pausePlayers ); 641 $( this ).on( 'ready', _.bind( this.setNode, this ) ); 642 }, 579 643 580 this.fetch(); 644 styles: [ 645 _wpmejsSettings.pluginPath + 'mediaelementplayer.min.css', 646 _wpmejsSettings.pluginPath + 'wp-mediaelement.css' 647 ], 581 648 582 $( this ).on( 'ready', this.setPlaylist ); 649 scripts: [ 650 _wpmejsSettings.includesPath + 'jquery/jquery.js', 651 _wpmejsSettings.includesPath + 'underscore.min.js', 652 _wpmejsSettings.includesPath + 'backbone.min.js', 653 _wpmejsSettings.includesPath + 'wp-util.js', 654 _wpmejsSettings.pluginPath + 'mediaelement-and-player.min.js', 655 _wpmejsSettings.pluginPath + 'wp-playlist.js' 656 ], 657 658 setNode: function () { 659 if ( this.parsed ) { 660 this.createIframe( this.parsed ); 661 } else if ( ! this.fetching ) { 662 this.fetch(); 663 } 583 664 }, 584 665 585 666 /** 586 667 * Asynchronously fetch the shortcode's attachments 587 668 */ 588 fetch: function() { 669 fetch: function () { 670 var self = this; 671 672 this.fetching = true; 673 589 674 this.attachments = wp.media.playlist.attachments( this.shortcode ); 590 this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); 591 }, 675 this.dfd = this.attachments.more(); 592 676 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.data 601 } ).player ); 677 this.dfd 678 .always( function() { 679 self.fetching = false; 680 } ) 681 .done( function( response ) { 682 if ( response ) { 683 self.parsed = self.setHtml( response ); 684 self.createIframe( self.parsed ); 685 } 686 } ); 602 687 }, 603 688 604 689 /** … … 607 692 * 608 693 * @returns {string} 609 694 */ 610 getHtml: function() {695 setHtml: function() { 611 696 var data = this.shortcode.attrs.named, 612 697 model = wp.media.playlist, 613 698 options, 614 699 attachments, 615 tracks = []; 700 tracks = [], 701 template; 616 702 617 703 // Don't render errors while still fetching attachments 618 704 if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { 619 return ''; 705 this.parsed = ''; 706 return; 620 707 } 621 708 622 709 _.each( model.defaults, function( value, key ) { … … 680 767 681 768 options.tracks = tracks; 682 769 this.data = options; 770 template = this.getStyles(); 771 template += this.template( options ); 772 template += this.getScripts(); 773 this.parsed = template; 774 return template; 775 }, 683 776 684 return this.template( options ); 777 getHtml: function() { 778 if ( ! this.parsed ) { 779 return this.loadingPlaceholder(); 780 } 781 return this.parsed; 685 782 }, 686 783 687 784 unbind: function() { … … 708 805 this.shortcode = options.shortcode.string(); 709 806 } 710 807 711 _.bindAll( this, ' setHtml', 'setNode', 'fetch' );808 _.bindAll( this, 'createIframe', 'setNode', 'fetch' ); 712 809 $( this ).on( 'ready', this.setNode ); 713 810 }, 714 811 unbind: function() { … … 721 818 }, 722 819 setNode: function () { 723 820 if ( this.parsed ) { 724 this.setHtml( this.parsed ); 725 this.parseMediaShortcodes(); 821 this.createIframe( this.parsed ); 726 822 } else if ( ! this.fetching ) { 727 823 this.fetch(); 728 824 } … … 744 840 .done( function( response ) { 745 841 if ( response ) { 746 842 self.parsed = response; 747 self. setHtml( response );843 self.createIframe( response ); 748 844 } 749 845 } ) 750 846 .fail( function( response ) { … … 760 856 self.setError( response.statusText, 'admin-media' ); 761 857 } 762 858 } ); 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 859 } 828 860 } ); 829 861 -
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. -
src/wp-includes/script-loader.php
323 323 324 324 $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.js", array('mediaelement'), false, 1 ); 325 325 did_action( 'init' ) && $scripts->localize( 'mediaelement', '_wpmejsSettings', array( 326 'includesPath' => includes_url( 'js/', 'relative' ), 326 327 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ), 328 'editorStylesheets' => get_editor_stylesheets() 327 329 ) ); 328 330 329 331 $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 ); … … 510 512 $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), false, 1 ); 511 513 512 514 $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" ); 513 515 514 516 $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 ); 515 517 $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 ); 516 518 did_action( 'init' ) && $scripts->localize( 'media', 'attachMediaBoxL10n', array( … … 1033 1035 } 1034 1036 } 1035 1037 1038 function get_editor_stylesheets() { 1039 $stylesheets = array(); 1040 // load editor_style.css if the current theme supports it 1041 if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { 1042 $editor_styles = $GLOBALS['editor_styles']; 1043 1044 $editor_styles = array_unique( array_filter( $editor_styles ) ); 1045 $style_uri = get_stylesheet_directory_uri(); 1046 $style_dir = get_stylesheet_directory(); 1047 1048 // Support externally referenced styles (like, say, fonts). 1049 foreach ( $editor_styles as $key => $file ) { 1050 if ( preg_match( '~^(https?:)?//~', $file ) ) { 1051 $stylesheets[] = esc_url_raw( $file ); 1052 unset( $editor_styles[ $key ] ); 1053 } 1054 } 1055 1056 // Look in a parent theme first, that way child theme CSS overrides. 1057 if ( is_child_theme() ) { 1058 $template_uri = get_template_directory_uri(); 1059 $template_dir = get_template_directory(); 1060 1061 foreach ( $editor_styles as $key => $file ) { 1062 if ( $file && file_exists( "$template_dir/$file" ) ) { 1063 $stylesheets[] = "$template_uri/$file"; 1064 } 1065 } 1066 } 1067 1068 foreach ( $editor_styles as $file ) { 1069 if ( $file && file_exists( "$style_dir/$file" ) ) { 1070 $stylesheets[] = "$style_uri/$file"; 1071 } 1072 } 1073 } 1074 return $stylesheets; 1075 } 1076 1036 1077 add_action( 'wp_default_scripts', 'wp_default_scripts' ); 1037 1078 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); 1038 1079 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );