<?php $content = $this->getContent() ?>
<?php $helper = $this->helper('MGS\Fbuilder\Helper\Generate') ?>

<textarea name="text_content" title="" data-ui-id="form-element-content" id="table_form_content" class="textarea required-entry" rows="20" cols="15" style="" aria-hidden="true"><?php echo $content ?></textarea>

<?php if ($helper->getStoreConfig('cms/wysiwyg/editor')=='Magento_Tinymce3/tinymce3Adapter'): ?>
    <script type="text/javascript">
    //<![CDATA[
        openEditorPopup = function(url, name, specs, parent) {
            if ((typeof popups == "undefined") || popups[name] == undefined || popups[name].closed) {
                if (typeof popups == "undefined") {
                    popups = new Array();
                }
                var opener = (parent != undefined ? parent : window);
                popups[name] = opener.open(url, name, specs);
            } else {
                popups[name].focus();
            }
            return popups[name];
        }

        closeEditorPopup = function(name) {
            if ((typeof popups != "undefined") && popups[name] != undefined && !popups[name].closed) {
                popups[name].close();
            }
        }
    //]]>
    </script>

    <script type="text/javascript">
        window.tinyMCE_GZ = window.tinyMCE_GZ || {};
        window.tinyMCE_GZ.loaded = true;
        require([
            "jquery",
            "mage/translate",
            "mage/adminhtml/events",
            "mage/adminhtml/wysiwyg/tiny_mce/setup",
            "mage/adminhtml/wysiwyg/widget"
        ], function(jQuery){
                var wysiwygtable_form_content = new wysiwygSetup(
                "table_form_content", {
                    "enabled":true,
                    "hidden":false,
                    "use_container":false,
                    "add_variables":false,
                    "add_widgets":true,
                    "no_display":false,
                    "encode_directives":true,
                    "baseStaticUrl":"<?php echo str_replace('https:', '', str_replace('http:', '', $this->getStaticUrl())) ?>",
                    "baseStaticDefaultUrl":"<?php echo str_replace('https:', '', str_replace('http:', '', $this->getStaticUrl())) ?>",
                    "directives_url":"<?php echo str_replace('https:', '', str_replace('http:', '', $this->getUrl('fbuilder/wysiwyg/directive'))) ?>",
                    "popup_css":"",
                    "content_css":"",
                    "width":"100%",
                    "height":"500px",
                    "directives_url_quoted":"<?php echo str_replace('https:', '', str_replace('http:', '', $this->getUrl('fbuilder/wysiwyg/directive'))) ?>",
                    "add_images":true,
                    "files_browser_window_width":"1000",
                    "files_browser_window_height":"600",
                    "widget_plugin_src":"",
                    "widget_placeholders": <?php echo json_encode($this->getWidgetPlaceHolder()) ?>,
                    "widget_window_url":""
                });


                wysiwygtable_form_content.setup("exact");
                editorFormValidationHandler = wysiwygtable_form_content.onFormValidation.bind(wysiwygtable_form_content);
                Event.observe("toggletable_form_content", "click", wysiwygtable_form_content.toggle.bind(wysiwygtable_form_content));
                varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler);
                varienGlobalEvents.clearEventHandlers("open_browser_callback");
                varienGlobalEvents.attachEventHandler("open_browser_callback", wysiwygtable_form_content.openFileBrowser);
        });
    </script>
<?php endif ?>

<?php if ($helper->getStoreConfig('cms/wysiwyg/editor')=='mage/adminhtml/wysiwyg/tiny_mce/tinymce5Adapter'): ?>
    <script type="text/javascript">
        require([
        "jquery",
        "mage/translate",
        "mage/adminhtml/events",
        "mage/adminhtml/wysiwyg/tiny_mce/setup"
        ], function(jQuery){
            wysiwygcms_block_form_content = new wysiwygSetup("table_form_content", {
                "width":"100%",  // defined width of editor
                "height":"500px", // height of editor
                //"plugins":[{"name":"image"}], // for image
                "tinymce":{"toolbar":"table","plugins":"table",
                }
            });
            wysiwygcms_block_form_content.setup("exact");
            editorFormValidationHandler = wysiwygcms_block_form_content.onFormValidation.bind(wysiwygcms_block_form_content);
            Event.observe("togglecms_block_form_content", "click", wysiwygcms_block_form_content.toggle.bind(wysiwygcms_block_form_content));
            varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler);
            varienGlobalEvents.clearEventHandlers("open_browser_callback");
            varienGlobalEvents.attachEventHandler("open_browser_callback", wysiwygcms_block_form_content.openFileBrowser);
        });
    </script>
<?php endif ?>
