<commit_before>/**
 * Created by Shadowgun on 13.02.2015.
 */
/**
 Text Editor
 */
Imcms.Text = {};

Imcms.Text.API = function () {

};
Imcms.Text.API.prototype = {
    get: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text"),
            type: "GET",
            data: request,
            success: callback
        })
    },
    update: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text"),
            type: "POST",
            data: request,
            success: callback
        })
    },
    validate: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text.validate"),
            type: "POST",
            data: request,
            success: callback
        })
    }
};

Imcms.Text.Editor = function () {
    this.init();
};

Imcms.Text.Editor.prototype = {
    _api: new Imcms.Text.API(),
    _textFrame: {},
    init: function () {
        this._textFrame = new Imcms.FrameBuilder().title("Text Editor");

        CKEDITOR.on('instanceCreated', this._onCreated.bind(this));
        CKEDITOR.on("confirmChangesEvent", this._onConfirm.bind(this));
        CKEDITOR.on("validateText", this._onValidateText.bind(this));
        CKEDITOR.on("getTextHistory", this._onGetTextHistory.bind(this));

        $("[contenteditable='true']").each(this.addEditor.bind(this));
    },
    addEditor: function (position, element) {
        element = $(element);
        CKEDITOR.inline(element[0]);
        element.parents("a").attr("onclick", "return false;");

        $("<div>").insertAfter(element)
            .append(element)
            .css({overflow: "hidden"});

        var loopTitle = "";
        if (element.data("loopentryref")) {
            loopTitle = (element.data("loopentryref")).split("_");
            loopTitle = "L" + loopTitle[0] + "-E" + loopTitle[1] + "-T";
        }

        var title = loopTitle + element.data("no") + " | " + element.data("label"),
            currentFrame = this._textFrame
                .click(function (e) {
                    currentFrame.hide();
                    element.focus();
                    element.trigger(e);
                    element.blur(function () {
                        currentFrame.show();
                    });
                })
                .build()
                .attr("title", title.replace(/<(?:.|\n)*?>/gim, ''))
                .insertBefore(element);

        if (element.data("showlabel")) {
            $("<div>").addClass("text-editor-label")
                .html(element.data("label"))
                .insertBefore(element);
        }
    },
    _onConfirm: function (event) {
        var editor = event.editor,
            data = $(editor.element.$).data(),
            isHtmlContent = (data.contenttype === "html"),
            callFunc = (isHtmlContent) ? "html" : "text",
            content = $(editor.element.$)[callFunc]();

        // save only when content is changed or mode is switched
        if ((data.content !== content) || CKEDITOR.switchFormat) {
            data.content = content;
            if (!data.meta) {
                data.meta = Imcms.document.meta;<commit_msg>IMCMS-179 - Image in texteditor: - Replaced context menu item with new custom item in case of internal images.<commit_after>/**
 * Created by Shadowgun on 13.02.2015.
 */
/**
 Text Editor
 */
Imcms.Text = {};

Imcms.Text.API = function () {

};
Imcms.Text.API.prototype = {
    get: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text"),
            type: "GET",
            data: request,
            success: callback
        })
    },
    update: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text"),
            type: "POST",
            data: request,
            success: callback
        })
    },
    validate: function (request, callback) {
        $.ajax({
            url: Imcms.Linker.get("text.validate"),
            type: "POST",
            data: request,
            success: callback
        })
    }
};

Imcms.Text.Editor = function () {
    this.init();
};

Imcms.Text.Editor.prototype = {
    _api: new Imcms.Text.API(),
    _textFrame: {},
    init: function () {
        this._textFrame = new Imcms.FrameBuilder().title("Text Editor");

        CKEDITOR.on('instanceReady', this._onInstanceReady.bind(this));
        CKEDITOR.on('instanceCreated', this._onCreated.bind(this));
        CKEDITOR.on("confirmChangesEvent", this._onConfirm.bind(this));
        CKEDITOR.on("validateText", this._onValidateText.bind(this));
        CKEDITOR.on("getTextHistory", this._onGetTextHistory.bind(this));

        $("[contenteditable='true']").each(this.addEditor.bind(this));
    },
    addEditor: function (position, element) {
        element = $(element);
        CKEDITOR.inline(element[0]);
        element.parents("a").attr("onclick", "return false;");

        $("<div>").insertAfter(element)
            .append(element)
            .css({overflow: "hidden"});

        var loopTitle = "";
        if (element.data("loopentryref")) {
            loopTitle = (element.data("loopentryref")).split("_");
            loopTitle = "L" + loopTitle[0] + "-E" + loopTitle[1] + "-T";
        }

        var title = loopTitle + element.data("no") + " | " + element.data("label"),
            currentFrame = this._textFrame
                .click(function (e) {
                    currentFrame.hide();
                    element.focus();
                    element.trigger(e);
                    element.blur(function () {
                        currentFrame.show();
                    });
                })
                .build()
                .attr("title", title.replace(/<(?:.|\n)*?>/gim, ''))
                .insertBefore(element);

        if (element.data("showlabel")) {
            $("<div>").addClass("text-editor-label")
                .html(element.data("label"))
                .insertBefore(element);
        }
    },
    _onInstanceReady: function (event) {
        var editor = event.editor;

        editor.addCommand('editInternalImageCmd', {
            exec: function (editor) {
                // execution here
            }
        });
        var editInternalImageCmd = {
            label: editor.lang.image.menu,
            command: 'editInternalImageCmd',
            group: 'image'
        };
        editor.contextMenu.addListener(function (element, selection) {
            if (element.hasClass("internalImageInTextEditor")) {
                // skipping CKEditor's "image" context menu item that is items[3]
                editor.contextMenu.items = editor.contextMenu.items.slice(0,3);
                return {
                    editInternalImageCmd: CKEDITOR.TRISTATE_OFF
                };
            }
        });
        editor.addMenuItems({
            editInternalImageCmd: {
                label: 'Edit Image',
                command: 'editInternalImageCmd',
                group: 'image',
                order: 2
            }
        });
    },
    _onConfirm: function (event) {
        var editor = event.editor,
            data = $(editor.element.$).data(),
            isHtmlContent = (data.contenttype === "html"),
            callFunc = (isHtmlContent) ? "html" : "text",
            content = $(editor.element.$)[callFunc]();

        // save only when content is changed or mode is switched
        if ((data.content !== content) || CKEDITOR.switchFormat) {
            data.content = content;
            if (!data.meta) {
                data.meta = Imcms.document.meta;
{'fraction_non_alphanumeric': 0.15273586143550716, 'fraction_numerical': 0.0038052748983073087, 'mean_word_length': 1.7456772334293948, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '238608', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2065, 'n_words': 387}