X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53f4633144ed68c8b8fb5861f992b5489894a940..b22765f41bf0b2021b9beb9120ee0ac91fa89292:/wp-includes/js/mce-view.js diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index c0ae6680..3d2616d7 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -120,7 +120,7 @@ // Add the processed piece for the match. pieces.push( { - content: '

' + text + '

', + content: instance.ignore ? text : '

' + text + '

', processed: true } ); @@ -327,9 +327,9 @@ this.replaceMarkers(); if ( content ) { - this.setContent( content, function( editor, node, contentNode ) { + this.setContent( content, function( editor, node ) { $( node ).data( 'rendered', true ); - this.bindNode.call( this, editor, node, contentNode ); + this.bindNode.call( this, editor, node ); }, force ? null : false ); } else { this.setLoader(); @@ -351,9 +351,8 @@ * Runs before their content is removed from the DOM. */ unbind: function() { - this.getNodes( function( editor, node, contentNode ) { - this.unbindNode.call( this, editor, node, contentNode ); - $( node ).trigger( 'wp-mce-view-unbind' ); + this.getNodes( function( editor, node ) { + this.unbindNode.call( this, editor, node ); }, true ); }, @@ -394,7 +393,7 @@ return rendered ? data : ! data; } ) .each( function() { - callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) ); + callback.call( self, editor, this, this /* back compat */ ); } ); } ); }, @@ -421,8 +420,7 @@ */ replaceMarkers: function() { this.getMarkers( function( editor, node ) { - var selected = node === editor.selection.getNode(), - $viewNode; + var $viewNode; if ( ! this.loader && $( node ).text() !== this.text ) { editor.dom.setAttrib( node, 'data-wpview-marker', null ); @@ -430,20 +428,10 @@ } $viewNode = editor.$( - '
' + - '

\u00a0

' + - '
' + - '
' + - '
' + - '

\u00a0

' + - '
' + '
' ); editor.$( node ).replaceWith( $viewNode ); - - if ( selected ) { - editor.wp.setViewCursor( false, $viewNode[0] ); - } } ); }, @@ -469,17 +457,20 @@ } else if ( _.isString( content ) && content.indexOf( ' Visual. setTimeout( function() { - var iframe, iframeDoc, observer, i, block; - - contentNode.innerHTML = ''; + var iframe, iframeWin, iframeDoc, MutationObserver, observer, i, block; + + editor.undoManager.transact( function() { + node.innerHTML = ''; + + iframe = dom.add( node, 'iframe', { + /* jshint scripturl: true */ + src: tinymce.Env.ie ? 'javascript:""' : '', + frameBorder: '0', + allowTransparency: 'true', + scrolling: 'no', + 'class': 'wpview-sandbox', + style: { + width: '100%', + display: 'block' + }, + height: self.iframeHeight + } ); - iframe = dom.add( contentNode, 'iframe', { - /* jshint scripturl: true */ - src: tinymce.Env.ie ? 'javascript:""' : '', - frameBorder: '0', - allowTransparency: 'true', - scrolling: 'no', - 'class': 'wpview-sandbox', - style: { - width: '100%', - display: 'block' - }, - height: self.iframeHeight + dom.add( node, 'span', { 'class': 'mce-shim' } ); + dom.add( node, 'span', { 'class': 'wpview-end' } ); } ); - dom.add( contentNode, 'div', { 'class': 'wpview-overlay' } ); - - iframeDoc = iframe.contentWindow.document; + // Bail if the iframe node is not attached to the DOM. + // Happens when the view is dragged in the editor. + // There is a browser restriction when iframes are moved in the DOM. They get emptied. + // The iframe will be rerendered after dropping the view node at the new location. + if ( ! iframe.contentWindow ) { + return; + } + iframeWin = iframe.contentWindow; + iframeDoc = iframeWin.document; iframeDoc.open(); iframeDoc.write( @@ -605,7 +610,9 @@ }, 3000 ); } - $( iframe.contentWindow ).on( 'load', resize ); + $( iframeWin ).on( 'load', resize ); + + MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver; if ( MutationObserver ) { observer = new MutationObserver( _.debounce( resize, 100 ) ); @@ -615,27 +622,13 @@ childList: true, subtree: true } ); - - $( node ).one( 'wp-mce-view-unbind', function() { - observer.disconnect(); - } ); } else { for ( i = 1; i < 6; i++ ) { setTimeout( resize, i * 700 ); } } - function classChange() { - iframeDoc.body.className = editor.getBody().className; - } - - editor.on( 'wp-body-class-change', classChange ); - - $( node ).one( 'wp-mce-view-unbind', function() { - editor.off( 'wp-body-class-change', classChange ); - } ); - - callback && callback.call( self, editor, node, contentNode ); + callback && callback.call( self, editor, node ); }, 50 ); }, rendered ); }, @@ -718,8 +711,7 @@ * @param {HTMLElement} node The view node to remove. */ remove: function( editor, node ) { - this.unbindNode.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); - $( node ).trigger( 'wp-mce-view-unbind' ); + this.unbindNode.call( this, editor, node ); editor.dom.remove( node ); editor.focus(); } @@ -732,7 +724,26 @@ * and a view for embeddable URLs. */ ( function( window, views, media, $ ) { - var base, gallery, av, embed; + var base, gallery, av, embed, + schema, parser, serializer; + + function verifyHTML( string ) { + var settings = {}; + + if ( ! window.tinymce ) { + return string.replace( /<[^>]+>/g, '' ); + } + + if ( ! string || ( string.indexOf( '<' ) === -1 && string.indexOf( '>' ) === -1 ) ) { + return string; + } + + schema = schema || new window.tinymce.html.Schema( settings ); + parser = parser || new window.tinymce.html.DomParser( settings, schema ); + serializer = serializer || new window.tinymce.html.Serializer( settings, schema ); + + return serializer.serialize( parser.parse( string, { forced_root_block: false } ) ); + } base = { state: [], @@ -783,6 +794,7 @@ } ); self.render( self.template( { + verifyHTML: verifyHTML, attachments: attachments, columns: attrs.columns ? parseInt( attrs.columns, 10 ) : media.galleryDefaults.columns } ) ); @@ -816,6 +828,7 @@ } ) .fail( function( response ) { if ( self.url ) { + self.ignore = true; self.removeMarkers(); } else { self.setError( response.message || response.statusText, 'admin-media' );