Ticket #28195: 28195.8.patch
File 28195.8.patch, 12.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
8 8 // Ensure the global `wp` object exists. 9 9 window.wp = window.wp || {}; 10 10 11 (function($){ 11 ( function( $ ) { 12 'use strict'; 13 12 14 var views = {}, 13 15 instances = {}, 14 16 media = wp.media, … … 27 29 */ 28 30 wp.mce.View = function( options ) { 29 31 options = options || {}; 32 this.type = options.type; 30 33 _.extend( this, _.pick( options, viewOptions ) ); 31 34 this.initialize.apply( this, arguments ); 32 35 }; … … 35 38 initialize: function() {}, 36 39 getHtml: function() {}, 37 40 render: function() { 38 var html = this.getHtml(); 41 var html = 42 '<div class="toolbar">' + 43 '<div class="dashicons dashicons-no-alt remove"></div>' + 44 ( _.isFunction( views[ this.type ].edit ) ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) + 45 '</div>' + 46 '<div class="wpview-content">' + 47 this.getHtml() + 48 '</div>' + 49 ( this.overlay ? '<div class="wpview-overlay"></div>' : '' ) + 50 // The <ins> is used to mark the end of the wrapper div. 51 // Needed when comparing the content as string for preventing extra undo levels. 52 '<ins data-wpview-end="1"></ins>'; 53 39 54 // Search all tinymce editor instances and update the placeholders 40 55 _.each( tinymce.editors, function( editor ) { 41 56 var self = this; 42 57 if ( editor.plugins.wpview ) { 43 $( editor.getDoc() ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each( function ( i, element ) { 44 var node = $( element ); 45 // The <ins> is used to mark the end of the wrapper div. Needed when comparing 46 // the content as string for preventing extra undo levels. 47 node.html( html ).append( '<ins data-wpview-end="1"></ins>' ); 58 $( editor.getBody() ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each( function ( i, element ) { 59 editor.dom.setHTML( element, html ); 48 60 $( self ).trigger( 'ready', element ); 49 61 }); 50 62 } 51 63 }, this ); 52 64 }, 53 unbind: function() {} 65 unbind: function() {}, 66 setContent: function( node, html ) { 67 var dom = tinymce.activeEditor.dom, 68 parent = dom.select( '.wpview-content', node )[0]; 69 70 if ( _.isString( html ) ) { 71 dom.setHTML( parent, html ); 72 } else { 73 parent.appendChild( html ); 74 } 75 } 54 76 } ); 55 77 56 78 // take advantage of the Backbone extend method … … 209 231 210 232 if ( ! wp.mce.views.getInstance( encodedText ) ) { 211 233 viewOptions = options; 234 viewOptions.type = viewType; 212 235 viewOptions.encodedText = encodedText; 213 236 instance = new view.View( viewOptions ); 214 237 instances[ encodedText ] = instance; … … 244 267 if ( ! instance ) { 245 268 result = view.toView( text ); 246 269 viewOptions = result.options; 270 viewOptions.type = view.type; 247 271 viewOptions.encodedText = encodedText; 248 272 instance = new view.View( viewOptions ); 249 273 instances[ encodedText ] = instance; … … 361 385 loaded: false, 362 386 363 387 View: _.extend( {}, wp.media.mixin, { 388 overlay: true, 389 364 390 initialize: function( options ) { 365 391 this.players = []; 366 392 this.shortcode = options.shortcode; … … 511 537 state: ['playlist-edit', 'video-playlist-edit'], 512 538 View: _.extend( {}, wp.media.mixin, { 513 539 template: media.template( 'editor-playlist' ), 540 overlay: true, 514 541 515 542 initialize: function( options ) { 516 543 this.players = []; … … 637 664 /** 638 665 * TinyMCE handler for the embed shortcode 639 666 */ 640 wp.mce.views.register( 'embed', { 641 shortcode: 'embed', 642 View: _.extend( {}, wp.media.mixin, { 643 template: media.template( 'editor-embed' ), 644 initialize: function( options ) { 645 this.players = []; 646 this.content = options.content; 647 this.parsed = false; 648 this.shortcode = options.shortcode; 649 _.bindAll( this, 'setHtml', 'setNode', 'fetch' ); 650 $( this ).on( 'ready', this.setNode ); 651 }, 652 unbind: function() { 653 var self = this; 654 _.each( this.players, function ( player ) { 655 player.pause(); 656 self.removePlayer( player ); 657 } ); 658 this.players = []; 659 }, 660 setNode: function ( e, node ) { 661 this.node = node; 662 if ( this.parsed ) { 663 this.parseMediaShortcodes(); 664 } else { 665 this.fetch(); 667 wp.mce.embedView = _.extend( {}, wp.media.mixin, { 668 overlay: true, 669 initialize: function( options ) { 670 this.players = []; 671 this.content = options.content; 672 this.parsed = false; 673 this.original = options.url || options.shortcode.string(); 674 if ( options.url ) { 675 this.shortcode = '[embed]' + options.url + '[/embed]'; 676 } else { 677 this.shortcode = options.shortcode.string(); 678 } 679 _.bindAll( this, 'setHtml', 'setNode', 'fetch' ); 680 $( this ).on( 'ready', this.setNode ); 681 }, 682 unbind: function() { 683 var self = this; 684 _.each( this.players, function ( player ) { 685 player.pause(); 686 self.removePlayer( player ); 687 } ); 688 this.players = []; 689 }, 690 setNode: function ( e, node ) { 691 this.node = node; 692 if ( this.parsed ) { 693 this.setHtml( this.parsed ); 694 this.parseMediaShortcodes(); 695 } else { 696 this.fetch(); 697 } 698 }, 699 fetch: function () { 700 var self = this; 701 wp.ajax.send( 'parse-embed', { 702 data: { 703 post_ID: $( '#post_ID' ).val(), 704 content: this.shortcode 666 705 } 667 }, 668 fetch: function () { 669 wp.ajax.send( 'parse-embed', { 670 data: { 671 post_ID: $( '#post_ID' ).val(), 672 content: this.shortcode.string() 706 } ).done( function( content ) { 707 self.parsed = content; 708 self.setHtml( content ); 709 } ); 710 }, 711 /* jshint scripturl: true */ 712 setHtml: function ( content ) { 713 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 714 $content, scripts, observer, iframe, iframeWin, iframeDoc, 715 test = '<a href', 716 dom = tinymce.activeEditor.dom; 717 718 if ( content.substring( 0, test.length ) === test ) { 719 dom.replace( dom.create( 'P', null, this.original ), this.node ); 720 } else { 721 $content = $( $.trim( content ) ); 722 scripts = $content.find( 'script' ).add( $content.filter( 'script' ) ); 723 724 if ( scripts.length ) { 725 726 iframe = dom.create( 'IFRAME', { 727 src: 'javascript:""', 728 frameBorder: '0', 729 allowTransparency: 'true', 730 style: { 731 width: '100%', 732 display: 'block' 733 } 734 } ); 735 736 this.setContent( this.node, iframe ); 737 738 iframeWin = iframe.contentWindow; 739 iframeDoc = iframeWin.document; 740 741 iframeWin.resize = function() { 742 $( iframe ).height( $( iframeDoc ).height() ); 743 }; 744 745 iframeDoc.open(); 746 iframeDoc.write( '<!DOCTYPE html><html><head><meta charset="utf-8"></head><body onload="setTimeout( resize, 1000 );">' + content + '</body></html>' ); 747 iframeDoc.close(); 748 749 if ( MutationObserver ) { 750 observer = new MutationObserver( _.debounce( function() { 751 iframeWin.resize(); 752 }, 500 ) ).observe( iframeDoc.body, { 753 attributes: true, 754 childList: true, 755 subtree: true 756 } ); 673 757 } 674 } ).done( this.setHtml ); 675 }, 676 setHtml: function ( content ) { 677 this.parsed = content; 678 $( this.node ).html( this.getHtml() ); 679 this.parseMediaShortcodes(); 680 }, 681 parseMediaShortcodes: function () { 682 var self = this; 683 $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).each( function ( i, element ) { 684 self.players.push( new MediaElementPlayer( element, self.mejsSettings ) ); 685 } ); 686 }, 687 getHtml: function() { 688 if ( ! this.parsed ) { 689 return ''; 758 } else { 759 this.setContent( this.node, content ); 690 760 } 691 return this.template({ content: this.parsed });692 761 } 693 } ), 694 edit: function() {} 762 763 this.parseMediaShortcodes(); 764 }, 765 parseMediaShortcodes: function () { 766 var self = this; 767 $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).each( function ( i, element ) { 768 self.players.push( new MediaElementPlayer( element, self.mejsSettings ) ); 769 } ); 770 }, 771 getHtml: function() { 772 return ''; 773 } 774 } ); 775 776 wp.mce.views.register( 'embed', { 777 shortcode: 'embed', 778 View: wp.mce.embedView 779 } ); 780 781 wp.mce.views.register( 'embedURL', { 782 shortcode: 'embed', 783 toView: function( content ) { 784 var re = /^<p>\s*(https?:\/\/[^\s"]+)\s*<\/p>$/gim, 785 match = re.exec( content ); 786 787 if ( ! match ) { 788 return; 789 } 790 791 return { 792 index: match.index, 793 content: match[0], 794 options: { 795 url: match[1] 796 } 797 }; 798 }, 799 View: wp.mce.embedView 695 800 } ); 696 801 697 802 }(jQuery)); -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
158 158 // matching view patterns, and transform the matches into 159 159 // view wrappers. 160 160 editor.on( 'BeforeSetContent', function( event ) { 161 var node; 162 161 163 if ( ! event.content ) { 162 164 return; 163 165 } … … 166 168 wp.mce.views.unbind( editor ); 167 169 } 168 170 169 event.content = wp.mce.views.toViews( event.content ); 170 }); 171 node = editor.selection.getNode(); 171 172 172 editor.on( 'PastePreProcess', function( event ) {173 if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/im ) ) {174 event.content = ' [embed]' + event.content + '[/embed]';173 // If a url is inserted in an empty paragraph, wrap the url in p tags so it's detected by wp.mce.views. 174 if ( node.nodeName === 'P' && editor.dom.isEmpty( node ) && event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/im ) ) { 175 event.content = '<p>' + event.content + '</p>'; 175 176 } 176 } ); 177 178 event.content = wp.mce.views.toViews( event.content ); 179 }); 177 180 178 181 // When the editor's content has been updated and the DOM has been 179 182 // processed, render the views in the document. -
src/wp-includes/media-template.php
994 994 </script> 995 995 996 996 <script type="text/html" id="tmpl-editor-gallery"> 997 <div class="toolbar">998 <div class="dashicons dashicons-edit edit"></div><div class="dashicons dashicons-no-alt remove"></div>999 </div>1000 997 <# if ( data.attachments ) { #> 1001 998 <div class="gallery gallery-columns-{{ data.columns }}"> 1002 999 <# _.each( data.attachments, function( attachment, index ) { #> … … 1027 1024 </script> 1028 1025 1029 1026 <script type="text/html" id="tmpl-editor-audio"> 1030 <div class="toolbar">1031 <div class="dashicons dashicons-edit edit"></div>1032 <div class="dashicons dashicons-no-alt remove"></div>1033 </div>1034 1027 <?php wp_underscore_audio_template() ?> 1035 <div class="wpview-overlay"></div>1036 1028 </script> 1037 1029 1038 1030 <script type="text/html" id="tmpl-editor-video"> 1039 <div class="toolbar">1040 <div class="dashicons dashicons-edit edit"></div>1041 <div class="dashicons dashicons-no-alt remove"></div>1042 </div>1043 1031 <?php wp_underscore_video_template() ?> 1044 <div class="wpview-overlay"></div>1045 1032 </script> 1046 1033 1047 1034 <?php wp_underscore_playlist_templates() ?> 1048 1035 1049 1036 <script type="text/html" id="tmpl-editor-playlist"> 1050 <div class="toolbar">1051 <div class="dashicons dashicons-edit edit"></div>1052 <div class="dashicons dashicons-no-alt remove"></div>1053 </div>1054 1037 <# if ( data.tracks ) { #> 1055 1038 <div class="wp-playlist wp-{{ data.type }}-playlist wp-playlist-{{ data.style }}"> 1056 1039 <# if ( 'audio' === data.type ){ #> … … 1062 1045 <div class="wp-playlist-next"></div> 1063 1046 <div class="wp-playlist-prev"></div> 1064 1047 </div> 1065 <div class="wpview-overlay"></div>1066 1048 <# } else { #> 1067 1049 <div class="wpview-error"> 1068 1050 <div class="dashicons dashicons-video-alt3"></div><p><?php _e( 'No items found.' ); ?></p> … … 1075 1057 <div class="upload-errors"></div> 1076 1058 </script> 1077 1059 1078 <script type="text/html" id="tmpl-editor-embed">1079 <div class="toolbar">1080 <div class="dashicons dashicons-no-alt remove"></div>1081 </div>1082 {{{ data.content }}}1083 <div class="wpview-overlay"></div>1084 </script>1085 1086 1060 <?php 1087 1061 1088 1062 /**