<commit_before>/**
 * @author <NAME> from Ubrainians for imCode
 * 15.08.18
 */
Imcms.define(
    'imcms-tinymce-text-editor',
    [
        'tinyMCE', 'imcms-uuid-generator', 'jquery', 'imcms', 'imcms-text-editor-utils', 'imcms-text-history-plugin',
        'imcms-text-validation-plugin', 'imcms-image-in-text-plugin', 'imcms-text-discard-changes-plugin',
        'imcms-text-full-screen-plugin'
    ],
    function (
        tinyMCE, uuidGenerator, $, imcms, textEditorUtils, textHistory, textValidation, imageInText,
        discardChangesPlugin, fullScreenPlugin
    ) {
        var commonConfig = {
            skin_url: imcms.contextPath + '/js/libs/tinymce/skins/white',
            convert_urls: false,
            cache_suffix: '?v=0.0.1',
            branding: false,
            skin: 'white',
            inline: true,
            inline_boundaries: false,
            toolbar_items_size: 'small',
            content_css: imcms.contextPath + '/css/imcms-text_editor.css',
            menubar: false,
            statusbar: false,
            forced_root_block: false,
            init_instance_callback: prepareEditor,
            save_onsavecallback: textEditorUtils.saveContent,
            setup: function (editor) {
                textHistory.initTextHistory(editor);
                textValidation.initTextValidation(editor);
                imageInText.initImageInText(editor);
                discardChangesPlugin.initDiscardChanges(editor);
            }
        };

        var inlineEditorConfig = $.extend({
            valid_elements: '*[*]',
            plugins: ['autolink link lists hr code ' + fullScreenPlugin.pluginName + ' save'],
            toolbar: 'code | bold italic underline | bullist numlist | hr |'
                + ' alignleft aligncenter alignright alignjustify | link ' + imageInText.pluginName + ' | '
                + textHistory.pluginName + ' ' + textValidation.pluginName + ' |' + ' ' + fullScreenPlugin.pluginName
                + ' | save ' + discardChangesPlugin.pluginName
        }, commonConfig);

        fullScreenPlugin.initFullScreen();

        function clearSaveBtnText(editor) {
            delete editor.buttons.save.text;
        }

        function setEditorFocusOnEditControlClick(editor) {
            editor.$().parents('.imcms-editor-area--text')
                .find('.imcms-control--text')
                .on('click', function () {
                    editor.focus();
                });
        }

        function initSaveContentConfirmation(editor) {
            editor.on('blur', function (e) {
                textEditorUtils.onEditorBlur(e.target)
            });
        }

        function prepareEditor(editor) {
            clearSaveBtnText(editor);
            textEditorUtils.setEditorFocus(editor);
            setEditorFocusOnEditControlClick(editor);
            textEditorUtils.showEditButton($(editor.$()));
            initSaveContentConfirmation(editor);
        }

        return {
            init: function ($textEditor) {
                var config = inlineEditorConfig;
                var toolbarId = uuidGenerator.generateUUID();
                var textAreaId = uuidGenerator.generateUUID();

                $textEditor.attr('id', textAreaId)
                    .closest('.imcms-editor-area--text')
                    .find('.imcms-editor-area__text-toolbar')
                    .attr('id', toolbarId);

                var editorConfig = $.extend({
                    selector: '#' + textAreaId,
                    fixed_toolbar_container: '#' + toolbarId
                }, config);

                // 4.5.7 the last version compatible with IE 10
                if (imcms.browserInfo.isIE10) {
                    tinyMCE.baseURL = 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.5.7';
                    tinyMCE.suffix = '.min';
                }

                tinyMCE.init(editorConfig);
            }
        };
    }
);<commit_msg>IMCMS-341 - Text editor changes: - Text editor refactoring.<commit_after>/**
 * @author <NAME> from Ubrainians for imCode
 * 15.08.18
 */
