Ticket #28905: 28905.5.patch
File 28905.5.patch, 8.1 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
47 47 '</div>'; 48 48 }, 49 49 render: function() { 50 var html = this.getHtml() || this.loadingPlaceholder();51 52 50 this.setContent( 53 51 '<p class="wpview-selection-before">\u00a0</p>' + 54 52 '<div class="wpview-body" contenteditable="false">' + … … 57 55 '<div class="dashicons dashicons-no-alt remove"></div>' + 58 56 '</div>' + 59 57 '<div class="wpview-content wpview-type-' + this.type + '">' + 60 html+58 ( this.getHtml() || this.loadingPlaceholder() ) + 61 59 '</div>' + 62 60 ( this.overlay ? '<div class="wpview-overlay"></div>' : '' ) + 63 61 '</div>' + 64 62 '<p class="wpview-selection-after">\u00a0</p>', 65 function( self, editor, node ) {66 $( self ).trigger( 'ready', [ editor, node ] );67 },68 63 'wrap' 69 64 ); 65 66 $( this ).trigger( 'ready' ); 70 67 }, 71 68 unbind: function() {}, 72 get Nodes: function( callback ) {73 var nodes = [];69 getEditors: function( callback ) { 70 var editors = []; 74 71 75 72 _.each( tinymce.editors, function( editor ) { 76 73 if ( editor.plugins.wpview ) { 77 $( editor.getBody() ) 78 .find( '[data-wpview-text="' + this.encodedText + '"]' ) 79 .each( function ( i, node ) { 80 if ( callback ) { 81 callback( editor, node ); 82 } 74 if ( callback ) { 75 callback( editor ); 76 } 83 77 84 nodes.push( node ); 85 } ); 78 editors.push( editor ); 86 79 } 87 80 }, this ); 88 81 89 return nodes;82 return editors; 90 83 }, 91 setContent: function( html, callback, option ) { 92 var self = this; 84 getNodes: function( callback ) { 85 var nodes = [], 86 self = this; 93 87 94 this.getNodes( function ( editor, element ) { 95 var contentWrap = $( element ).find( '.wpview-content' ), 96 wrap = element; 88 this.getEditors( function( editor ) { 89 $( editor.getBody() ) 90 .find( '[data-wpview-text="' + self.encodedText + '"]' ) 91 .each( function ( i, node ) { 92 if ( callback ) { 93 callback( editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 94 } 97 95 98 if ( contentWrap.length && option !== 'wrap' ) {99 element = contentWrap = contentWrap[0];100 }96 nodes.push( node ); 97 } ); 98 } ); 101 99 102 if ( _.isString( html ) ) { 103 if ( option === 'replace' ) { 104 element = editor.dom.replace( editor.dom.createFragment( html ), wrap ); 105 } else { 106 editor.dom.setHTML( element, html ); 107 } 108 } else { 109 if ( option === 'replace' ) { 110 element = editor.dom.replace( html, wrap ); 111 } else { 112 $( element ).empty().append( html ); 113 } 100 return nodes; 101 }, 102 setContent: function( html, option ) { 103 this.getNodes( function ( editor, node, content ) { 104 var el = ( option === 'wrap' || option === 'replace' ) ? node : content, 105 insert = html; 106 107 if ( _.isString( insert ) ) { 108 insert = editor.dom.createFragment( insert ); 114 109 } 115 110 116 if ( _.isFunction( callback ) ) { 117 callback( self, editor, $( element ).find( '.wpview-content' )[0] ); 111 if ( option === 'replace' ) { 112 editor.dom.replace( insert, el ); 113 } else { 114 el.innerHTML = ''; 115 el.appendChild( insert ); 118 116 } 119 117 } ); 120 118 }, 121 122 119 /* jshint scripturl: true */ 123 createIframe: function ( content) {120 setIframes: function ( html ) { 124 121 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; 125 122 126 if ( content.indexOf( '<script' ) !== -1 ) {127 this.getNodes( function ( editor, node ) {123 if ( html.indexOf( '<script' ) !== -1 ) { 124 this.getNodes( function ( editor, node, content ) { 128 125 var dom = editor.dom, 129 126 iframe, iframeDoc, i, resize; 130 127 131 node = $( node ).find( '.wpview-content' )[0]; 132 if ( ! node ) { 133 return; 134 } 135 node.innerHTML = ''; 128 content.innerHTML = ''; 136 129 137 iframe = dom.add( node, 'iframe', {130 iframe = dom.add( content, 'iframe', { 138 131 src: tinymce.Env.ie ? 'javascript:""' : '', 139 132 frameBorder: '0', 140 133 allowTransparency: 'true', … … 155 148 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' + 156 149 '</head>' + 157 150 '<body data-context="iframe-sandbox" style="padding: 0; margin: 0;" class="' + editor.getBody().className + '">' + 158 content+151 html + 159 152 '</body>' + 160 153 '</html>' 161 154 ); … … 182 175 } 183 176 }); 184 177 } else { 185 this.setContent( content);178 this.setContent( html ); 186 179 } 187 180 }, 188 189 181 setError: function( message, dashicon ) { 190 182 this.setContent( 191 183 '<div class="wpview-error">' + … … 507 499 action: 'parse-media-shortcode', 508 500 509 501 initialize: function( options ) { 502 var self = this; 503 510 504 this.shortcode = options.shortcode; 511 this.fetching = false;512 505 513 _.bindAll( this, ' createIframe', 'setNode', 'fetch', 'pausePlayers' );514 $( this ).on( 'ready', this.setNode );506 _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'pausePlayers' ); 507 $( this ).on( 'ready', this.setNodes ); 515 508 516 509 $( document ).on( 'media:edit', this.pausePlayers ); 517 },518 510 519 setNode: function ( event, editor ) { 520 editor.on( 'hide', this.pausePlayers ); 511 this.fetch(); 512 513 this.getEditors( function( editor ) { 514 editor.on( 'hide', self.pausePlayers ); 515 }); 516 }, 521 517 518 setNodes: function () { 522 519 if ( this.parsed ) { 523 this.createIframe( this.parsed ); 524 } else if ( ! this.fetching ) { 525 this.fetch(); 520 this.setIframes( this.parsed ); 526 521 } 527 522 }, 528 523 529 524 fetch: function () { 530 525 var self = this; 531 this.fetching = true;532 526 533 527 wp.ajax.send( this.action, { 534 528 data: { … … 537 531 shortcode: this.shortcode.string() 538 532 } 539 533 } ) 540 .always( function() {541 self.fetching = false;542 } )543 534 .done( function( response ) { 544 535 if ( response ) { 545 536 self.parsed = response; 546 self. createIframe( response );537 self.setIframes( response ); 547 538 } 548 539 } ) 549 540 .fail( function( response ) { … … 553 544 554 545 self.setError( response.message, 'admin-media' ); 555 546 } else { 556 self.setContent( '<p>' + self.original + '</p>', null,'replace' );547 self.setContent( '<p>' + self.original + '</p>', 'replace' ); 557 548 } 558 549 } else if ( response && response.statusText ) { 559 550 self.setError( response.statusText, 'admin-media' ); … … 561 552 } ); 562 553 }, 563 554 564 /**565 * Return parsed response566 *567 * @returns {string}568 */569 getHtml: function() {570 if ( ! this.parsed ) {571 return ' ';572 }573 return this.parsed;574 },575 576 555 pausePlayers: function() { 577 this.getNodes( function( editor, node ) {578 var p, win = $( 'iframe', node).get(0).contentWindow;556 this.getNodes( function( editor, node, content ) { 557 var p, win = $( 'iframe', content ).get(0).contentWindow; 579 558 580 559 if ( win && win.mejs ) { 581 560 for ( p in win.mejs.players ) { … … 586 565 }, 587 566 588 567 unsetPlayers: function() { 589 this.getNodes( function( editor, node ) {590 var p, win = $( 'iframe', node).get(0).contentWindow;568 this.getNodes( function( editor, node, content ) { 569 var p, win = $( 'iframe', content ).get(0).contentWindow; 591 570 592 571 if ( win && win.mejs ) { 593 572 for ( p in win.mejs.players ) { … … 679 658 action: 'parse-embed', 680 659 initialize: function( options ) { 681 660 this.content = options.content; 682 this.fetching = false;683 this.parsed = false;684 661 this.original = options.url || options.shortcode.string(); 685 662 686 663 if ( options.url ) { … … 691 668 this.shortcode = options.shortcode; 692 669 } 693 670 694 _.bindAll( this, 'createIframe', 'setNode', 'fetch' ); 695 $( this ).on( 'ready', this.setNode ); 696 }, 671 _.bindAll( this, 'setIframes', 'setNodes', 'fetch' ); 672 $( this ).on( 'ready', this.setNodes ); 697 673 698 /** 699 * Return parsed response 700 * 701 * @returns {string} 702 */ 703 getHtml: function() { 704 if ( ! this.parsed ) { 705 return ''; 706 } 707 return this.parsed; 674 this.fetch(); 708 675 } 709 676 } ), 710 677 edit: function( node ) {