<commit_before>/**
 * @description
 * 简单上传:点击按钮,直接选择文件上传
 * @author Jinqn
 * @date 2014-03-31
 */
UE.plugin.register('simpleupload', function (){
    var me = this,
        uploadInput;

    function initUploadBtn(){
        var container = me.container,
            wrapper = document.createElement('form'),
            form = document.createElement('form'),
            input = uploadInput = document.createElement('input'),
            iframe = document.createElement('iframe'),
            iframeId = 'edui_iframe_' + (+new Date()).toString(36),
            imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));

        input.type = 'file';
        input.accept = 'image/*';
        input.name = me.options.imageFieldName;
        input.style.cssText = 'display:none;width:0px;height:0px;border:0;margin:0;padding:0;position:absolute;';

        iframe.name = iframe.id = iframeId;
        iframe.style.cssText = 'display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;';

        form.target = iframeId;
        form.method = 'POST';
        form.enctype = 'multipart/form-data';
        form.action = imageActionUrl;
        form.style.cssText = 'display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;';

        wrapper.className = 'edui-' + me.options.theme;
        wrapper.id = me.ui.id + '_iframeupload';

        form.appendChild(input);
        form.appendChild(iframe);
        wrapper.appendChild(form);
        container.appendChild(form);

        domUtils.on(input, 'change', function(){
            var loadingId = 'loading_' + (+new Date()).toString(36);
            var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
            me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');

            function callback(){
                var link, json, loader, body = (iframe.contentDocument || iframe.contentWindow.contentDocument).body, result = body.innerText || body.textContent || '';
                try{
                    json = (new Function("return " + result))();
                    link = me.options.imageUrlPrefix + json.url;
                    if(json.state == 'SUCCESS' && json.url) {
                        loader = me.document.getElementById(loadingId);
                        loader.setAttribute('src', link);
                        loader.setAttribute('_src', link);
                        loader.removeAttribute('title');
                        domUtils.removeClasses(loader, 'loadingclass');
                    } else {
                        showErrorLoader && showErrorLoader(json.state);
                    }
                }catch(er){
                    showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
                }
                input.value = '';
                domUtils.un(iframe, 'load', callback);
            }
            function showErrorLoader(title){
                if(loadingId) {
                    var loader = me.document.getElementById(loadingId);
                    domUtils.removeClasses(loader, 'loadingclass');
                    domUtils.addClass(loader, 'loaderrorclass');<commit_msg>修改上传图片<commit_after>/**
 * @description
 * 简单上传:点击按钮,直接选择文件上传
 * @author Jinqn
 * @date 2014-03-31
 */
UE.plugin.register('simpleupload', function (){
    var me = this,
        uploadInput;

    function initUploadBtn(){
        var container = me.container,
            wrapper = document.createElement('form'),
            form = document.createElement('form'),
            input = uploadInput = document.createElement('input'),
            iframe = document.createElement('iframe'),
            iframeId = 'edui_iframe_' + (+new Date()).toString(36),
            imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));

        input.type = 'file';
        input.accept = 'image/*';
        input.name = me.options.imageFieldName;
        input.style.cssText = 'display:none;width:0px;height:0px;border:0;margin:0;padding:0;position:absolute;';

        iframe.name = iframe.id = iframeId;
        iframe.style.cssText = 'display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;';

        form.target = iframeId;
        form.method = 'POST';
        form.enctype = 'multipart/form-data';
        form.action = imageActionUrl;
        form.style.cssText = 'display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;';

        wrapper.className = 'edui-' + me.options.theme;
        wrapper.id = me.ui.id + '_iframeupload';

        form.appendChild(input);
        form.appendChild(iframe);
        wrapper.appendChild(form);
        container.appendChild(form);

        domUtils.on(input, 'change', function(){
            var loadingId = 'loading_' + (+new Date()).toString(36);
            var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
            me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');

            function callback(){
                var link, json, loader, body = (iframe.contentDocument || iframe.contentWindow.contentDocument).body, result = body.innerText || body.textContent || '';
                try{
                    json = (new Function("return " + result))();
                    link = me.options.imageUrlPrefix + json.url;
                    if(json.state == 'SUCCESS' && json.url) {
                        loader = me.document.getElementById(loadingId);
                        loader.setAttribute('src', link);
                        loader.setAttribute('_src', link);
                        loader.removeAttribute('title');
                        loader.removeAttribute('id');
                        domUtils.removeClasses(loader, 'loadingclass');
                    } else {
                        showErrorLoader && showErrorLoader(json.state);
                    }
                }catch(er){
                    showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
                }
                input.value = '';
                domUtils.un(iframe, 'load', callback);
            }
            function showErrorLoader(title){
                if(loadingId) {
                    var loader = me.document.getElementById(loadingId);
                    domUtils.removeClasses(loader, 'loadingclass');
                    domUtils.addClass(loader, 'loaderrorclass');
{'fraction_non_alphanumeric': 0.13952104715156924, 'fraction_numerical': 0.008032128514056224, 'mean_word_length': 2.134731934731935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5973960', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1767, 'n_words': 280}