Imcms.define(
    'imcms-tinymce-text-editor',
    [
        'tinyMCE', 'imcms-uuid-generator', 'jquery', 'imcms', 'imcms-text-editor-utils', 'imcms-text-history-plugin',
        'imcms-text-validation-plugin', 'imcms-image-in-text-plugin', 'imcms-text-discard-changes-plugin',
        'imcms-text-full-screen-plugin'
    ],
    function (
        tinyMCE, uuidGenerator, $, imcms, textEditorUtils, textHistory, textValidation, imageInText,
        discardChangesPlugin, fullScreenPlugin
    ) {
        var sourceCodePlugin = 'code';
        var fontPlugins = ['bold', 'italic', 'underline'].join(' ');
        var listsPlugins = ['bullist', 'numlist'].join(' ');
        var horizontalLinePlugin = 'hr';
        var textAlignPlugins = ['alignleft', 'aligncenter', 'alignright', 'alignjustify'].join(' ');
        var specialInsertsPlugins = ['link', imageInText.pluginName].join(' ');
        var customImcmsTextPlugins = [textHistory.pluginName, textValidation.pluginName].join(' ');
        var fullscreenPlugin = fullScreenPlugin.pluginName;
        var saveAndDiscardPlugins = ['save', discardChangesPlugin.pluginName].join(' ');

        var toolbar = [
            sourceCodePlugin,
            fontPlugins,
            listsPlugins,
            horizontalLinePlugin,
            textAlignPlugins,
            specialInsertsPlugins,
            customImcmsTextPlugins,
            fullscreenPlugin,
            saveAndDiscardPlugins
        ].join(' | ');

        var inlineEditorConfig = {
            skin_url: imcms.contextPath + '/js/libs/tinymce/skins/white',
            convert_urls: false,
            cache_suffix: '?v=0.0.1',
            branding: false,
            skin: 'white',
            inline: true,
            inline_boundaries: false,
            toolbar_items_size: 'small',
            content_css: imcms.contextPath + '/css/imcms-text_editor.css',
            menubar: false,
            statusbar: false,
            forced_root_block: false,
            init_instance_callback: prepareEditor,
            save_onsavecallback: textEditorUtils.saveContent,
            setup: function (editor) {
                textHistory.initTextHistory(editor);
                textValidation.initTextValidation(editor);
                imageInText.initImageInText(editor);
                discardChangesPlugin.initDiscardChanges(editor);
            },
            valid_elements: '*[*]',
            plugins: ['autolink link lists hr code ' + fullScreenPlugin.pluginName + ' save'],
            toolbar: toolbar
        };

        fullScreenPlugin.initFullScreen();

        function clearSaveBtnText(editor) {
            delete editor.buttons.save.text;
        }

        function setEditorFocusOnEditControlClick(editor) {
            editor.$().parents('.imcms-editor-area--text')
                .find('.imcms-control--text')
                .on('click', function () {
                    editor.focus();
                });
        }

        function initSaveContentConfirmation(editor) {
            editor.on('blur', function (e) {
                textEditorUtils.onEditorBlur(e.target)
            });
        }

        function prepareEditor(editor) {
            clearSaveBtnText(editor);
            textEditorUtils.setEditorFocus(editor);
            setEditorFocusOnEditControlClick(editor);
            textEditorUtils.showEditButton($(editor.$()));
            initSaveContentConfirmation(editor);
        }

        return {
            init: function ($textEditor) {
                var toolbarId = uuidGenerator.generateUUID();
                var textAreaId = uuidGenerator.generateUUID();

                $textEditor.attr('id', textAreaId)
                    .closest('.imcms-editor-area--text')
                    .find('.imcms-editor-area__text-toolbar')
                    .attr('id', toolbarId);

                var editorConfig = $.extend({
                    selector: '#' + textAreaId,
                    fixed_toolbar_container: '#' + toolbarId
                }, inlineEditorConfig);

                // 4.5.7 the last version compatible with IE 10
                if (imcms.browserInfo.isIE10) {
                    tinyMCE.baseURL = 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.5.7';
                    tinyMCE.suffix = '.min';
                }

                tinyMCE.init(editorConfig);
            }
        };
    }
);
{'fraction_non_alphanumeric': 0.1155613146424785, 'fraction_numerical': 0.004829779714925197, 'mean_word_length': 1.8375668449197862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2373154', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2227, 'n_words': 366}