<textarea name="<?php echo $name ?>" id="<?php echo $this->getId('textarea') ?>"><?= e($value) ?></textarea>
<script>
    function froalaInit() {
        $("#<?php echo $this->getId('textarea') ?>").froalaEditor({
            theme:     'october',
            language:  '<?php echo $lang; ?>',
            width:     '<?php echo $width; ?>',
            height:    '<?php echo $height; ?>',
            toolbarButtons:    [<?php echo $toolbar_froala_lg; ?>],
            toolbarButtonsMD:  [<?php echo $toolbar_froala_md; ?>],
            toolbarButtonsSM:  [<?php echo $toolbar_froala_sm; ?>],
            toolbarButtonsXS:  [<?php echo $toolbar_froala_xs; ?>],
            imageUploadURL:    '<?php echo URL::to('image_upload'); ?>',
            imageUploadParams: {id: "my_editor"},
            imageDeleteURL:    '<?php echo URL::to('delete_image'); ?>',
            linkList: [
                {
                    text: 'Google',
                    href: 'https://google.com',
                    target: '_blank'
                },
                {
                    text: 'Facebook',
                    href: 'https://facebook.com',
                    target: '_blank'
                }
            ]
        })
        // Catch image removal from the editor.
        .on('editable.afterRemoveImage', function(e, editor, $img) {
            // Set the image source to the image delete params.
            editor.options.imageDeleteParams = {src: $img.attr('src')};

            // Make the delete request.
            editor.deleteImage($img);
        });
    }
    
    $(function() {
        if (typeof $("#<?php echo $this->getId('textarea') ?>").froalaEditor === 'undefined') {
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/font-awesome.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/froala_editor.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/froala_style.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/themes/october.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/char_counter.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/code_view.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/colors.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/draggable.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/emoticons.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/file.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/fullscreen.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/image.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/image_manager.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/line_breaker.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/quick_insert.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/table.min.css'); ?>" type="text/css">');
            $('head').append('<link rel="stylesheet" href="<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/css/plugins/video.min.css'); ?>" type="text/css">');
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/froala_editor.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/align.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/char_counter.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/code_beautifier.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/code_view.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/colors.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/draggable.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/emoticons.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/entities.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/file.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/font_family.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/font_size.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/fullscreen.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/image.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/image_manager.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/inline_style.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/line_breaker.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/link.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/lists.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/paragraph_format.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/paragraph_style.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/quick_insert.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/quote.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/save.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/table.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/url.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/plugins/video.min.js'); ?>', function() {
            $.getScript('<?php echo url('/plugins/anandpatel/wysiwygeditors/formwidgets/editor/assets/froala/js/languages/'.$lang.'.js'); ?>', function() {
            froalaInit();
            }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); }); });
        }
        else {
            froalaInit();
        }
    });
</script>
