514 | | // Seems the browsers need a bit of time to insert/set the view nodes, |
515 | | // or the iframe will fail especially when switching Text => Visual. |
516 | | setTimeout( function() { |
517 | | var iframe, iframeWin, iframeDoc, MutationObserver, observer, i, block; |
518 | | |
519 | | editor.undoManager.transact( function() { |
520 | | node.innerHTML = ''; |
521 | | |
522 | | iframe = dom.add( node, 'iframe', { |
523 | | /* jshint scripturl: true */ |
524 | | src: tinymce.Env.ie ? 'javascript:""' : '', |
525 | | frameBorder: '0', |
526 | | allowTransparency: 'true', |
527 | | scrolling: 'no', |
528 | | 'class': 'wpview-sandbox', |
529 | | style: { |
530 | | width: '100%', |
531 | | display: 'block' |
532 | | }, |
533 | | height: self.iframeHeight |
534 | | } ); |
| 515 | editor.undoManager.transact( function() { |
| 516 | node.innerHTML = ''; |
536 | | dom.add( node, 'span', { 'class': 'mce-shim' } ); |
537 | | dom.add( node, 'span', { 'class': 'wpview-end' } ); |
| 518 | iframe = dom.add( node, 'iframe', { |
| 519 | /* jshint scripturl: true */ |
| 520 | src: tinymce.Env.ie ? 'javascript:""' : '', |
| 521 | frameBorder: '0', |
| 522 | allowTransparency: 'true', |
| 523 | scrolling: 'no', |
| 524 | 'class': 'wpview-sandbox', |
| 525 | style: { |
| 526 | width: '100%', |
| 527 | display: 'block' |
| 528 | }, |
| 529 | height: self.iframeHeight |
540 | | // Bail if the iframe node is not attached to the DOM. |
541 | | // Happens when the view is dragged in the editor. |
542 | | // There is a browser restriction when iframes are moved in the DOM. They get emptied. |
543 | | // The iframe will be rerendered after dropping the view node at the new location. |
544 | | if ( ! iframe.contentWindow ) { |
545 | | return; |
546 | | } |
| 532 | dom.add( node, 'span', { 'class': 'mce-shim' } ); |
| 533 | dom.add( node, 'span', { 'class': 'wpview-end' } ); |
| 534 | } ); |
548 | | iframeWin = iframe.contentWindow; |
549 | | iframeDoc = iframeWin.document; |
550 | | iframeDoc.open(); |
551 | | |
552 | | iframeDoc.write( |
553 | | '<!DOCTYPE html>' + |
554 | | '<html>' + |
555 | | '<head>' + |
556 | | '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' + |
557 | | head + |
558 | | styles + |
559 | | '<style>' + |
560 | | 'html {' + |
561 | | 'background: transparent;' + |
562 | | 'padding: 0;' + |
563 | | 'margin: 0;' + |
564 | | '}' + |
565 | | 'body#wpview-iframe-sandbox {' + |
566 | | 'background: transparent;' + |
567 | | 'padding: 1px 0 !important;' + |
568 | | 'margin: -1px 0 0 !important;' + |
569 | | '}' + |
570 | | 'body#wpview-iframe-sandbox:before,' + |
571 | | 'body#wpview-iframe-sandbox:after {' + |
572 | | 'display: none;' + |
573 | | 'content: "";' + |
574 | | '}' + |
575 | | '</style>' + |
576 | | '</head>' + |
577 | | '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' + |
578 | | body + |
579 | | '</body>' + |
580 | | '</html>' |
581 | | ); |
| 536 | // Bail if the iframe node is not attached to the DOM. |
| 537 | // Happens when the view is dragged in the editor. |
| 538 | // There is a browser restriction when iframes are moved in the DOM. They get emptied. |
| 539 | // The iframe will be rerendered after dropping the view node at the new location. |
| 540 | if ( ! iframe.contentWindow ) { |
| 541 | return; |
| 542 | } |
583 | | iframeDoc.close(); |
| 544 | iframeWin = iframe.contentWindow; |
| 545 | iframeDoc = iframeWin.document; |
| 546 | iframeDoc.open(); |
| 547 | |
| 548 | iframeDoc.write( |
| 549 | '<!DOCTYPE html>' + |
| 550 | '<html>' + |
| 551 | '<head>' + |
| 552 | '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' + |
| 553 | head + |
| 554 | styles + |
| 555 | '<style>' + |
| 556 | 'html {' + |
| 557 | 'background: transparent;' + |
| 558 | 'padding: 0;' + |
| 559 | 'margin: 0;' + |
| 560 | '}' + |
| 561 | 'body#wpview-iframe-sandbox {' + |
| 562 | 'background: transparent;' + |
| 563 | 'padding: 1px 0 !important;' + |
| 564 | 'margin: -1px 0 0 !important;' + |
| 565 | '}' + |
| 566 | 'body#wpview-iframe-sandbox:before,' + |
| 567 | 'body#wpview-iframe-sandbox:after {' + |
| 568 | 'display: none;' + |
| 569 | 'content: "";' + |
| 570 | '}' + |
| 571 | '</style>' + |
| 572 | '</head>' + |
| 573 | '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' + |
| 574 | body + |
| 575 | '</body>' + |
| 576 | '</html>' |
| 577 | ); |
592 | | // Make sure the iframe still exists. |
593 | | if ( iframe.contentWindow ) { |
594 | | $iframe = $( iframe ); |
595 | | self.iframeHeight = $( iframeDoc.body ).height(); |
596 | | |
597 | | if ( $iframe.height() !== self.iframeHeight ) { |
598 | | $iframe.height( self.iframeHeight ); |
599 | | editor.nodeChanged(); |
600 | | } |
| 584 | if ( block ) { |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | // Make sure the iframe still exists. |
| 589 | if ( iframe.contentWindow ) { |
| 590 | $iframe = $( iframe ); |
| 591 | self.iframeHeight = $( iframeDoc.body ).height(); |
| 592 | |
| 593 | if ( $iframe.height() !== self.iframeHeight ) { |
| 594 | $iframe.height( self.iframeHeight ); |
| 595 | editor.nodeChanged(); |