Ticket #31669: 31669.5.patch
File 31669.5.patch, 7.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
77 77 */ 78 78 unbind: function() { 79 79 _.each( instances, function( instance ) { 80 instance.unbind ();80 instance.unbindAll(); 81 81 } ); 82 82 }, 83 83 … … 87 87 * and creates a new instance for every match. 88 88 * 89 89 * @param {String} content The string to scan. 90 * 91 * @return {String} The string with markers. 90 92 */ 91 93 setMarkers: function( content ) { 92 94 var pieces = [ { content: content } ], … … 140 142 }, 141 143 142 144 /** 145 * The opposite of `setMarkers`. 146 * Replaces all view markup in a given string with the view text. 147 * 148 * @param {String} content The string to scan. 149 * 150 * @return {String} The string with view text. 151 */ 152 reset: function( content ) { 153 function callback() { 154 return '<p>' + decodeURIComponent( arguments[1] ) + '</p>'; 155 } 156 157 content = content.replace( /<[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^>]+>[^>]+>/g, callback ); 158 content = content.replace( /<[^>]+data-wpview-marker="([^"]+)"[^>]*>[^>]+>/g, callback ); 159 160 return content; 161 }, 162 163 /** 143 164 * Create a view instance. 144 165 * 145 166 * @param {String} type The view type. … … 298 319 /** 299 320 * Renders all view nodes tied to this view instance that are not yet rendered. 300 321 * 322 * @param {String} content The content to render. Optional. 301 323 * @param {Boolean} force Rerender all view nodes tied to this view instance. 302 324 */ 303 render: function( force ) { 325 render: function( content, force ) { 326 if ( content != null ) { 327 this.content = content; 328 } 329 330 content = this.getContent(); 331 304 332 // If there's nothing to render an no loader needs to be shown, stop. 305 if ( ! this.loader && ! this.getContent()) {333 if ( ! this.loader && ! content ) { 306 334 return; 307 335 } 308 336 309 337 // We're about to rerender all views of this instance, so unbind rendered views. 310 force && this.unbind ();338 force && this.unbindAll(); 311 339 312 340 // Replace any left over markers. 313 341 this.replaceMarkers(); 314 342 315 if ( this.getContent() ) { 316 this.setContent( this.getContent(), function( editor, node ) { 317 $( node ).data( 'rendered', true ).trigger( 'wp-mce-view-bind' ); 343 if ( content ) { 344 this.setContent( content, function( editor, node ) { 345 $( node ).data( 'rendered', true ); 346 this.bind.apply( this, arguments ); 318 347 }, force ? null : false ); 319 348 } else { 320 349 this.setLoader(); … … 322 351 }, 323 352 324 353 /** 354 * Binds a given node after its content is added to the DOM. 355 */ 356 bind: function() {}, 357 358 /** 359 * Unbinds a given node before its content is removed from the DOM. 360 */ 361 unbind: function() {}, 362 363 /** 325 364 * Unbinds all view nodes tied to this view instance. 326 365 * Runs before their content is removed from the DOM. 327 366 */ 328 unbind : function() {367 unbindAll: function() { 329 368 this.getNodes( function( editor, node ) { 369 this.unbind.apply( this, arguments ); 330 370 $( node ).trigger( 'wp-mce-view-unbind' ); 331 371 }, true ); 332 372 }, … … 461 501 * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. 462 502 */ 463 503 setIframes: function( head, body, callback, rendered ) { 464 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; 504 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 505 self = this; 465 506 466 507 this.getNodes( function( editor, node, content ) { 467 508 // Seems Firefox needs a bit of time to insert/set the view nodes, … … 582 623 editor.off( 'wp-body-class-change', classChange ); 583 624 } ); 584 625 585 callback && callback.apply( this, arguments );626 callback && callback.apply( self, arguments ); 586 627 }, 50 ); 587 628 }, rendered ); 588 629 }, … … 663 704 * @param {HTMLElement} node The view node to remove. 664 705 */ 665 706 remove: function( editor, node ) { 707 this.unbind.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 666 708 $( node ).trigger( 'wp-mce-view-unbind' ); 667 709 editor.dom.remove( node ); 668 710 } … … 726 768 } 727 769 } ); 728 770 729 self. content =self.template( {771 self.render( self.template( { 730 772 attachments: attachments, 731 773 columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns 732 } ); 733 734 self.render(); 774 } ) ); 735 775 } ) 736 776 .fail( function( jqXHR, textStatus ) { 737 777 self.setError( textStatus ); … … 752 792 } ); 753 793 } 754 794 755 wp.ajax.send( this.action, { 756 data: { 757 post_ID: postID, 758 type: this.shortcode.tag, 759 shortcode: this.shortcode.string() 760 } 795 wp.ajax.post( this.action, { 796 post_ID: postID, 797 type: this.shortcode.tag, 798 shortcode: this.shortcode.string() 761 799 } ) 762 800 .done( function( response ) { 763 self.content = response; 764 self.render(); 801 self.render( response ); 765 802 } ) 766 803 .fail( function( response ) { 767 804 if ( self.url ) { -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
151 151 }; 152 152 } 153 153 154 // Remove the content of view wrappers from HTML string155 function emptyViews( content ) {156 return content.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g, '$1' );157 }158 159 154 // Prevent adding undo levels on changes inside a view wrapper 160 155 editor.on( 'BeforeAddUndo', function( event ) { 161 if ( event.l astLevel && emptyViews( event.level.content ) === emptyViews( event.lastLevel.content )) {162 event. preventDefault();156 if ( event.level.content ) { 157 event.level.content = wp.mce.views.reset( event.level.content ); 163 158 } 164 } );159 } ); 165 160 166 161 // When the editor's content changes, scan the new content for 167 162 // matching view patterns, and transform the matches into … … 169 164 editor.on( 'BeforeSetContent', function( event ) { 170 165 var node; 171 166 172 if ( ! event.content ) { 167 if ( ! event.selection ) { 168 wp.mce.views.unbind(); 169 } 170 171 if ( ! event.content || event.wphide ) { 173 172 return; 174 173 } 175 174 … … 330 329 } 331 330 }); 332 331 333 editor.on( 'PreProcess', function( event ) { 334 // Empty the wpview wrap nodes 335 tinymce.each( editor.dom.select( 'div[data-wpview-text]', event.node ), function( node ) { 336 node.textContent = node.innerText = '\u00a0'; 337 }); 338 }); 332 editor.on( 'PostProcess', function( event ) { 333 event.content = wp.mce.views.reset( event.content ); 334 } ); 339 335 340 editor.on( 'PostProcess', function( event ) { 341 if ( event.content ) { 342 event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) { 343 if ( shortcode ) { 344 return '<p>' + window.decodeURIComponent( shortcode ) + '</p>'; 345 } 346 return ''; // If error, remove the view wrapper 347 }); 348 } 349 }); 336 editor.on( 'hide', function() { 337 var data = editor.undoManager.data; 338 339 editor.setContent( data[ data.length - 1 ].content, { format: 'raw', wphide: true } ); 340 } ); 350 341 351 342 // Excludes arrow keys, delete, backspace, enter, space bar. 352 343 // Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode