]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mce-view.js
WordPress 4.7-scripts
[autoinstalls/wordpress.git] / wp-includes / js / mce-view.js
index 3d2616d7852eb1b9c4661e0a2fb11d4b222f2ae9..8c8de56a0ef98ff306f27392bbfc965b298b7215 100644 (file)
 
                        text = tinymce.DOM.decode( text );
 
+                       if ( text.indexOf( '[' ) !== -1 && text.indexOf( ']' ) !== -1 ) {
+                               // Looks like a shortcode? Remove any line breaks from inside of shortcodes
+                               // or autop will replace them with <p> and <br> later and the string won't match.
+                               text = text.replace( /\[[^\]]+\]/g, function( match ) {
+                                       return match.replace( /[\r\n]/g, '' );
+                               });
+                       }
+
                        if ( ! force ) {
                                instance = this.getInstance( text );
 
                 */
                render: function( force ) {
                        _.each( instances, function( instance ) {
-                               instance.render( force );
+                               instance.render( null, force );
                        } );
                },
 
                initialize: function() {},
 
                /**
-                * Retuns the content to render in the view node.
+                * Returns the content to render in the view node.
                 *
                 * @return {*}
                 */
                                var dom = editor.dom,
                                        styles = '',
                                        bodyClasses = editor.getBody().className || '',
-                                       editorHead = editor.getDoc().getElementsByTagName( 'head' )[0];
+                                       editorHead = editor.getDoc().getElementsByTagName( 'head' )[0],
+                                       iframe, iframeWin, iframeDoc, MutationObserver, observer, i, block;
 
                                tinymce.each( dom.$( 'link[rel="stylesheet"]', editorHead ), function( link ) {
                                        if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
                                        }, '\u200B' );
                                }
 
-                               // Seems the browsers need a bit of time to insert/set the view nodes,
-                               // or the iframe will fail especially when switching Text => Visual.
-                               setTimeout( function() {
-                                       var iframe, iframeWin, iframeDoc, MutationObserver, observer, i, block;
+                               editor.undoManager.transact( function() {
+                                       node.innerHTML = '';
 
-                                       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( 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
-                                               } );
+                                       dom.add( node, 'span', { 'class': 'mce-shim' } );
+                                       dom.add( node, 'span', { 'class': 'wpview-end' } );
+                               } );
 
-                                               dom.add( node, 'span', { 'class': 'mce-shim' } );
-                                               dom.add( node, 'span', { 'class': 'wpview-end' } );
-                                       } );
+                               // 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(
+                                       '<!DOCTYPE html>' +
+                                       '<html>' +
+                                               '<head>' +
+                                                       '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
+                                                       head +
+                                                       styles +
+                                                       '<style>' +
+                                                               'html {' +
+                                                                       'background: transparent;' +
+                                                                       'padding: 0;' +
+                                                                       'margin: 0;' +
+                                                               '}' +
+                                                               'body#wpview-iframe-sandbox {' +
+                                                                       'background: transparent;' +
+                                                                       'padding: 1px 0 !important;' +
+                                                                       'margin: -1px 0 0 !important;' +
+                                                               '}' +
+                                                               'body#wpview-iframe-sandbox:before,' +
+                                                               'body#wpview-iframe-sandbox:after {' +
+                                                                       'display: none;' +
+                                                                       'content: "";' +
+                                                               '}' +
+                                                       '</style>' +
+                                               '</head>' +
+                                               '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
+                                                       body +
+                                               '</body>' +
+                                       '</html>'
+                               );
+
+                               iframeDoc.close();
 
