<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Backend\Block\Page $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<div id="preview" class="cms-revision-preview">
    <div class="toolbar">
        <?php if (!$block->isSingleStoreMode()):?>
            <div class="store-switcher">
                <?= $block->getChildHtml('store_switcher') ?>
            </div>
        <?php endif;?>
    </div>
    <iframe
        name="preview_iframe"
        id="preview_iframe"
        class="preview_iframe"
        frameborder="0"
        title="<?= $block->escapeHtmlAttr(__('Preview')) ?>"
        width="100%"
        sandbox="allow-forms allow-pointer-lock allow-same-origin"
    >

    </iframe>
    <?= $block->getChildHtml('preview_form') ?>
</div>

<?php $scriptString = <<<script
require(['jquery', 'loadingPopup', 'prototype'], function(jQuery){

//<![CDATA[
var previewForm = $('preview_form');
var previewIframe = $('preview_iframe');

function preview() {
    previewForm.writeAttribute('target', previewIframe.readAttribute('id'));
    blockPreview();
    previewForm.submit();
}

function blockPreview() {
    jQuery('body').loadingPopup({
        timeout: false
    });
}

function unBlockPreview() {
    jQuery('body').trigger('hideLoadingPopup');
}

jQuery(document).ready(preview);
jQuery(previewIframe).ready(unBlockPreview);

jQuery("#preview_iframe").load(function() {
    jQuery(this).height(jQuery(this).contents().find("html").height() );
});

//]]>

});
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
