<commit_before>/*
 * wysiwyg web editor
 *
 * suneditor.js
 * Copyright 2017 <NAME>.
 * MIT license.
 */
SUNEDITOR.plugin.image = {
    add: function (_this) {
        var context = _this.context;
        context.image = {
            _imageElement: null,
            _imageElement_w: 0,
            _imageElement_h: 0,
            _imageElement_l: 0,
            _imageElement_t: 0,
            _imageClientX: 0,
            _imageResize_parent_t: 0,
            _imageResize_parent_l: 0
        };

        /** image dialog */
        var image_dialog = eval(this.setDialog());
        context.image.modal = image_dialog;
        context.image.focusElement = image_dialog.getElementsByClassName('sun-editor-id-image-url')[0];
        context.image.imgInputFile = image_dialog.getElementsByClassName('sun-editor-id-image-file')[0];

        /** image resize controller, button */
        var resize_img_div = eval(this.setController_ImageResizeController());
        context.image.imageResizeDiv = resize_img_div;
        context.image.imageResizeDisplay = resize_img_div.getElementsByClassName('sun-editor-id-img-display')[0];

        var resize_img_button = eval(this.setController_ImageButton());
        context.image.imageResizeBtn = resize_img_button;

        /** add event listeners */
        context.image.imgInputFile.addEventListener('change', SUNEDITOR.plugin.image.onChange_imgInput.bind(_this));
        context.image.modal.getElementsByClassName("btn-primary")[0].addEventListener('click', SUNEDITOR.plugin.image.submit_dialog.bind(_this));
        resize_img_div.getElementsByClassName('sun-editor-img-controller')[0].addEventListener('mousedown', SUNEDITOR.plugin.image.onMouseDown_image_ctrl.bind(_this));
        context.image.imageResizeBtn.addEventListener('click', SUNEDITOR.plugin.image.onClick_imageResizeBtn.bind(_this));

        /** append html */
        context.dialog.modal.appendChild(image_dialog);
        context.element.relative.appendChild(resize_img_div);
        context.element.relative.appendChild(resize_img_button);
    },

    /** dialog */
    setDialog: function () {
        var lang = SUNEDITOR.lang;
        var dialog = document.createElement('DIV');
        dialog.className = 'modal-content sun-editor-id-dialog-image';
        dialog.style.display = 'none';
        dialog.innerHTML = '' +
            '<form class="editor_image" method="post" enctype="multipart/form-data">' +
            '   <div class="modal-header">' +
            '       <button type="button" data-command="close" class="close" aria-label="Close">' +
            '           <span aria-hidden="true" data-command="close">x</span>' +
            '       </button>' +
            '       <h5 class="modal-title">' + lang.dialogBox.imageBox.title + '</h5>' +
            '   </div>' +
            '   <div class="modal-body">' +
            '       <div class="form-group">' +
            '           <label>' + lang.dialogBox.imageBox.file + '</label>' +
            '               <input class="form-control sun-editor-id-image-file" type="file" accept="image/*" multiple="multiple" />' +
            '       </div>' +
            '       <div class="form-group">' +
            '           <label>' + lang.dialogBox.imageBox.url + '</label><input class="form-control sun-editor-id-image-url" type="text" />' +
            '       </div>' +
            '   </div>' +
            '   <div class="modal-footer">' +
            '       <button type="submit" class="btn btn-primary sun-editor-id-submit-image"><span>' + lang.dialogBox.submitButton + '</span></button>' +
            '   </div>' +
            '</form>';

        return dialog;
    },

    xmlHttp: null,

    onChange_imgInput: function (e) {
        e = e || window.event;

        function inputAction(files) {
            if (files) {
                this.showLoading();
                SUNEDITOR.plugin.dialog.closeDialog.call(this);

                var imageUploadUrl = this.context.user.imageUploadUrl;
                var filesLen = files.length;
                var xmlHttp = SUNEDITOR.plugin.image.xmlHttp;
                var i;

                if (imageUploadUrl !== null && imageUploadUrl.length > 0) {
                    var formData = new FormData();

                    for (i = 0; i < filesLen; i++) {
                        formData.append("file-" + i, files[i]);
                    }

                    xmlHttp = SUNEDITOR.func.getXMLHttpRequest();
                    xmlHttp.onreadystatechange = SUNEDITOR.plugin.image.callBack_imgUpload.bind(this);
                    xmlHttp.open("post", imageUploadUrl, true);
                    xmlHttp.send(formData);
                } else {
                    for (i = 0; i < filesLen; i++) {<commit_msg>fix: server image upload callBack<commit_after>/*
 * wysiwyg web editor
 *
 * suneditor.js
 * Copyright 2017 <NAME>.
 * MIT license.
 */
SUNEDITOR.plugin.image = {
    add: function (_this) {
        var context = _this.context;
        context.image = {
            _imageElement: null,
            _imageElement_w: 0,
            _imageElement_h: 0,
            _imageElement_l: 0,
            _imageElement_t: 0,
            _imageClientX: 0,
            _imageResize_parent_t: 0,
            _imageResize_parent_l: 0
        };

        /** image dialog */
        var image_dialog = eval(this.setDialog());
        context.image.modal = image_dialog;
        context.image.focusElement = image_dialog.getElementsByClassName('sun-editor-id-image-url')[0];
        context.image.imgInputFile = image_dialog.getElementsByClassName('sun-editor-id-image-file')[0];

        /** image resize controller, button */
        var resize_img_div = eval(this.setController_ImageResizeController());
        context.image.imageResizeDiv = resize_img_div;
        context.image.imageResizeDisplay = resize_img_div.getElementsByClassName('sun-editor-id-img-display')[0];

        var resize_img_button = eval(this.setController_ImageButton());
        context.image.imageResizeBtn = resize_img_button;

        /** add event listeners */
        context.image.imgInputFile.addEventListener('change', SUNEDITOR.plugin.image.onChange_imgInput.bind(_this));
        context.image.modal.getElementsByClassName("btn-primary")[0].addEventListener('click', SUNEDITOR.plugin.image.submit_dialog.bind(_this));
        resize_img_div.getElementsByClassName('sun-editor-img-controller')[0].addEventListener('mousedown', SUNEDITOR.plugin.image.onMouseDown_image_ctrl.bind(_this));
        context.image.imageResizeBtn.addEventListener('click', SUNEDITOR.plugin.image.onClick_imageResizeBtn.bind(_this));

        /** append html */
        context.dialog.modal.appendChild(image_dialog);
        context.element.relative.appendChild(resize_img_div);
        context.element.relative.appendChild(resize_img_button);
    },

    /** dialog */
    setDialog: function () {
        var lang = SUNEDITOR.lang;
        var dialog = document.createElement('DIV');
        dialog.className = 'modal-content sun-editor-id-dialog-image';
        dialog.style.display = 'none';
        dialog.innerHTML = '' +
            '<form class="editor_image" method="post" enctype="multipart/form-data">' +
            '   <div class="modal-header">' +
            '       <button type="button" data-command="close" class="close" aria-label="Close">' +
            '           <span aria-hidden="true" data-command="close">x</span>' +
            '       </button>' +
            '       <h5 class="modal-title">' + lang.dialogBox.imageBox.title + '</h5>' +
            '   </div>' +
            '   <div class="modal-body">' +
            '       <div class="form-group">' +
            '           <label>' + lang.dialogBox.imageBox.file + '</label>' +
            '               <input class="form-control sun-editor-id-image-file" type="file" accept="image/*" multiple="multiple" />' +
            '       </div>' +
            '       <div class="form-group">' +
            '           <label>' + lang.dialogBox.imageBox.url + '</label><input class="form-control sun-editor-id-image-url" type="text" />' +
            '       </div>' +
            '   </div>' +
            '   <div class="modal-footer">' +
            '       <button type="submit" class="btn btn-primary sun-editor-id-submit-image"><span>' + lang.dialogBox.submitButton + '</span></button>' +
            '   </div>' +
            '</form>';

        return dialog;
    },

    xmlHttp: null,

    onChange_imgInput: function (e) {
        e = e || window.event;

        function inputAction(files) {
            if (files) {
                this.showLoading();
                SUNEDITOR.plugin.dialog.closeDialog.call(this);

                var imageUploadUrl = this.context.user.imageUploadUrl;
                var filesLen = files.length;
                var i;

                if (imageUploadUrl !== null && imageUploadUrl.length > 0) {
                    var formData = new FormData();

                    for (i = 0; i < filesLen; i++) {
                        formData.append("file-" + i, files[i]);
                    }

                    SUNEDITOR.plugin.image.xmlHttp = SUNEDITOR.func.getXMLHttpRequest();
                    SUNEDITOR.plugin.image.xmlHttp.onreadystatechange = SUNEDITOR.plugin.image.callBack_imgUpload.bind(this);
                    SUNEDITOR.plugin.image.xmlHttp.open("post", imageUploadUrl, true);
                    SUNEDITOR.plugin.image.xmlHttp.send(formData);
                } else {
                    for (i = 0; i < filesLen; i++) {
{'fraction_non_alphanumeric': 0.1379670214986433, 'fraction_numerical': 0.004383218534752661, 'mean_word_length': 2.0754172015404366, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '3852299', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2679, 'n_words': 415}