-                                       // 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 ) {
+                               function resize() {
+                                       var $iframe;
+
+                                       if ( block ) {
                                                return;
                                        }
 
-                                       iframeWin = iframe.contentWindow;
-                                       iframeDoc = iframeWin.document;
-                                       iframeDoc.open();
-
-                                       iframeDoc.write(
-                                               '<!DOCTYPE html>' +
-                                               '<html>' +
-                                                       '<head>' +
-                                                               '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
-                                                               head +
-                                                               styles +
-                                                               '<style>' +
-                                                                       'html {' +
-                                                                               'background: transparent;' +
-                                                                               'padding: 0;' +
-                                                                               'margin: 0;' +
-                                                                       '}' +
-                                                                       'body#wpview-iframe-sandbox {' +
-                                                                               'background: transparent;' +
-                                                                               'padding: 1px 0 !important;' +
-                                                                               'margin: -1px 0 0 !important;' +
-                                                                       '}' +
-                                                                       'body#wpview-iframe-sandbox:before,' +
-                                                                       'body#wpview-iframe-sandbox:after {' +
-                                                                               'display: none;' +
-                                                                               'content: "";' +
-                                                                       '}' +
-                                                               '</style>' +
-                                                       '</head>' +
-                                                       '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
-                                                               body +
-                                                       '</body>' +
-                                               '</html>'
-                                       );
-
-                                       iframeDoc.close();
-
-                                       function resize() {
-                                               var $iframe;
-
-                                               if ( block ) {
-                                                       return;
-                                               }
-
-                                               // Make sure the iframe still exists.
-                                               if ( iframe.contentWindow ) {
-                                                       $iframe = $( iframe );
-                                                       self.iframeHeight = $( iframeDoc.body ).height();
+                                       // Make sure the iframe still exists.
+                                       if ( iframe.contentWindow ) {
+                                               $iframe = $( iframe );
+                                               self.iframeHeight = $( iframeDoc.body ).height();
 
-                                                       if ( $iframe.height() !== self.iframeHeight ) {
-                                                               $iframe.height( self.iframeHeight );
-                                                               editor.nodeChanged();
-                                                       }
+                                               if ( $iframe.height() !== self.iframeHeight ) {
+                                                       $iframe.height( self.iframeHeight );
+                                                       editor.nodeChanged();
                                                }
                                        }
+                               }
 
-                                       if ( self.iframeHeight ) {
-                                               block = true;
+                               if ( self.iframeHeight ) {
+                                       block = true;
 
-                                               setTimeout( function() {
-                                                       block = false;
-                                                       resize();
-                                               }, 3000 );
-                                       }
+                                       setTimeout( function() {
+                                               block = false;
+                                               resize();
+                                       }, 3000 );
+                               }
+
+                               function reload() {
+                                       $( node ).data( 'rendered', null );
 
-                                       $( iframeWin ).on( 'load', resize );
+                                       setTimeout( function() {
+                                               wp.mce.views.render();
+                                       } );
+                               }
 
-                                       MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver;
+                               $( iframeWin ).on( 'load', resize ).on( 'unload', reload );
 
-                                       if ( MutationObserver ) {
-                                               observer = new MutationObserver( _.debounce( resize, 100 ) );
+                               MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver;
 
-                                               observer.observe( iframeDoc.body, {
-                                                       attributes: true,
-                                                       childList: true,
-                                                       subtree: true
-                                               } );
-                                       } else {
-                                               for ( i = 1; i < 6; i++ ) {
-                                                       setTimeout( resize, i * 700 );
-                                               }
+                               if ( MutationObserver ) {
+                                       observer = new MutationObserver( _.debounce( resize, 100 ) );
+
+                                       observer.observe( iframeDoc.body, {
+                                               attributes: true,
+                                               childList: true,
+                                               subtree: true
+                                       } );
+                               } else {
+                                       for ( i = 1; i < 6; i++ ) {
+                                               setTimeout( resize, i * 700 );
                                        }
+                               }
 
-                                       callback && callback.call( self, editor, node );
-                               }, 50 );
+                               callback && callback.call( self, editor, node );
                        }, rendered );
                },
 
                /**
                 * Sets a loader for all view nodes tied to this view instance.
                 */
-               setLoader: function() {
+               setLoader: function( dashicon ) {
                        this.setContent(
                                '<div class="loading-placeholder">' +
-                                       '<div class="dashicons dashicons-admin-media"></div>' +
+                                       '<div class="dashicons dashicons-' + ( dashicon || 'admin-media' ) + '"></div>' +
                                        '<div class="wpview-loading"><ins></ins></div>' +
                                '</div>'
                        );