Ticket #31669: 31669.13.patch
File 31669.13.patch, 8.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
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 } ], … … 298 300 /** 299 301 * Renders all view nodes tied to this view instance that are not yet rendered. 300 302 * 303 * @param {String} content The content to render. Optional. 301 304 * @param {Boolean} force Rerender all view nodes tied to this view instance. 302 305 */ 303 render: function( force ) { 306 render: function( content, force ) { 307 if ( content != null ) { 308 this.content = content; 309 } 310 311 content = this.getContent(); 312 304 313 // If there's nothing to render an no loader needs to be shown, stop. 305 if ( ! this.loader && ! this.getContent()) {314 if ( ! this.loader && ! content ) { 306 315 return; 307 316 } 308 317 … … 312 321 // Replace any left over markers. 313 322 this.replaceMarkers(); 314 323 315 if ( this.getContent() ) { 316 this.setContent( this.getContent(), function( editor, node ) { 317 $( node ).data( 'rendered', true ).trigger( 'wp-mce-view-bind' ); 324 if ( content ) { 325 this.setContent( content, function( editor, node ) { 326 $( node ).data( 'rendered', true ); 327 this.bindNode.apply( this, arguments ); 318 328 }, force ? null : false ); 319 329 } else { 320 330 this.setLoader(); … … 322 332 }, 323 333 324 334 /** 335 * Binds a given node after its content is added to the DOM. 336 */ 337 bindNode: function() {}, 338 339 /** 340 * Unbinds a given node before its content is removed from the DOM. 341 */ 342 unbindNode: function() {}, 343 344 /** 325 345 * Unbinds all view nodes tied to this view instance. 326 346 * Runs before their content is removed from the DOM. 327 347 */ 328 348 unbind: function() { 329 349 this.getNodes( function( editor, node ) { 350 this.unbindNode.apply( this, arguments ); 330 351 $( node ).trigger( 'wp-mce-view-unbind' ); 331 352 }, true ); 332 353 }, … … 461 482 * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. 462 483 */ 463 484 setIframes: function( head, body, callback, rendered ) { 464 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; 485 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 486 self = this; 465 487 466 488 this.getNodes( function( editor, node, content ) { 467 // Seems Firefox needs a bit of time to insert/set the view nodes, 489 var dom = editor.dom, 490 styles = '', 491 bodyClasses = editor.getBody().className || '', 492 iframe, iframeDoc, observer, i; 493 494 tinymce.each( dom.$( 495 'link[rel="stylesheet"]', 496 editor.getDoc().getElementsByTagName( 'head' )[0] 497 ), function( link ) { 498 if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 && 499 link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) { 500 501 styles += dom.getOuterHTML( link ); 502 } 503 } ); 504 505 // Seems the browsers need a bit of time to insert/set the view nodes, 468 506 // or the iframe will fail especially when switching Text => Visual. 469 507 setTimeout( function() { 470 var dom = editor.dom,471 styles = '',472 bodyClasses = editor.getBody().className || '',473 iframe, iframeDoc, observer, i;474 475 tinymce.each( dom.$(476 'link[rel="stylesheet"]',477 editor.getDoc().getElementsByTagName( 'head' )[0]478 ), function( link ) {479 if (480 link.href &&481 link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&482 link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1483 ) {484 styles += dom.getOuterHTML( link );485 }486 } );487 488 508 content.innerHTML = ''; 489 509 490 510 iframe = dom.add( content, 'iframe', { … … 582 602 editor.off( 'wp-body-class-change', classChange ); 583 603 } ); 584 604 585 callback && callback.apply( this, arguments );605 callback && callback.apply( self, arguments ); 586 606 }, 50 ); 587 607 }, rendered ); 588 608 }, … … 664 684 * @param {HTMLElement} node The view node to remove. 665 685 */ 666 686 remove: function( editor, node ) { 687 this.unbindNode.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 667 688 $( node ).trigger( 'wp-mce-view-unbind' ); 668 689 editor.dom.remove( node ); 669 690 editor.focus(); … … 728 749 } 729 750 } ); 730 751 731 self. content =self.template( {752 self.render( self.template( { 732 753 attachments: attachments, 733 754 columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns 734 } ); 735 736 self.render(); 755 } ) ); 737 756 } ) 738 757 .fail( function( jqXHR, textStatus ) { 739 758 self.setError( textStatus ); … … 754 773 } ); 755 774 } 756 775 757 wp.ajax.send( this.action, { 758 data: { 759 post_ID: postID, 760 type: this.shortcode.tag, 761 shortcode: this.shortcode.string() 762 } 776 wp.ajax.post( this.action, { 777 post_ID: postID, 778 type: this.shortcode.tag, 779 shortcode: this.shortcode.string() 763 780 } ) 764 781 .done( function( response ) { 765 self.content = response; 766 self.render(); 782 self.render( response ); 767 783 } ) 768 784 .fail( function( response ) { 769 785 if ( self.url ) { -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
4 4 * WordPress View plugin. 5 5 */ 6 6 tinymce.PluginManager.add( 'wpview', function( editor ) { 7 var selected, 7 var $ = editor.$, 8 selected, 8 9 Env = tinymce.Env, 9 10 VK = tinymce.util.VK, 10 11 TreeWalker = tinymce.dom.TreeWalker, … … 153 154 154 155 // Remove the content of view wrappers from HTML string 155 156 function emptyViews( content ) { 156 return content.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g, '$1' ); 157 content = content.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g, function( all, match ) { 158 return '<p>' + window.decodeURIComponent( match ) + '</p>'; 159 }); 160 161 return content.replace( / data-wpview-marker="[^"]+"/g, '' ); 157 162 } 158 163 159 164 // Prevent adding undo levels on changes inside a view wrapper 160 165 editor.on( 'BeforeAddUndo', function( event ) { 161 if ( event.l astLevel && emptyViews( event.level.content ) === emptyViews( event.lastLevel.content )) {162 event. preventDefault();166 if ( event.level.content ) { 167 event.level.content = emptyViews( event.level.content ); 163 168 } 164 169 }); 165 170 … … 169 174 editor.on( 'BeforeSetContent', function( event ) { 170 175 var node; 171 176 177 if ( ! event.selection ) { 178 wp.mce.views.unbind(); 179 } 180 172 181 if ( ! event.content ) { 173 182 return; 174 183 } … … 339 348 } 340 349 }); 341 350 342 editor.on( 'PreProcess', function( event ) { 343 // Empty the wpview wrap nodes 344 tinymce.each( editor.dom.select( 'div[data-wpview-text]', event.node ), function( node ) { 345 node.textContent = node.innerText = '\u00a0'; 351 function resetViews( rootNode ) { 352 // Replace view nodes 353 $( 'div[data-wpview-text]', rootNode ).each( function( i, node ) { 354 var $node = $( node ), 355 text = window.decodeURIComponent( $node.attr( 'data-wpview-text' ) || '' ); 356 357 if ( text && node.parentNode ) { 358 $node.replaceWith( $( editor.dom.create('p') ).text( text ) ); 359 } 346 360 }); 347 });348 361 349 editor.on( 'PostProcess', function( event ) { 350 if ( event.content ) { 351 event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) { 352 if ( shortcode ) { 353 return '<p>' + window.decodeURIComponent( shortcode ) + '</p>'; 354 } 355 return ''; // If error, remove the view wrapper 356 }); 357 } 362 // Remove marker attributes 363 $( 'p[data-wpview-marker]', rootNode ).attr( 'data-wpview-marker', null ); 364 } 365 366 editor.on( 'PreProcess', function( event ) { 367 // Replace the view nodes with their text in the DOM clone. 368 resetViews( event.node ); 369 }, true ); 370 371 editor.on( 'hide', function() { 372 // Replace the view nodes with their text directly in the editor body. 373 wp.mce.views.unbind(); 374 resetViews( editor.getBody() ); 358 375 }); 359 376 360 377 // Excludes arrow keys, delete, backspace, enter, space bar.