Ticket #39337: 39337.3.patch
File 39337.3.patch, 3.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/js/mce-view.js
88 88 * 89 89 * @return {String} The string with markers. 90 90 */ 91 setMarkers: function( content ) {91 setMarkers: function( content, event ) { 92 92 var pieces = [ { content: content } ], 93 93 self = this, 94 context = '', 94 95 instance, current; 95 96 96 97 _.each( views, function( view, type ) { … … 118 119 instance = self.createInstance( type, result.content, result.options ); 119 120 text = instance.loader ? '.' : instance.text; 120 121 122 if ( event ) { 123 if ( event.initial ) { 124 context = ' data-wpview-context="initial"'; 125 } else if ( ! event.load ) { 126 context = ' data-wpview-context="new"'; 127 } 128 } 129 121 130 // Add the processed piece for the match. 122 131 pieces.push( { 123 content: instance.ignore ? text : '<p data-wpview-marker="' + instance.encodedText + '" >' + text + '</p>',132 content: instance.ignore ? text : '<p data-wpview-marker="' + instance.encodedText + '"' + context + '>' + text + '</p>', 124 133 processed: true 125 134 } ); 126 135 … … 428 437 */ 429 438 replaceMarkers: function() { 430 439 this.getMarkers( function( editor, node ) { 431 var $viewNode; 440 var $viewNode, context; 441 var $node = editor.$( node ) 432 442 433 443 if ( ! this.loader && $( node ).text() !== this.text ) { 434 editor.dom.setAttrib( node, 'data-wpview-marker', null);444 $node.attr({ 'data-wpview-marker': null, 'data-wpview-context': null }); 435 445 return; 436 446 } 437 447 448 context = $node.attr( 'data-wpview-context' ); 449 438 450 $viewNode = editor.$( 439 451 '<div class="wpview wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '" contenteditable="false"></div>' 440 452 ); 441 453 442 editor.$( node ).replaceWith( $viewNode ); 454 $node.replaceWith( $viewNode ); 455 456 if ( context === 'new' ) { 457 if ( ! $viewNode.next().length ) { 458 editor.selection.select( $viewNode[0] ); 459 460 setTimeout( function() { 461 editor.selection.collapse(); 462 } ); 463 } 464 } else if ( context === 'initial' && ! $viewNode.prev().length ) { 465 // When the first element is a wpview node, make sure it is not (partially) selected. 466 editor.selection.select( editor.getBody() ); 467 editor.selection.collapse( true ); 468 } 443 469 } ); 444 470 }, 445 471 … … 448 474 */ 449 475 removeMarkers: function() { 450 476 this.getMarkers( function( editor, node ) { 451 editor. dom.setAttrib( node, 'data-wpview-marker', null);477 editor.$( node ).attr({ 'data-wpview-marker': null, 'data-wpview-context': null }); 452 478 } ); 453 479 }, 454 480 -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
88 88 } 89 89 } 90 90 91 event.content = wp.mce.views.setMarkers( event.content );91 event.content = wp.mce.views.setMarkers( event.content, event ); 92 92 } ); 93 93 94 94 // Replace any new markers nodes with views.