@lingxiteam/lcdp-ueditor-react 1.0.2 → 1.0.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/LcdpUeditor.js +3 -1
- package/es/tools/UeditorResourceLoader.d.ts +1 -1
- package/es/tools/UeditorResourceLoader.js +18 -7
- package/lib/LcdpUeditor.js +1 -3
- package/lib/tools/UeditorResourceLoader.d.ts +1 -1
- package/lib/tools/UeditorResourceLoader.js +15 -7
- package/package.json +1 -1
- package/ueditor-resource/dialogs/anchor/anchor.html +1 -1
- package/ueditor-resource/dialogs/attachment/attachment.css +2 -715
- package/ueditor-resource/dialogs/attachment/attachment.html +6 -6
- package/ueditor-resource/dialogs/attachment/attachment.js +2 -803
- package/ueditor-resource/dialogs/audio/audio.css +2 -878
- package/ueditor-resource/dialogs/audio/audio.js +2 -815
- package/ueditor-resource/dialogs/background/background.css +2 -192
- package/ueditor-resource/dialogs/background/background.html +3 -3
- package/ueditor-resource/dialogs/background/background.js +2 -370
- package/ueditor-resource/dialogs/contentimport/contentimport.html +3 -3
- package/ueditor-resource/dialogs/contentimport/contentimport.js +2 -91
- package/ueditor-resource/dialogs/emotion/emotion.css +2 -128
- package/ueditor-resource/dialogs/emotion/emotion.html +3 -3
- package/ueditor-resource/dialogs/emotion/emotion.js +2 -186
- package/ueditor-resource/dialogs/formula/formula.html +4 -4
- package/ueditor-resource/dialogs/formula/formula.js +2 -147
- package/ueditor-resource/dialogs/help/help.css +2 -36
- package/ueditor-resource/dialogs/help/help.html +3 -3
- package/ueditor-resource/dialogs/help/help.js +2 -57
- package/ueditor-resource/dialogs/image/image.css +2 -767
- package/ueditor-resource/dialogs/image/image.js +2 -1060
- package/ueditor-resource/dialogs/insertframe/insertframe.html +2 -2
- package/ueditor-resource/dialogs/internal.js +2 -81
- package/ueditor-resource/dialogs/preview/preview.html +2 -2
- package/ueditor-resource/dialogs/scrawl/scrawl.css +2 -323
- package/ueditor-resource/dialogs/scrawl/scrawl.html +3 -3
- package/ueditor-resource/dialogs/scrawl/scrawl.js +2 -682
- package/ueditor-resource/dialogs/searchreplace/searchreplace.html +2 -2
- package/ueditor-resource/dialogs/searchreplace/searchreplace.js +2 -174
- package/ueditor-resource/dialogs/spechars/spechars.html +2 -2
- package/ueditor-resource/dialogs/spechars/spechars.js +2 -86
- package/ueditor-resource/dialogs/table/edittable.css +2 -84
- package/ueditor-resource/dialogs/table/edittable.html +3 -3
- package/ueditor-resource/dialogs/table/edittable.js +2 -241
- package/ueditor-resource/dialogs/table/edittd.html +1 -1
- package/ueditor-resource/dialogs/table/edittip.html +1 -1
- package/ueditor-resource/dialogs/template/config.js +2 -42
- package/ueditor-resource/dialogs/template/template.css +2 -98
- package/ueditor-resource/dialogs/template/template.html +4 -4
- package/ueditor-resource/dialogs/template/template.js +2 -53
- package/ueditor-resource/dialogs/video/video.css +2 -908
- package/ueditor-resource/dialogs/video/video.js +2 -867
- package/ueditor-resource/dialogs/wordimage/wordimage.html +5 -5
- package/ueditor-resource/dialogs/wordimage/wordimage.js +2 -93
- package/ueditor-resource/lang/en/en.js +2 -686
- package/ueditor-resource/lang/zh-cn/zh-cn.js +2 -748
- package/ueditor-resource/lang/zh-tw/zh-tw.js +2 -748
- package/ueditor-resource/plugins/demo/demo.js +1 -3
- package/ueditor-resource/themes/default/css/ueditor.css +2 -2148
- package/ueditor-resource/themes/default/dialog.css +2 -16
- package/ueditor-resource/themes/default/dialogbase.css +2 -131
- package/ueditor-resource/themes/iframe.css +2 -62
- package/ueditor-resource/third-party/SyntaxHighlighter/shCore.js +4 -3655
- package/ueditor-resource/third-party/SyntaxHighlighter/shCoreDefault.css +3 -1
- package/ueditor-resource/third-party/clipboard/clipboard.js +2 -753
- package/ueditor-resource/third-party/codemirror/codemirror.css +2 -105
- package/ueditor-resource/third-party/codemirror/codemirror.js +3 -3581
- package/ueditor-resource/third-party/jquery-3.5.1.js +4 -2
- package/ueditor-resource/third-party/jquery-3.5.1_1.js +4 -4314
- package/ueditor-resource/third-party/webuploader/webuploader.css +2 -87
- package/ueditor-resource/third-party/webuploader/webuploader.js +5 -4
- package/ueditor-resource/ueditor.all.js +20 -32644
- package/ueditor-resource/ueditor.config.js +2 -655
- package/ueditor-resource/ueditor.parse.js +2 -639
- package/es/LcdpUeditor.d.ts.map +0 -1
- package/es/const.d.ts.map +0 -1
- package/es/index.d.ts.map +0 -1
- package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
- package/es/tools/filterHtmlNode.d.ts.map +0 -1
- package/es/tools/loadScript.d.ts.map +0 -1
- package/es/type.d.ts.map +0 -1
| @@ -1,1060 +1,2 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             * User: Jinqn
         | 
| 3 | 
            -
             * Date: 14-04-08
         | 
| 4 | 
            -
             * Time: 下午16:34
         | 
| 5 | 
            -
             * 上传图片对话框逻辑代码,包括tab: 远程图片/上传图片/在线图片/搜索图片
         | 
| 6 | 
            -
             */
         | 
| 7 | 
            -
            (function () {
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                var remoteImage,
         | 
| 10 | 
            -
                    uploadImage,
         | 
| 11 | 
            -
                    onlineImage;
         | 
| 12 | 
            -
                var editorOpt = {};
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                window.onload = function () {
         | 
| 15 | 
            -
                    editorOpt = editor.getOpt('imageConfig');
         | 
| 16 | 
            -
                    initTabs();
         | 
| 17 | 
            -
                    initAlign();
         | 
| 18 | 
            -
                    initButtons();
         | 
| 19 | 
            -
                };
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                /* 初始化tab标签 */
         | 
| 22 | 
            -
                function initTabs() {
         | 
| 23 | 
            -
                    var tabs = $G('tabhead').children;
         | 
| 24 | 
            -
                    for (var i = 0; i < tabs.length; i++) {
         | 
| 25 | 
            -
                        domUtils.on(tabs[i], "click", function (e) {
         | 
| 26 | 
            -
                            var target = e.target || e.srcElement;
         | 
| 27 | 
            -
                            setTabFocus(target.getAttribute('data-content-id'));
         | 
| 28 | 
            -
                        });
         | 
| 29 | 
            -
                    }
         | 
| 30 | 
            -
                    if (!editorOpt.disableUpload) {
         | 
| 31 | 
            -
                        $G('tabhead').querySelector('[data-content-id="upload"]').style.display = 'inline-block';
         | 
| 32 | 
            -
                    }
         | 
| 33 | 
            -
                    if (!editorOpt.disableOnline) {
         | 
| 34 | 
            -
                        $G('tabhead').querySelector('[data-content-id="online"]').style.display = 'inline-block';
         | 
| 35 | 
            -
                    }
         | 
| 36 | 
            -
                    if (!!editorOpt.selectCallback) {
         | 
| 37 | 
            -
                        $G('imageSelect').style.display = 'inline-block';
         | 
| 38 | 
            -
                        domUtils.on($G('imageSelect'), "click", function (e) {
         | 
| 39 | 
            -
                            editorOpt.selectCallback(editor, function (info) {
         | 
| 40 | 
            -
                                if (info) {
         | 
| 41 | 
            -
                                    $G('url').value = info.path;
         | 
| 42 | 
            -
                                    $G('title').value = info.name;
         | 
| 43 | 
            -
                                    var img = new Image();
         | 
| 44 | 
            -
                                    img.onload = function () {
         | 
| 45 | 
            -
                                        $G('width').value = img.width;
         | 
| 46 | 
            -
                                        $G('height').value = img.height;
         | 
| 47 | 
            -
                                        remoteImage.setPreview();
         | 
| 48 | 
            -
                                    };
         | 
| 49 | 
            -
                                    img.onerror = function () {
         | 
| 50 | 
            -
                                        remoteImage.setPreview();
         | 
| 51 | 
            -
                                    };
         | 
| 52 | 
            -
                                    img.src = info.path;
         | 
| 53 | 
            -
                                }
         | 
| 54 | 
            -
                            });
         | 
| 55 | 
            -
                        });
         | 
| 56 | 
            -
                    }
         | 
| 57 | 
            -
                    var img = editor.selection.getRange().getClosedNode();
         | 
| 58 | 
            -
                    if (img && img.tagName && img.tagName.toLowerCase() == 'img') {
         | 
| 59 | 
            -
                        setTabFocus('remote');
         | 
| 60 | 
            -
                    } else {
         | 
| 61 | 
            -
                        setTabFocus('remote');
         | 
| 62 | 
            -
                    }
         | 
| 63 | 
            -
                }
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                /* 初始化tabbody */
         | 
| 66 | 
            -
                function setTabFocus(id) {
         | 
| 67 | 
            -
                    if (!id) return;
         | 
| 68 | 
            -
                    var i, bodyId, tabs = $G('tabhead').children;
         | 
| 69 | 
            -
                    for (i = 0; i < tabs.length; i++) {
         | 
| 70 | 
            -
                        bodyId = tabs[i].getAttribute('data-content-id');
         | 
| 71 | 
            -
                        if (bodyId == id) {
         | 
| 72 | 
            -
                            domUtils.addClass(tabs[i], 'focus');
         | 
| 73 | 
            -
                            domUtils.addClass($G(bodyId), 'focus');
         | 
| 74 | 
            -
                        } else {
         | 
| 75 | 
            -
                            domUtils.removeClasses(tabs[i], 'focus');
         | 
| 76 | 
            -
                            domUtils.removeClasses($G(bodyId), 'focus');
         | 
| 77 | 
            -
                        }
         | 
| 78 | 
            -
                    }
         | 
| 79 | 
            -
                    switch (id) {
         | 
| 80 | 
            -
                        case 'remote':
         | 
| 81 | 
            -
                            remoteImage = remoteImage || new RemoteImage();
         | 
| 82 | 
            -
                            break;
         | 
| 83 | 
            -
                        case 'upload':
         | 
| 84 | 
            -
                            setAlign(editor.getOpt('imageInsertAlign'));
         | 
| 85 | 
            -
                            uploadImage = uploadImage || new UploadImage('queueList');
         | 
| 86 | 
            -
                            break;
         | 
| 87 | 
            -
                        case 'online':
         | 
| 88 | 
            -
                            setAlign(editor.getOpt('imageManagerInsertAlign'));
         | 
| 89 | 
            -
                            onlineImage = onlineImage || new OnlineImage('imageList');
         | 
| 90 | 
            -
                            onlineImage.reset();
         | 
| 91 | 
            -
                            break;
         | 
| 92 | 
            -
                    }
         | 
| 93 | 
            -
                }
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                /* 初始化onok事件 */
         | 
| 96 | 
            -
                function initButtons() {
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                    dialog.onok = function () {
         | 
| 99 | 
            -
                        var remote = false, list = [], id, tabs = $G('tabhead').children;
         | 
| 100 | 
            -
                        for (var i = 0; i < tabs.length; i++) {
         | 
| 101 | 
            -
                            if (domUtils.hasClass(tabs[i], 'focus')) {
         | 
| 102 | 
            -
                                id = tabs[i].getAttribute('data-content-id');
         | 
| 103 | 
            -
                                break;
         | 
| 104 | 
            -
                            }
         | 
| 105 | 
            -
                        }
         | 
| 106 | 
            -
             | 
| 107 | 
            -
                        switch (id) {
         | 
| 108 | 
            -
                            case 'remote':
         | 
| 109 | 
            -
                                list = remoteImage.getInsertList();
         | 
| 110 | 
            -
                                break;
         | 
| 111 | 
            -
                            case 'upload':
         | 
| 112 | 
            -
                                list = uploadImage.getInsertList();
         | 
| 113 | 
            -
                                var count = uploadImage.getQueueCount();
         | 
| 114 | 
            -
                                if (count) {
         | 
| 115 | 
            -
                                    $('.info', '#queueList').html('<span style="color:red;">' + '还有2个未上传文件'.replace(/[\d]/, count) + '</span>');
         | 
| 116 | 
            -
                                    return false;
         | 
| 117 | 
            -
                                }
         | 
| 118 | 
            -
                                break;
         | 
| 119 | 
            -
                            case 'online':
         | 
| 120 | 
            -
                                list = onlineImage.getInsertList();
         | 
| 121 | 
            -
                                break;
         | 
| 122 | 
            -
                        }
         | 
| 123 | 
            -
             | 
| 124 | 
            -
                        if (list) {
         | 
| 125 | 
            -
                            editor.execCommand('insertimage', list);
         | 
| 126 | 
            -
                            remote && editor.fireEvent("catchRemoteImage");
         | 
| 127 | 
            -
                        }
         | 
| 128 | 
            -
                    };
         | 
| 129 | 
            -
                }
         | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
                /* 初始化对其方式的点击事件 */
         | 
| 133 | 
            -
                function initAlign() {
         | 
| 134 | 
            -
                    /* 点击align图标 */
         | 
| 135 | 
            -
                    domUtils.on($G("alignIcon"), 'click', function (e) {
         | 
| 136 | 
            -
                        var target = e.target || e.srcElement;
         | 
| 137 | 
            -
                        if (target.className && target.className.indexOf('-align') != -1) {
         | 
| 138 | 
            -
                            setAlign(target.getAttribute('data-align'));
         | 
| 139 | 
            -
                        }
         | 
| 140 | 
            -
                    });
         | 
| 141 | 
            -
                }
         | 
| 142 | 
            -
             | 
| 143 | 
            -
                /* 设置对齐方式 */
         | 
| 144 | 
            -
                function setAlign(align) {
         | 
| 145 | 
            -
                    align = align || 'none';
         | 
| 146 | 
            -
                    var aligns = $G("alignIcon").children;
         | 
| 147 | 
            -
                    for (i = 0; i < aligns.length; i++) {
         | 
| 148 | 
            -
                        if (aligns[i].getAttribute('data-align') == align) {
         | 
| 149 | 
            -
                            domUtils.addClass(aligns[i], 'focus');
         | 
| 150 | 
            -
                            $G("align").value = aligns[i].getAttribute('data-align');
         | 
| 151 | 
            -
                        } else {
         | 
| 152 | 
            -
                            domUtils.removeClasses(aligns[i], 'focus');
         | 
| 153 | 
            -
                        }
         | 
| 154 | 
            -
                    }
         | 
| 155 | 
            -
                }
         | 
| 156 | 
            -
             | 
| 157 | 
            -
                /* 获取对齐方式 */
         | 
| 158 | 
            -
                function getAlign() {
         | 
| 159 | 
            -
                    var align = $G("align").value || 'none';
         | 
| 160 | 
            -
                    return align == 'none' ? '' : align;
         | 
| 161 | 
            -
                }
         | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
                /* 在线图片 */
         | 
| 165 | 
            -
                function RemoteImage(target) {
         | 
| 166 | 
            -
                    this.container = utils.isString(target) ? document.getElementById(target) : target;
         | 
| 167 | 
            -
                    this.init();
         | 
| 168 | 
            -
                }
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                RemoteImage.prototype = {
         | 
| 171 | 
            -
                    init: function () {
         | 
| 172 | 
            -
                        this.initContainer();
         | 
| 173 | 
            -
                        this.initEvents();
         | 
| 174 | 
            -
                    },
         | 
| 175 | 
            -
                    initContainer: function () {
         | 
| 176 | 
            -
                        this.dom = {
         | 
| 177 | 
            -
                            'url': $G('url'),
         | 
| 178 | 
            -
                            'width': $G('width'),
         | 
| 179 | 
            -
                            'height': $G('height'),
         | 
| 180 | 
            -
                            'border': $G('border'),
         | 
| 181 | 
            -
                            'vhSpace': $G('vhSpace'),
         | 
| 182 | 
            -
                            'title': $G('title'),
         | 
| 183 | 
            -
                            'align': $G('align')
         | 
| 184 | 
            -
                        };
         | 
| 185 | 
            -
                        var img = editor.selection.getRange().getClosedNode();
         | 
| 186 | 
            -
                        if (img) {
         | 
| 187 | 
            -
                            this.setImage(img);
         | 
| 188 | 
            -
                        }
         | 
| 189 | 
            -
                    },
         | 
| 190 | 
            -
                    initEvents: function () {
         | 
| 191 | 
            -
                        var _this = this,
         | 
| 192 | 
            -
                            locker = {};
         | 
| 193 | 
            -
             | 
| 194 | 
            -
                        /* 改变url */
         | 
| 195 | 
            -
                        domUtils.on($G("url"), 'keyup', updatePreview);
         | 
| 196 | 
            -
                        domUtils.on($G("border"), 'keyup', updatePreview);
         | 
| 197 | 
            -
                        domUtils.on($G("title"), 'keyup', updatePreview);
         | 
| 198 | 
            -
             | 
| 199 | 
            -
                        domUtils.on($G("width"), 'keyup', function () {
         | 
| 200 | 
            -
                            if (locker.checked) {
         | 
| 201 | 
            -
                                var proportion = locker.getAttribute('data-proportion');
         | 
| 202 | 
            -
                                $G('height').value = Math.round(this.value / proportion);
         | 
| 203 | 
            -
                            } else {
         | 
| 204 | 
            -
                                _this.updateLocker();
         | 
| 205 | 
            -
                            }
         | 
| 206 | 
            -
                            updatePreview();
         | 
| 207 | 
            -
                        });
         | 
| 208 | 
            -
                        domUtils.on($G("height"), 'keyup', function () {
         | 
| 209 | 
            -
                            if (locker.checked) {
         | 
| 210 | 
            -
                                var proportion = locker.getAttribute('data-proportion');
         | 
| 211 | 
            -
                                $G('width').value = Math.round(this.value * proportion);
         | 
| 212 | 
            -
                            } else {
         | 
| 213 | 
            -
                                _this.updateLocker();
         | 
| 214 | 
            -
                            }
         | 
| 215 | 
            -
                            updatePreview();
         | 
| 216 | 
            -
                        });
         | 
| 217 | 
            -
                       
         | 
| 218 | 
            -
                        function updatePreview() {
         | 
| 219 | 
            -
                            _this.setPreview();
         | 
| 220 | 
            -
                        }
         | 
| 221 | 
            -
                    },
         | 
| 222 | 
            -
                    updateLocker: function () {
         | 
| 223 | 
            -
                        var width = $G('width').value,
         | 
| 224 | 
            -
                            height = $G('height').value,
         | 
| 225 | 
            -
                            locker = {};
         | 
| 226 | 
            -
                        if (width && height && width == parseInt(width) && height == parseInt(height)) {
         | 
| 227 | 
            -
                            locker.disabled = false;
         | 
| 228 | 
            -
                            locker.title = '';
         | 
| 229 | 
            -
                        } else {
         | 
| 230 | 
            -
                            locker.checked = false;
         | 
| 231 | 
            -
                            locker.disabled = 'disabled';
         | 
| 232 | 
            -
                            locker.title = lang.remoteLockError;
         | 
| 233 | 
            -
                        }
         | 
| 234 | 
            -
                    },
         | 
| 235 | 
            -
                    setImage: function (img) {
         | 
| 236 | 
            -
                        /* 不是正常的图片 */
         | 
| 237 | 
            -
                        if (!img.tagName || img.tagName.toLowerCase() != 'img' && !img.getAttribute("src") || !img.src) return;
         | 
| 238 | 
            -
             | 
| 239 | 
            -
                        var wordImgFlag = img.getAttribute("data-word-image"),
         | 
| 240 | 
            -
                            src = wordImgFlag ? wordImgFlag.replace("&", "&") : (img.getAttribute('_src') || img.getAttribute("src", 2).replace("&", "&")),
         | 
| 241 | 
            -
                            align = editor.queryCommandValue("imageFloat");
         | 
| 242 | 
            -
             | 
| 243 | 
            -
                        /* 防止onchange事件循环调用 */
         | 
| 244 | 
            -
                        if (src !== $G("url").value) $G("url").value = src;
         | 
| 245 | 
            -
                        if (src) {
         | 
| 246 | 
            -
                            /* 设置表单内容 */
         | 
| 247 | 
            -
                            $G("width").value = img.width || '';
         | 
| 248 | 
            -
                            $G("height").value = img.height || '';
         | 
| 249 | 
            -
                            $G("border").value = img.getAttribute("border") || '0';
         | 
| 250 | 
            -
                            $G("vhSpace").value = img.getAttribute("vspace") || '0';
         | 
| 251 | 
            -
                            $G("title").value = img.title || img.alt || '';
         | 
| 252 | 
            -
                            setAlign(align);
         | 
| 253 | 
            -
                            this.setPreview();
         | 
| 254 | 
            -
                            this.updateLocker();
         | 
| 255 | 
            -
                        }
         | 
| 256 | 
            -
                    },
         | 
| 257 | 
            -
                    getData: function () {
         | 
| 258 | 
            -
                        var data = {};
         | 
| 259 | 
            -
                        for (var k in this.dom) {
         | 
| 260 | 
            -
                            data[k] = this.dom[k].value;
         | 
| 261 | 
            -
                        }
         | 
| 262 | 
            -
                        return data;
         | 
| 263 | 
            -
                    },
         | 
| 264 | 
            -
                    setPreview: function () {
         | 
| 265 | 
            -
                        var url = $G('url').value,
         | 
| 266 | 
            -
                            ow = $G('width').value,
         | 
| 267 | 
            -
                            oh = $G('height').value,
         | 
| 268 | 
            -
                            border = $G('border').value,
         | 
| 269 | 
            -
                            title = $G('title').value,
         | 
| 270 | 
            -
                            preview = $G('preview'),
         | 
| 271 | 
            -
                            width,
         | 
| 272 | 
            -
                            height;
         | 
| 273 | 
            -
             | 
| 274 | 
            -
                        width = ((!ow || !oh) ? preview.offsetWidth : Math.min(ow, preview.offsetWidth));
         | 
| 275 | 
            -
                        width = width + (border * 2) > preview.offsetWidth ? width : (preview.offsetWidth - (border * 2));
         | 
| 276 | 
            -
                        height = (!ow || !oh) ? '' : width * oh / ow;
         | 
| 277 | 
            -
                        const location = window.parent.location;
         | 
| 278 | 
            -
                        const host = location.protocol + '//' + location.host + location.pathname;
         | 
| 279 | 
            -
                        if (url) {
         | 
| 280 | 
            -
                            preview.innerHTML = '<img src="' + encodeURI(host + url) + '" width="' + width + '" height="' + height + '" border="' + border + 'px solid #000" title="' + title + '" />';
         | 
| 281 | 
            -
                        }
         | 
| 282 | 
            -
                    },
         | 
| 283 | 
            -
                    getInsertList: function () {
         | 
| 284 | 
            -
                        var data = this.getData();
         | 
| 285 | 
            -
                        if (data['url']) {
         | 
| 286 | 
            -
                            var img = {
         | 
| 287 | 
            -
                                src: data['url'],
         | 
| 288 | 
            -
                                _src: data['url'],
         | 
| 289 | 
            -
                            }
         | 
| 290 | 
            -
                            img._propertyDelete = []
         | 
| 291 | 
            -
                            img.style = []
         | 
| 292 | 
            -
                            if (data['width']) {
         | 
| 293 | 
            -
                                img.width = data['width'];
         | 
| 294 | 
            -
                                img.style.push('width:' + data['width'] + 'px');
         | 
| 295 | 
            -
                            } else {
         | 
| 296 | 
            -
                                img._propertyDelete.push('width');
         | 
| 297 | 
            -
                            }
         | 
| 298 | 
            -
                            if (data['height']) {
         | 
| 299 | 
            -
                                img.height = data['height'];
         | 
| 300 | 
            -
                                img.style.push('height:' + data['height'] + 'px');
         | 
| 301 | 
            -
                            } else {
         | 
| 302 | 
            -
                                img._propertyDelete.push('height');
         | 
| 303 | 
            -
                            }
         | 
| 304 | 
            -
                            if (data['border']) {
         | 
| 305 | 
            -
                                img.border = data['border'];
         | 
| 306 | 
            -
                            } else {
         | 
| 307 | 
            -
                                img._propertyDelete.push('border');
         | 
| 308 | 
            -
                            }
         | 
| 309 | 
            -
                            if (data['align']) {
         | 
| 310 | 
            -
                                img.floatStyle = data['align'];
         | 
| 311 | 
            -
                            } else {
         | 
| 312 | 
            -
                                img._propertyDelete.push('floatStyle');
         | 
| 313 | 
            -
                            }
         | 
| 314 | 
            -
                            if (data['vhSpace']) {
         | 
| 315 | 
            -
                                img.vspace = data['vhSpace'];
         | 
| 316 | 
            -
                            } else {
         | 
| 317 | 
            -
                                img._propertyDelete.push('vspace');
         | 
| 318 | 
            -
                            }
         | 
| 319 | 
            -
                            if (data['title']) {
         | 
| 320 | 
            -
                                img.alt = data['title'];
         | 
| 321 | 
            -
                            } else {
         | 
| 322 | 
            -
                                img._propertyDelete.push('alt');
         | 
| 323 | 
            -
                            }
         | 
| 324 | 
            -
                            if (img.style.length > 0) {
         | 
| 325 | 
            -
                                img.style = img.style.join(';');
         | 
| 326 | 
            -
                            } else {
         | 
| 327 | 
            -
                                img._propertyDelete.push('style');
         | 
| 328 | 
            -
                            }
         | 
| 329 | 
            -
                            return [img];
         | 
| 330 | 
            -
                        } else {
         | 
| 331 | 
            -
                            return [];
         | 
| 332 | 
            -
                        }
         | 
| 333 | 
            -
                    }
         | 
| 334 | 
            -
                };
         | 
| 335 | 
            -
             | 
| 336 | 
            -
             | 
| 337 | 
            -
                /* 上传图片 */
         | 
| 338 | 
            -
                function UploadImage(target) {
         | 
| 339 | 
            -
                    this.$wrap = target.constructor == String ? $('#' + target) : $(target);
         | 
| 340 | 
            -
                    this.init();
         | 
| 341 | 
            -
                }
         | 
| 342 | 
            -
             | 
| 343 | 
            -
                UploadImage.prototype = {
         | 
| 344 | 
            -
                    init: function () {
         | 
| 345 | 
            -
                        this.imageList = [];
         | 
| 346 | 
            -
                        this.initContainer();
         | 
| 347 | 
            -
                        this.initUploader();
         | 
| 348 | 
            -
                    },
         | 
| 349 | 
            -
                    initContainer: function () {
         | 
| 350 | 
            -
                        this.$queue = this.$wrap.find('.filelist');
         | 
| 351 | 
            -
                    },
         | 
| 352 | 
            -
                    /* 初始化容器 */
         | 
| 353 | 
            -
                    initUploader: function () {
         | 
| 354 | 
            -
                        var _this = this,
         | 
| 355 | 
            -
                            $ = jQuery,    // just in case. Make sure it's not an other libaray.
         | 
| 356 | 
            -
                            $wrap = _this.$wrap,
         | 
| 357 | 
            -
                            // 图片容器
         | 
| 358 | 
            -
                            $queue = $wrap.find('.filelist'),
         | 
| 359 | 
            -
                            // 状态栏,包括进度和控制按钮
         | 
| 360 | 
            -
                            $statusBar = $wrap.find('.statusBar'),
         | 
| 361 | 
            -
                            // 文件总体选择信息。
         | 
| 362 | 
            -
                            $info = $statusBar.find('.info'),
         | 
| 363 | 
            -
                            // 上传按钮
         | 
| 364 | 
            -
                            $upload = $wrap.find('.uploadBtn'),
         | 
| 365 | 
            -
                            // 上传按钮
         | 
| 366 | 
            -
                            $filePickerBtn = $wrap.find('.filePickerBtn'),
         | 
| 367 | 
            -
                            // 上传按钮
         | 
| 368 | 
            -
                            $filePickerBlock = $wrap.find('.filePickerBlock'),
         | 
| 369 | 
            -
                            // 没选择文件之前的内容。
         | 
| 370 | 
            -
                            $placeHolder = $wrap.find('.placeholder'),
         | 
| 371 | 
            -
                            // 总体进度条
         | 
| 372 | 
            -
                            $progress = $statusBar.find('.progress').hide(),
         | 
| 373 | 
            -
                            // 添加的文件数量
         | 
| 374 | 
            -
                            fileCount = 0,
         | 
| 375 | 
            -
                            // 添加的文件总大小
         | 
| 376 | 
            -
                            fileSize = 0,
         | 
| 377 | 
            -
                            // 优化retina, 在retina下这个值是2
         | 
| 378 | 
            -
                            ratio = window.devicePixelRatio || 1,
         | 
| 379 | 
            -
                            // 缩略图大小
         | 
| 380 | 
            -
                            thumbnailWidth = 113 * ratio,
         | 
| 381 | 
            -
                            thumbnailHeight = 113 * ratio,
         | 
| 382 | 
            -
                            // 可能有pedding, ready, uploading, confirm, done.
         | 
| 383 | 
            -
                            state = '',
         | 
| 384 | 
            -
                            // 所有文件的进度信息,key为file id
         | 
| 385 | 
            -
                            percentages = {},
         | 
| 386 | 
            -
                            supportTransition = (function () {
         | 
| 387 | 
            -
                                var s = document.createElement('p').style,
         | 
| 388 | 
            -
                                    r = 'transition' in s ||
         | 
| 389 | 
            -
                                        'WebkitTransition' in s ||
         | 
| 390 | 
            -
                                        'MozTransition' in s ||
         | 
| 391 | 
            -
                                        'msTransition' in s ||
         | 
| 392 | 
            -
                                        'OTransition' in s;
         | 
| 393 | 
            -
                                s = null;
         | 
| 394 | 
            -
                                return r;
         | 
| 395 | 
            -
                            })(),
         | 
| 396 | 
            -
                            // WebUploader实例
         | 
| 397 | 
            -
                            uploader,
         | 
| 398 | 
            -
                            actionUrl = editor.getActionUrl(editor.getOpt('imageActionName')),
         | 
| 399 | 
            -
                            acceptExtensions = (editor.getOpt('imageAllowFiles') || []).join('').replace(/\./g, ',').replace(/^[,]/, ''),
         | 
| 400 | 
            -
                            imageMaxSize = editor.getOpt('imageMaxSize'),
         | 
| 401 | 
            -
                            imageCompressBorder = editor.getOpt('imageCompressBorder');
         | 
| 402 | 
            -
                        // 隐藏上传按钮
         | 
| 403 | 
            -
                        $upload.hide();
         | 
| 404 | 
            -
             | 
| 405 | 
            -
                        if (!WebUploader.Uploader.support()) {
         | 
| 406 | 
            -
                            $('#filePickerReady').after($('<div>').html(lang.errorNotSupport)).hide();
         | 
| 407 | 
            -
                            return;
         | 
| 408 | 
            -
                        } else if (!editor.getOpt('imageActionName')) {
         | 
| 409 | 
            -
                            $('#filePickerReady').after($('<div>').html(lang.errorLoadConfig)).hide();
         | 
| 410 | 
            -
                            return;
         | 
| 411 | 
            -
                        }
         | 
| 412 | 
            -
             | 
| 413 | 
            -
                        uploader = _this.uploader = WebUploader.create({
         | 
| 414 | 
            -
                            pick: {
         | 
| 415 | 
            -
                                id: '#filePickerReady',
         | 
| 416 | 
            -
                                label: lang.uploadSelectFile
         | 
| 417 | 
            -
                            },
         | 
| 418 | 
            -
                            accept: {
         | 
| 419 | 
            -
                                title: 'Images',
         | 
| 420 | 
            -
                                extensions: acceptExtensions,
         | 
| 421 | 
            -
                                mimeTypes: 'image/*'
         | 
| 422 | 
            -
                            },
         | 
| 423 | 
            -
                            swf: '../../third-party/webuploader/Uploader.swf',
         | 
| 424 | 
            -
                            server: '',
         | 
| 425 | 
            -
                            fileVal: editor.getOpt('imageFieldName'),
         | 
| 426 | 
            -
                            duplicate: true,
         | 
| 427 | 
            -
                            fileSingleSizeLimit: imageMaxSize,    // 默认 2 M
         | 
| 428 | 
            -
                            threads: 1,
         | 
| 429 | 
            -
                            headers: editor.getOpt('serverHeaders') || {},
         | 
| 430 | 
            -
                            compress: editor.getOpt('imageCompressEnable') ? {
         | 
| 431 | 
            -
                                enable: editor.getOpt('imageCompressEnable'),
         | 
| 432 | 
            -
                                maxWidthOrHeight: imageCompressBorder,
         | 
| 433 | 
            -
                                maxSize: imageMaxSize,
         | 
| 434 | 
            -
                            } : false
         | 
| 435 | 
            -
                        });
         | 
| 436 | 
            -
             | 
| 437 | 
            -
             | 
| 438 | 
            -
                        uploader.addButton({
         | 
| 439 | 
            -
                            id: '#filePickerBlock'
         | 
| 440 | 
            -
                        });
         | 
| 441 | 
            -
                        uploader.addButton({
         | 
| 442 | 
            -
                            id: '#filePickerBtn',
         | 
| 443 | 
            -
                            label: lang.uploadAddFile
         | 
| 444 | 
            -
                        });
         | 
| 445 | 
            -
             | 
| 446 | 
            -
                        setState('pedding');
         | 
| 447 | 
            -
             | 
| 448 | 
            -
                        // 当有文件添加进来时执行,负责view的创建
         | 
| 449 | 
            -
                        function addFile(file) {
         | 
| 450 | 
            -
                            var $li = $('<li id="' + file.id + '">' +
         | 
| 451 | 
            -
                                '<p class="title">' + file.name + '</p>' +
         | 
| 452 | 
            -
                                '<p class="imgWrap"></p>' +
         | 
| 453 | 
            -
                                '<p class="progress"><span></span></p>' +
         | 
| 454 | 
            -
                                '</li>'),
         | 
| 455 | 
            -
             | 
| 456 | 
            -
                                $btns = $('<div class="file-panel">' +
         | 
| 457 | 
            -
                                    '<span class="cancel">' + lang.uploadDelete + '</span>' +
         | 
| 458 | 
            -
                                    '<span class="rotateRight">' + lang.uploadTurnRight + '</span>' +
         | 
| 459 | 
            -
                                    '<span class="rotateLeft">' + lang.uploadTurnLeft + '</span></div>').appendTo($li),
         | 
| 460 | 
            -
                                $prgress = $li.find('p.progress span'),
         | 
| 461 | 
            -
                                $wrap = $li.find('p.imgWrap'),
         | 
| 462 | 
            -
                                $info = $('<p class="error"></p>').hide().appendTo($li),
         | 
| 463 | 
            -
             | 
| 464 | 
            -
                                showError = function (code) {
         | 
| 465 | 
            -
                                    switch (code) {
         | 
| 466 | 
            -
                                        case 'exceed_size':
         | 
| 467 | 
            -
                                            text = lang.errorExceedSize;
         | 
| 468 | 
            -
                                            break;
         | 
| 469 | 
            -
                                        case 'interrupt':
         | 
| 470 | 
            -
                                            text = lang.errorInterrupt;
         | 
| 471 | 
            -
                                            break;
         | 
| 472 | 
            -
                                        case 'http':
         | 
| 473 | 
            -
                                            text = lang.errorHttp;
         | 
| 474 | 
            -
                                            break;
         | 
| 475 | 
            -
                                        case 'not_allow_type':
         | 
| 476 | 
            -
                                            text = lang.errorFileType;
         | 
| 477 | 
            -
                                            break;
         | 
| 478 | 
            -
                                        default:
         | 
| 479 | 
            -
                                            text = lang.errorUploadRetry;
         | 
| 480 | 
            -
                                            break;
         | 
| 481 | 
            -
                                    }
         | 
| 482 | 
            -
                                    $info.text(text).show();
         | 
| 483 | 
            -
                                };
         | 
| 484 | 
            -
             | 
| 485 | 
            -
                            if (file.getStatus() === 'invalid') {
         | 
| 486 | 
            -
                                showError(file.statusText);
         | 
| 487 | 
            -
                            } else {
         | 
| 488 | 
            -
                                $wrap.text(lang.uploadPreview);
         | 
| 489 | 
            -
                                if (browser.ie && browser.version <= 7) {
         | 
| 490 | 
            -
                                    $wrap.text(lang.uploadNoPreview);
         | 
| 491 | 
            -
                                } else {
         | 
| 492 | 
            -
                                    uploader.makeThumb(file, function (error, src) {
         | 
| 493 | 
            -
                                        if (error || !src) {
         | 
| 494 | 
            -
                                            $wrap.text(lang.uploadNoPreview);
         | 
| 495 | 
            -
                                        } else {
         | 
| 496 | 
            -
                                            var $img = $('<img src="' + src + '">');
         | 
| 497 | 
            -
                                            $wrap.empty().append($img);
         | 
| 498 | 
            -
                                            $img.on('error', function () {
         | 
| 499 | 
            -
                                                $wrap.text(lang.uploadNoPreview);
         | 
| 500 | 
            -
                                            });
         | 
| 501 | 
            -
                                        }
         | 
| 502 | 
            -
                                    }, thumbnailWidth, thumbnailHeight);
         | 
| 503 | 
            -
                                }
         | 
| 504 | 
            -
                                percentages[file.id] = [file.size, 0];
         | 
| 505 | 
            -
                                file.rotation = 0;
         | 
| 506 | 
            -
             | 
| 507 | 
            -
                                /* 检查文件格式 */
         | 
| 508 | 
            -
                                if (!file.ext || acceptExtensions.indexOf(file.ext.toLowerCase()) == -1) {
         | 
| 509 | 
            -
                                    showError('not_allow_type');
         | 
| 510 | 
            -
                                    uploader.removeFile(file);
         | 
| 511 | 
            -
                                }
         | 
| 512 | 
            -
                            }
         | 
| 513 | 
            -
             | 
| 514 | 
            -
                            file.on('statuschange', function (cur, prev) {
         | 
| 515 | 
            -
                                if (prev === 'progress') {
         | 
| 516 | 
            -
                                    $prgress.hide().width(0);
         | 
| 517 | 
            -
                                } else if (prev === 'queued') {
         | 
| 518 | 
            -
                                    $li.off('mouseenter mouseleave');
         | 
| 519 | 
            -
                                    $btns.remove();
         | 
| 520 | 
            -
                                }
         | 
| 521 | 
            -
                                // 成功
         | 
| 522 | 
            -
                                if (cur === 'error' || cur === 'invalid') {
         | 
| 523 | 
            -
                                    showError(file.statusText);
         | 
| 524 | 
            -
                                    percentages[file.id][1] = 1;
         | 
| 525 | 
            -
                                } else if (cur === 'interrupt') {
         | 
| 526 | 
            -
                                    showError('interrupt');
         | 
| 527 | 
            -
                                } else if (cur === 'queued') {
         | 
| 528 | 
            -
                                    percentages[file.id][1] = 0;
         | 
| 529 | 
            -
                                } else if (cur === 'progress') {
         | 
| 530 | 
            -
                                    $info.hide();
         | 
| 531 | 
            -
                                    $prgress.css('display', 'block');
         | 
| 532 | 
            -
                                } else if (cur === 'complete') {
         | 
| 533 | 
            -
                                }
         | 
| 534 | 
            -
             | 
| 535 | 
            -
                                $li.removeClass('state-' + prev).addClass('state-' + cur);
         | 
| 536 | 
            -
                            });
         | 
| 537 | 
            -
             | 
| 538 | 
            -
                            $li.on('mouseenter', function () {
         | 
| 539 | 
            -
                                $btns.stop().animate({ height: 30 });
         | 
| 540 | 
            -
                            });
         | 
| 541 | 
            -
                            $li.on('mouseleave', function () {
         | 
| 542 | 
            -
                                $btns.stop().animate({ height: 0 });
         | 
| 543 | 
            -
                            });
         | 
| 544 | 
            -
             | 
| 545 | 
            -
                            $btns.on('click', 'span', function () {
         | 
| 546 | 
            -
                                var index = $(this).index(),
         | 
| 547 | 
            -
                                    deg;
         | 
| 548 | 
            -
             | 
| 549 | 
            -
                                switch (index) {
         | 
| 550 | 
            -
                                    case 0:
         | 
| 551 | 
            -
                                        uploader.removeFile(file);
         | 
| 552 | 
            -
                                        return;
         | 
| 553 | 
            -
                                    case 1:
         | 
| 554 | 
            -
                                        file.rotation += 90;
         | 
| 555 | 
            -
                                        break;
         | 
| 556 | 
            -
                                    case 2:
         | 
| 557 | 
            -
                                        file.rotation -= 90;
         | 
| 558 | 
            -
                                        break;
         | 
| 559 | 
            -
                                }
         | 
| 560 | 
            -
             | 
| 561 | 
            -
                                if (supportTransition) {
         | 
| 562 | 
            -
                                    deg = 'rotate(' + file.rotation + 'deg)';
         | 
| 563 | 
            -
                                    $wrap.css({
         | 
| 564 | 
            -
                                        '-webkit-transform': deg,
         | 
| 565 | 
            -
                                        '-mos-transform': deg,
         | 
| 566 | 
            -
                                        '-o-transform': deg,
         | 
| 567 | 
            -
                                        'transform': deg
         | 
| 568 | 
            -
                                    });
         | 
| 569 | 
            -
                                } else {
         | 
| 570 | 
            -
                                    $wrap.css('filter', 'progid:DXImageTransform.Microsoft.BasicImage(rotation=' + (~~((file.rotation / 90) % 4 + 4) % 4) + ')');
         | 
| 571 | 
            -
                                }
         | 
| 572 | 
            -
             | 
| 573 | 
            -
                            });
         | 
| 574 | 
            -
             | 
| 575 | 
            -
                            $li.insertBefore($filePickerBlock);
         | 
| 576 | 
            -
                        }
         | 
| 577 | 
            -
             | 
| 578 | 
            -
                        // 负责view的销毁
         | 
| 579 | 
            -
                        function removeFile(file) {
         | 
| 580 | 
            -
                            var $li = $('#' + file.id);
         | 
| 581 | 
            -
                            delete percentages[file.id];
         | 
| 582 | 
            -
                            updateTotalProgress();
         | 
| 583 | 
            -
                            $li.off().find('.file-panel').off().end().remove();
         | 
| 584 | 
            -
                        }
         | 
| 585 | 
            -
             | 
| 586 | 
            -
                        function updateTotalProgress() {
         | 
| 587 | 
            -
                            var loaded = 0,
         | 
| 588 | 
            -
                                total = 0,
         | 
| 589 | 
            -
                                spans = $progress.children(),
         | 
| 590 | 
            -
                                percent;
         | 
| 591 | 
            -
             | 
| 592 | 
            -
                            $.each(percentages, function (k, v) {
         | 
| 593 | 
            -
                                total += v[0];
         | 
| 594 | 
            -
                                loaded += v[0] * v[1];
         | 
| 595 | 
            -
                            });
         | 
| 596 | 
            -
             | 
| 597 | 
            -
                            percent = total ? loaded / total : 0;
         | 
| 598 | 
            -
             | 
| 599 | 
            -
                            spans.eq(0).text(Math.round(percent * 100) + '%');
         | 
| 600 | 
            -
                            spans.eq(1).css('width', Math.round(percent * 100) + '%');
         | 
| 601 | 
            -
                            updateStatus();
         | 
| 602 | 
            -
                        }
         | 
| 603 | 
            -
             | 
| 604 | 
            -
                        function setState(val, files) {
         | 
| 605 | 
            -
             | 
| 606 | 
            -
                            if (val !== state) {
         | 
| 607 | 
            -
             | 
| 608 | 
            -
                                var stats = uploader.getStats();
         | 
| 609 | 
            -
             | 
| 610 | 
            -
                                $upload.removeClass('state-' + state);
         | 
| 611 | 
            -
                                $upload.addClass('state-' + val);
         | 
| 612 | 
            -
             | 
| 613 | 
            -
                                switch (val) {
         | 
| 614 | 
            -
             | 
| 615 | 
            -
                                    /* 未选择文件 */
         | 
| 616 | 
            -
                                    case 'pedding':
         | 
| 617 | 
            -
                                        $queue.addClass('element-invisible');
         | 
| 618 | 
            -
                                        $statusBar.addClass('element-invisible');
         | 
| 619 | 
            -
                                        $placeHolder.removeClass('element-invisible');
         | 
| 620 | 
            -
                                        $progress.hide();
         | 
| 621 | 
            -
                                        $info.hide();
         | 
| 622 | 
            -
                                        uploader.refresh();
         | 
| 623 | 
            -
                                        break;
         | 
| 624 | 
            -
             | 
| 625 | 
            -
                                    /* 可以开始上传 */
         | 
| 626 | 
            -
                                    case 'ready':
         | 
| 627 | 
            -
                                        $placeHolder.addClass('element-invisible');
         | 
| 628 | 
            -
                                        $queue.removeClass('element-invisible');
         | 
| 629 | 
            -
                                        $statusBar.removeClass('element-invisible');
         | 
| 630 | 
            -
                                        $progress.hide();
         | 
| 631 | 
            -
                                        $info.show();
         | 
| 632 | 
            -
                                        $upload.text(lang.uploadStart);
         | 
| 633 | 
            -
                                        uploader.refresh();
         | 
| 634 | 
            -
                                        break;
         | 
| 635 | 
            -
             | 
| 636 | 
            -
                                    /* 上传中 */
         | 
| 637 | 
            -
                                    case 'uploading':
         | 
| 638 | 
            -
                                        $progress.show();
         | 
| 639 | 
            -
                                        $info.hide();
         | 
| 640 | 
            -
                                        $upload.text(lang.uploadPause);
         | 
| 641 | 
            -
                                        break;
         | 
| 642 | 
            -
             | 
| 643 | 
            -
                                    /* 暂停上传 */
         | 
| 644 | 
            -
                                    case 'paused':
         | 
| 645 | 
            -
                                        $progress.show();
         | 
| 646 | 
            -
                                        $info.hide();
         | 
| 647 | 
            -
                                        $upload.text(lang.uploadContinue);
         | 
| 648 | 
            -
                                        break;
         | 
| 649 | 
            -
             | 
| 650 | 
            -
                                    case 'confirm':
         | 
| 651 | 
            -
                                        $progress.show();
         | 
| 652 | 
            -
                                        $info.hide();
         | 
| 653 | 
            -
                                        $upload.text(lang.uploadStart);
         | 
| 654 | 
            -
             | 
| 655 | 
            -
                                        stats = uploader.getStats();
         | 
| 656 | 
            -
                                        if (stats.successNum && !stats.uploadFailNum) {
         | 
| 657 | 
            -
                                            setState('finish');
         | 
| 658 | 
            -
                                            return;
         | 
| 659 | 
            -
                                        }
         | 
| 660 | 
            -
                                        break;
         | 
| 661 | 
            -
             | 
| 662 | 
            -
                                    case 'finish':
         | 
| 663 | 
            -
                                        $progress.hide();
         | 
| 664 | 
            -
                                        $info.show();
         | 
| 665 | 
            -
                                        if (stats.uploadFailNum) {
         | 
| 666 | 
            -
                                            $upload.text(lang.uploadRetry);
         | 
| 667 | 
            -
                                        } else {
         | 
| 668 | 
            -
                                            $upload.text(lang.uploadStart);
         | 
| 669 | 
            -
                                        }
         | 
| 670 | 
            -
                                        break;
         | 
| 671 | 
            -
                                }
         | 
| 672 | 
            -
             | 
| 673 | 
            -
                                state = val;
         | 
| 674 | 
            -
                                updateStatus();
         | 
| 675 | 
            -
             | 
| 676 | 
            -
                            }
         | 
| 677 | 
            -
             | 
| 678 | 
            -
                            if (!_this.getQueueCount()) {
         | 
| 679 | 
            -
                                $upload.addClass('disabled')
         | 
| 680 | 
            -
                            } else {
         | 
| 681 | 
            -
                                $upload.removeClass('disabled')
         | 
| 682 | 
            -
                            }
         | 
| 683 | 
            -
             | 
| 684 | 
            -
                        }
         | 
| 685 | 
            -
             | 
| 686 | 
            -
                        function updateStatus() {
         | 
| 687 | 
            -
                            var text = '', stats;
         | 
| 688 | 
            -
             | 
| 689 | 
            -
                            if (state === 'ready') {
         | 
| 690 | 
            -
                                text = lang.updateStatusReady.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize));
         | 
| 691 | 
            -
                            } else if (state === 'confirm') {
         | 
| 692 | 
            -
                                stats = uploader.getStats();
         | 
| 693 | 
            -
                                if (stats.uploadFailNum) {
         | 
| 694 | 
            -
                                    text = lang.updateStatusConfirm.replace('_', stats.successNum).replace('_', stats.successNum);
         | 
| 695 | 
            -
                                }
         | 
| 696 | 
            -
                            } else {
         | 
| 697 | 
            -
                                stats = uploader.getStats();
         | 
| 698 | 
            -
                                text = lang.updateStatusFinish.replace('_', fileCount).replace('_KB', WebUploader.formatSize(fileSize)).replace('_', stats.successNum);
         | 
| 699 | 
            -
             | 
| 700 | 
            -
                                if (stats.uploadFailNum) {
         | 
| 701 | 
            -
                                    text += lang.updateStatusError.replace('_', stats.uploadFailNum);
         | 
| 702 | 
            -
                                }
         | 
| 703 | 
            -
                            }
         | 
| 704 | 
            -
             | 
| 705 | 
            -
                            $info.html(text);
         | 
| 706 | 
            -
                        }
         | 
| 707 | 
            -
             | 
| 708 | 
            -
                        /**
         | 
| 709 | 
            -
                        * 前置校验
         | 
| 710 | 
            -
                        */
         | 
| 711 | 
            -
                        uploader.on('beforeFileQueued', function (file) {
         | 
| 712 | 
            -
                            if (file.ext && acceptExtensions.indexOf(file.ext.toLowerCase()) != -1) {
         | 
| 713 | 
            -
                                return true;
         | 
| 714 | 
            -
                            }
         | 
| 715 | 
            -
                            return false;
         | 
| 716 | 
            -
                        })
         | 
| 717 | 
            -
             | 
| 718 | 
            -
                        uploader.on('fileQueued', function (file) {
         | 
| 719 | 
            -
                            fileCount++;
         | 
| 720 | 
            -
                            fileSize += file.size;
         | 
| 721 | 
            -
             | 
| 722 | 
            -
                            if (fileCount === 1) {
         | 
| 723 | 
            -
                                $placeHolder.addClass('element-invisible');
         | 
| 724 | 
            -
                                $statusBar.show();
         | 
| 725 | 
            -
                            }
         | 
| 726 | 
            -
             | 
| 727 | 
            -
                            addFile(file);
         | 
| 728 | 
            -
             | 
| 729 | 
            -
                            const uploadFunc = editor.getOpt('uploadFunction');
         | 
| 730 | 
            -
                            if (typeof uploadFunc === 'function') {
         | 
| 731 | 
            -
                                // 开始上传
         | 
| 732 | 
            -
                                if (state === 'ready') {
         | 
| 733 | 
            -
                                    setState('uploading');
         | 
| 734 | 
            -
                                } else if (state === 'pedding') {
         | 
| 735 | 
            -
                                    setState('ready');
         | 
| 736 | 
            -
                                    setState('uploading');
         | 
| 737 | 
            -
                                }
         | 
| 738 | 
            -
                                file.setStatus('progress');
         | 
| 739 | 
            -
                                uploader.trigger('uploadProgress', file, 0);
         | 
| 740 | 
            -
                                uploadFunc(file.source.source, 'image').then(function (response) {
         | 
| 741 | 
            -
                                    uploader.trigger('uploadProgress', file, 1);
         | 
| 742 | 
            -
                                    file.setStatus('complete');
         | 
| 743 | 
            -
                                    setState('finish');
         | 
| 744 | 
            -
                                    uploader.trigger('uploadSuccess', file, response);
         | 
| 745 | 
            -
                                    uploader.trigger('uploadComplete', file);
         | 
| 746 | 
            -
                                });
         | 
| 747 | 
            -
                            }
         | 
| 748 | 
            -
                        });
         | 
| 749 | 
            -
             | 
| 750 | 
            -
                        uploader.on('fileDequeued', function (file) {
         | 
| 751 | 
            -
                            if (file.ext && acceptExtensions.indexOf(file.ext.toLowerCase()) != -1 && file.size <= imageMaxSize) {
         | 
| 752 | 
            -
                                fileCount--;
         | 
| 753 | 
            -
                                fileSize -= file.size;
         | 
| 754 | 
            -
                            }
         | 
| 755 | 
            -
             | 
| 756 | 
            -
                            removeFile(file);
         | 
| 757 | 
            -
                            updateTotalProgress();
         | 
| 758 | 
            -
                        });
         | 
| 759 | 
            -
             | 
| 760 | 
            -
                        uploader.on('filesQueued', function (file) {
         | 
| 761 | 
            -
                            if (!uploader.isInProgress() && (state == 'pedding' || state == 'finish' || state == 'confirm' || state == 'ready')) {
         | 
| 762 | 
            -
                                setState('ready');
         | 
| 763 | 
            -
                            }
         | 
| 764 | 
            -
                            updateTotalProgress();
         | 
| 765 | 
            -
                        });
         | 
| 766 | 
            -
             | 
| 767 | 
            -
                        uploader.on('all', function (type, files) {
         | 
| 768 | 
            -
                            switch (type) {
         | 
| 769 | 
            -
                                case 'uploadFinished':
         | 
| 770 | 
            -
                                    setState('confirm', files);
         | 
| 771 | 
            -
                                    break;
         | 
| 772 | 
            -
                                case 'startUpload':
         | 
| 773 | 
            -
                                    /* 添加额外的GET参数 */
         | 
| 774 | 
            -
                                    var params = utils.serializeParam(editor.queryCommandValue('serverparam')) || '',
         | 
| 775 | 
            -
                                        url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?' : '&') + 'encode=utf-8&' + params);
         | 
| 776 | 
            -
                                    uploader.option('server', url);
         | 
| 777 | 
            -
                                    setState('uploading', files);
         | 
| 778 | 
            -
                                    break;
         | 
| 779 | 
            -
                                case 'stopUpload':
         | 
| 780 | 
            -
                                    setState('paused', files);
         | 
| 781 | 
            -
                                    break;
         | 
| 782 | 
            -
                            }
         | 
| 783 | 
            -
                        });
         | 
| 784 | 
            -
             | 
| 785 | 
            -
             | 
| 786 | 
            -
                        uploader.on('uploadBeforeSend', function (file, data, header) {
         | 
| 787 | 
            -
                            //这里可以通过data对象添加POST参数
         | 
| 788 | 
            -
                            if (actionUrl.toLowerCase().indexOf('jsp') != -1) {
         | 
| 789 | 
            -
                                header['X-Requested-With'] = 'XMLHttpRequest';
         | 
| 790 | 
            -
                            }
         | 
| 791 | 
            -
                            return false;
         | 
| 792 | 
            -
                        });
         | 
| 793 | 
            -
             | 
| 794 | 
            -
                        uploader.on('uploadProgress', function (file, percentage) {
         | 
| 795 | 
            -
                            var $li = $('#' + file.id),
         | 
| 796 | 
            -
                                $percent = $li.find('.progress span');
         | 
| 797 | 
            -
             | 
| 798 | 
            -
                            $percent.css('width', percentage * 100 + '%');
         | 
| 799 | 
            -
                            percentages[file.id][1] = percentage;
         | 
| 800 | 
            -
                            updateTotalProgress();
         | 
| 801 | 
            -
                        });
         | 
| 802 | 
            -
             | 
| 803 | 
            -
                        uploader.on('uploadSuccess', function (file, json) {
         | 
| 804 | 
            -
                            var $file = $('#' + file.id);
         | 
| 805 | 
            -
                            try {
         | 
| 806 | 
            -
                                if (json.state == 'SUCCESS') {
         | 
| 807 | 
            -
                                    _this.imageList.push(json);
         | 
| 808 | 
            -
                                    $file.append('<span class="success"></span>');
         | 
| 809 | 
            -
                                    // 触发上传图片事件
         | 
| 810 | 
            -
                                    editor.fireEvent("uploadsuccess", {
         | 
| 811 | 
            -
                                        res: json,
         | 
| 812 | 
            -
                                        type: 'image'
         | 
| 813 | 
            -
                                    });
         | 
| 814 | 
            -
             | 
| 815 | 
            -
                                } else {
         | 
| 816 | 
            -
                                    $file.find('.error').text(json.state).show();
         | 
| 817 | 
            -
                                }
         | 
| 818 | 
            -
                            } catch (e) {
         | 
| 819 | 
            -
                                $file.find('.error').text(lang.errorServerUpload).show();
         | 
| 820 | 
            -
                            }
         | 
| 821 | 
            -
                            updateTotalProgress();
         | 
| 822 | 
            -
                        });
         | 
| 823 | 
            -
             | 
| 824 | 
            -
                        uploader.on('uploadError', function (file, code) {
         | 
| 825 | 
            -
                        });
         | 
| 826 | 
            -
                        uploader.on('error', function (code, file) {
         | 
| 827 | 
            -
                            if (code == 'Q_TYPE_DENIED' || code == 'F_EXCEED_SIZE') {
         | 
| 828 | 
            -
                                addFile(file);
         | 
| 829 | 
            -
                            }
         | 
| 830 | 
            -
                        });
         | 
| 831 | 
            -
                        uploader.on('uploadComplete', function (file, ret) {
         | 
| 832 | 
            -
                        });
         | 
| 833 | 
            -
             | 
| 834 | 
            -
                        $upload.on('click', function () {
         | 
| 835 | 
            -
                            if ($(this).hasClass('disabled')) {
         | 
| 836 | 
            -
                                return false;
         | 
| 837 | 
            -
                            }
         | 
| 838 | 
            -
             | 
| 839 | 
            -
                            if (state === 'ready') {
         | 
| 840 | 
            -
                                uploader.upload();
         | 
| 841 | 
            -
                            } else if (state === 'paused') {
         | 
| 842 | 
            -
                                uploader.upload();
         | 
| 843 | 
            -
                            } else if (state === 'uploading') {
         | 
| 844 | 
            -
                                uploader.stop();
         | 
| 845 | 
            -
                            }
         | 
| 846 | 
            -
                        });
         | 
| 847 | 
            -
             | 
| 848 | 
            -
                        $upload.addClass('state-' + state);
         | 
| 849 | 
            -
                        updateTotalProgress();
         | 
| 850 | 
            -
                    },
         | 
| 851 | 
            -
                    getQueueCount: function () {
         | 
| 852 | 
            -
                        var file, i, status, readyFile = 0, files = this.uploader.getFiles();
         | 
| 853 | 
            -
                        for (i = 0; file = files[i++];) {
         | 
| 854 | 
            -
                            status = file.getStatus();
         | 
| 855 | 
            -
                            if (status == 'queued' || status == 'uploading' || status == 'progress') readyFile++;
         | 
| 856 | 
            -
                        }
         | 
| 857 | 
            -
                        return readyFile;
         | 
| 858 | 
            -
                    },
         | 
| 859 | 
            -
                    destroy: function () {
         | 
| 860 | 
            -
                        this.$wrap.remove();
         | 
| 861 | 
            -
                    },
         | 
| 862 | 
            -
                    getInsertList: function () {
         | 
| 863 | 
            -
                        var i, data, list = [],
         | 
| 864 | 
            -
                            align = getAlign();
         | 
| 865 | 
            -
                        for (i = 0; i < this.imageList.length; i++) {
         | 
| 866 | 
            -
                            data = this.imageList[i];
         | 
| 867 | 
            -
                            list.push({
         | 
| 868 | 
            -
                                src: data.url,
         | 
| 869 | 
            -
                                _src: data.url,
         | 
| 870 | 
            -
                                alt: data.original,
         | 
| 871 | 
            -
                                floatStyle: align
         | 
| 872 | 
            -
                            });
         | 
| 873 | 
            -
                        }
         | 
| 874 | 
            -
                        return list;
         | 
| 875 | 
            -
                    }
         | 
| 876 | 
            -
                };
         | 
| 877 | 
            -
             | 
| 878 | 
            -
             | 
| 879 | 
            -
                /* 在线图片 */
         | 
| 880 | 
            -
                function OnlineImage(target) {
         | 
| 881 | 
            -
                    this.container = utils.isString(target) ? document.getElementById(target) : target;
         | 
| 882 | 
            -
                    this.init();
         | 
| 883 | 
            -
                }
         | 
| 884 | 
            -
             | 
| 885 | 
            -
                OnlineImage.prototype = {
         | 
| 886 | 
            -
                    init: function () {
         | 
| 887 | 
            -
                        this.reset();
         | 
| 888 | 
            -
                        this.initEvents();
         | 
| 889 | 
            -
                    },
         | 
| 890 | 
            -
                    /* 初始化容器 */
         | 
| 891 | 
            -
                    initContainer: function () {
         | 
| 892 | 
            -
                        this.container.innerHTML = '';
         | 
| 893 | 
            -
                        this.list = document.createElement('ul');
         | 
| 894 | 
            -
                        this.clearFloat = document.createElement('li');
         | 
| 895 | 
            -
             | 
| 896 | 
            -
                        domUtils.addClass(this.list, 'list');
         | 
| 897 | 
            -
                        domUtils.addClass(this.clearFloat, 'clearFloat');
         | 
| 898 | 
            -
             | 
| 899 | 
            -
                        this.list.appendChild(this.clearFloat);
         | 
| 900 | 
            -
                        this.container.appendChild(this.list);
         | 
| 901 | 
            -
                    },
         | 
| 902 | 
            -
                    /* 初始化滚动事件,滚动到地步自动拉取数据 */
         | 
| 903 | 
            -
                    initEvents: function () {
         | 
| 904 | 
            -
                        var _this = this;
         | 
| 905 | 
            -
             | 
| 906 | 
            -
                        /* 滚动拉取图片 */
         | 
| 907 | 
            -
                        domUtils.on($G('imageList'), 'scroll', function (e) {
         | 
| 908 | 
            -
                            var panel = this;
         | 
| 909 | 
            -
                            if (panel.scrollHeight - (panel.offsetHeight + panel.scrollTop) < 10) {
         | 
| 910 | 
            -
                                _this.getImageData();
         | 
| 911 | 
            -
                            }
         | 
| 912 | 
            -
                        });
         | 
| 913 | 
            -
                        /* 选中图片 */
         | 
| 914 | 
            -
                        domUtils.on(this.container, 'click', function (e) {
         | 
| 915 | 
            -
                            var target = e.target || e.srcElement,
         | 
| 916 | 
            -
                                li = target.parentNode;
         | 
| 917 | 
            -
             | 
| 918 | 
            -
                            if (li.tagName.toLowerCase() == 'li') {
         | 
| 919 | 
            -
                                if (domUtils.hasClass(li, 'selected')) {
         | 
| 920 | 
            -
                                    domUtils.removeClasses(li, 'selected');
         | 
| 921 | 
            -
                                } else {
         | 
| 922 | 
            -
                                    domUtils.addClass(li, 'selected');
         | 
| 923 | 
            -
                                }
         | 
| 924 | 
            -
                            }
         | 
| 925 | 
            -
                        });
         | 
| 926 | 
            -
                    },
         | 
| 927 | 
            -
                    /* 初始化第一次的数据 */
         | 
| 928 | 
            -
                    initData: function () {
         | 
| 929 | 
            -
             | 
| 930 | 
            -
                        /* 拉取数据需要使用的值 */
         | 
| 931 | 
            -
                        this.state = 0;
         | 
| 932 | 
            -
                        this.listSize = editor.getOpt('imageManagerListSize');
         | 
| 933 | 
            -
                        this.listIndex = 0;
         | 
| 934 | 
            -
                        this.listEnd = false;
         | 
| 935 | 
            -
             | 
| 936 | 
            -
                        /* 第一次拉取数据 */
         | 
| 937 | 
            -
                        this.getImageData();
         | 
| 938 | 
            -
                    },
         | 
| 939 | 
            -
                    /* 重置界面 */
         | 
| 940 | 
            -
                    reset: function () {
         | 
| 941 | 
            -
                        this.initContainer();
         | 
| 942 | 
            -
                        this.initData();
         | 
| 943 | 
            -
                    },
         | 
| 944 | 
            -
                    /* 向后台拉取图片列表数据 */
         | 
| 945 | 
            -
                    getImageData: function () {
         | 
| 946 | 
            -
                        var _this = this;
         | 
| 947 | 
            -
             | 
| 948 | 
            -
                        if (!_this.listEnd && !this.isLoadingData) {
         | 
| 949 | 
            -
                            this.isLoadingData = true;
         | 
| 950 | 
            -
                            var url = editor.getActionUrl(editor.getOpt('imageManagerActionName')),
         | 
| 951 | 
            -
                                isJsonp = utils.isCrossDomainUrl(url);
         | 
| 952 | 
            -
                            ajax.request(url, {
         | 
| 953 | 
            -
                                'timeout': 100000,
         | 
| 954 | 
            -
                                'dataType': isJsonp ? 'jsonp' : '',
         | 
| 955 | 
            -
                                'headers': editor.options.serverHeaders || {},
         | 
| 956 | 
            -
                                'data': utils.extend({
         | 
| 957 | 
            -
                                    start: this.listIndex,
         | 
| 958 | 
            -
                                    size: this.listSize
         | 
| 959 | 
            -
                                }, editor.queryCommandValue('serverparam')),
         | 
| 960 | 
            -
                                'method': 'get',
         | 
| 961 | 
            -
                                'onsuccess': function (r) {
         | 
| 962 | 
            -
                                    try {
         | 
| 963 | 
            -
                                        var json = isJsonp ? r : eval('(' + r.responseText + ')');
         | 
| 964 | 
            -
                                        if (json.state === 'SUCCESS') {
         | 
| 965 | 
            -
                                            _this.pushData(json.list);
         | 
| 966 | 
            -
                                            _this.listIndex = parseInt(json.start) + parseInt(json.list.length);
         | 
| 967 | 
            -
                                            if (_this.listIndex >= json.total) {
         | 
| 968 | 
            -
                                                _this.listEnd = true;
         | 
| 969 | 
            -
                                            }
         | 
| 970 | 
            -
                                            _this.isLoadingData = false;
         | 
| 971 | 
            -
                                        }
         | 
| 972 | 
            -
                                    } catch (e) {
         | 
| 973 | 
            -
                                        if (r.responseText.indexOf('ue_separate_ue') != -1) {
         | 
| 974 | 
            -
                                            var list = r.responseText.split(r.responseText);
         | 
| 975 | 
            -
                                            _this.pushData(list);
         | 
| 976 | 
            -
                                            _this.listIndex = parseInt(list.length);
         | 
| 977 | 
            -
                                            _this.listEnd = true;
         | 
| 978 | 
            -
                                            _this.isLoadingData = false;
         | 
| 979 | 
            -
                                        }
         | 
| 980 | 
            -
                                    }
         | 
| 981 | 
            -
                                },
         | 
| 982 | 
            -
                                'onerror': function () {
         | 
| 983 | 
            -
                                    _this.isLoadingData = false;
         | 
| 984 | 
            -
                                }
         | 
| 985 | 
            -
                            });
         | 
| 986 | 
            -
                        }
         | 
| 987 | 
            -
                    },
         | 
| 988 | 
            -
                    /* 添加图片到列表界面上 */
         | 
| 989 | 
            -
                    pushData: function (list) {
         | 
| 990 | 
            -
                        var i, item, img, icon, _this = this;
         | 
| 991 | 
            -
                        for (i = 0; i < list.length; i++) {
         | 
| 992 | 
            -
                            if (list[i] && list[i].url) {
         | 
| 993 | 
            -
                                item = document.createElement('li');
         | 
| 994 | 
            -
                                img = document.createElement('img');
         | 
| 995 | 
            -
                                icon = document.createElement('span');
         | 
| 996 | 
            -
             | 
| 997 | 
            -
                                domUtils.on(img, 'load', (function (image) {
         | 
| 998 | 
            -
                                    return function () {
         | 
| 999 | 
            -
                                        _this.scale(image, image.parentNode.offsetWidth, image.parentNode.offsetHeight);
         | 
| 1000 | 
            -
                                    }
         | 
| 1001 | 
            -
                                })(img));
         | 
| 1002 | 
            -
                                img.width = 113;
         | 
| 1003 | 
            -
                                img.setAttribute('src', list[i].url + (list[i].url.indexOf('?') == -1 ? '?noCache=' : '&noCache=') + (+new Date()).toString(36));
         | 
| 1004 | 
            -
                                img.setAttribute('_src', list[i].url);
         | 
| 1005 | 
            -
                                domUtils.addClass(icon, 'icon');
         | 
| 1006 | 
            -
             | 
| 1007 | 
            -
                                item.appendChild(img);
         | 
| 1008 | 
            -
                                item.appendChild(icon);
         | 
| 1009 | 
            -
                                this.list.insertBefore(item, this.clearFloat);
         | 
| 1010 | 
            -
                            }
         | 
| 1011 | 
            -
                        }
         | 
| 1012 | 
            -
                    },
         | 
| 1013 | 
            -
                    /* 改变图片大小 */
         | 
| 1014 | 
            -
                    scale: function (img, w, h, type) {
         | 
| 1015 | 
            -
                        var ow = img.width,
         | 
| 1016 | 
            -
                            oh = img.height;
         | 
| 1017 | 
            -
             | 
| 1018 | 
            -
                        if (type == 'justify') {
         | 
| 1019 | 
            -
                            if (ow >= oh) {
         | 
| 1020 | 
            -
                                img.width = w;
         | 
| 1021 | 
            -
                                img.height = h * oh / ow;
         | 
| 1022 | 
            -
                                img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
         | 
| 1023 | 
            -
                            } else {
         | 
| 1024 | 
            -
                                img.width = w * ow / oh;
         | 
| 1025 | 
            -
                                img.height = h;
         | 
| 1026 | 
            -
                                img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
         | 
| 1027 | 
            -
                            }
         | 
| 1028 | 
            -
                        } else {
         | 
| 1029 | 
            -
                            if (ow >= oh) {
         | 
| 1030 | 
            -
                                img.width = w * ow / oh;
         | 
| 1031 | 
            -
                                img.height = h;
         | 
| 1032 | 
            -
                                img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
         | 
| 1033 | 
            -
                            } else {
         | 
| 1034 | 
            -
                                img.width = w;
         | 
| 1035 | 
            -
                                img.height = h * oh / ow;
         | 
| 1036 | 
            -
                                img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
         | 
| 1037 | 
            -
                            }
         | 
| 1038 | 
            -
                        }
         | 
| 1039 | 
            -
                    },
         | 
| 1040 | 
            -
                    getInsertList: function () {
         | 
| 1041 | 
            -
                        var i, lis = this.list.children, list = [], align = getAlign();
         | 
| 1042 | 
            -
                        for (i = 0; i < lis.length; i++) {
         | 
| 1043 | 
            -
                            if (domUtils.hasClass(lis[i], 'selected')) {
         | 
| 1044 | 
            -
                                var img = lis[i].firstChild,
         | 
| 1045 | 
            -
                                    src = img.getAttribute('_src');
         | 
| 1046 | 
            -
             | 
| 1047 | 
            -
                                list.push({
         | 
| 1048 | 
            -
                                    src: src,
         | 
| 1049 | 
            -
                                    _src: src,
         | 
| 1050 | 
            -
                                    alt: src.substr(src.lastIndexOf('/') + 1),
         | 
| 1051 | 
            -
                                    floatStyle: align
         | 
| 1052 | 
            -
                                });
         | 
| 1053 | 
            -
                            }
         | 
| 1054 | 
            -
             | 
| 1055 | 
            -
                        }
         | 
| 1056 | 
            -
                        return list;
         | 
| 1057 | 
            -
                    }
         | 
| 1058 | 
            -
                };
         | 
| 1059 | 
            -
             | 
| 1060 | 
            -
            })();
         | 
| 1 | 
            +
            /*! UEditorPlus v2.0.0*/
         | 
| 2 | 
            +
            !function(){function initTabs(){for(var a=$G("tabhead").children,b=0;b<a.length;b++)domUtils.on(a[b],"click",function(a){var b=a.target||a.srcElement;setTabFocus(b.getAttribute("data-content-id"))});editorOpt.disableUpload||($G("tabhead").querySelector('[data-content-id="upload"]').style.display="inline-block"),editorOpt.disableOnline||($G("tabhead").querySelector('[data-content-id="online"]').style.display="inline-block"),editorOpt.selectCallback&&($G("imageSelect").style.display="inline-block",domUtils.on($G("imageSelect"),"click",function(a){editorOpt.selectCallback(editor,function(a){if(a){$G("url").value=a.path,$G("title").value=a.name;var b=new Image;b.onload=function(){$G("width").value=b.width,$G("height").value=b.height,remoteImage.setPreview()},b.onerror=function(){remoteImage.setPreview()},b.src=a.path}})}));var c=editor.selection.getRange().getClosedNode();setTabFocus((c&&c.tagName&&"img"==c.tagName.toLowerCase(),"remote"))}function setTabFocus(a){if(a){var b,c,d=$G("tabhead").children;for(b=0;b<d.length;b++)c=d[b].getAttribute("data-content-id"),c==a?(domUtils.addClass(d[b],"focus"),domUtils.addClass($G(c),"focus")):(domUtils.removeClasses(d[b],"focus"),domUtils.removeClasses($G(c),"focus"));switch(a){case"remote":remoteImage=remoteImage||new RemoteImage;break;case"upload":setAlign(editor.getOpt("imageInsertAlign")),uploadImage=uploadImage||new UploadImage("queueList");break;case"online":setAlign(editor.getOpt("imageManagerInsertAlign")),onlineImage=onlineImage||new OnlineImage("imageList"),onlineImage.reset()}}}function initButtons(){dialog.onok=function(){for(var a,b=!1,c=[],d=$G("tabhead").children,e=0;e<d.length;e++)if(domUtils.hasClass(d[e],"focus")){a=d[e].getAttribute("data-content-id");break}switch(a){case"remote":c=remoteImage.getInsertList();break;case"upload":c=uploadImage.getInsertList();var f=uploadImage.getQueueCount();if(f)return $(".info","#queueList").html('<span style="color:red;">'+"还有2个未上传文件".replace(/[\d]/,f)+"</span>"),!1;break;case"online":c=onlineImage.getInsertList()}c&&(editor.execCommand("insertimage",c),b&&editor.fireEvent("catchRemoteImage"))}}function initAlign(){domUtils.on($G("alignIcon"),"click",function(a){var b=a.target||a.srcElement;b.className&&b.className.indexOf("-align")!=-1&&setAlign(b.getAttribute("data-align"))})}function setAlign(a){a=a||"none";var b=$G("alignIcon").children;for(i=0;i<b.length;i++)b[i].getAttribute("data-align")==a?(domUtils.addClass(b[i],"focus"),$G("align").value=b[i].getAttribute("data-align")):domUtils.removeClasses(b[i],"focus")}function getAlign(){var a=$G("align").value||"none";return"none"==a?"":a}function RemoteImage(a){this.container=utils.isString(a)?document.getElementById(a):a,this.init()}function UploadImage(a){this.$wrap=a.constructor==String?$("#"+a):$(a),this.init()}function OnlineImage(a){this.container=utils.isString(a)?document.getElementById(a):a,this.init()}var remoteImage,uploadImage,onlineImage,editorOpt={};window.onload=function(){editorOpt=editor.getOpt("imageConfig"),initTabs(),initAlign(),initButtons()},RemoteImage.prototype={init:function(){this.initContainer(),this.initEvents()},initContainer:function(){this.dom={url:$G("url"),width:$G("width"),height:$G("height"),border:$G("border"),vhSpace:$G("vhSpace"),title:$G("title"),align:$G("align")};var a=editor.selection.getRange().getClosedNode();a&&this.setImage(a)},initEvents:function(){function a(){b.setPreview()}var b=this,c={};domUtils.on($G("url"),"keyup",a),domUtils.on($G("border"),"keyup",a),domUtils.on($G("title"),"keyup",a),domUtils.on($G("width"),"keyup",function(){if(c.checked){var d=c.getAttribute("data-proportion");$G("height").value=Math.round(this.value/d)}else b.updateLocker();a()}),domUtils.on($G("height"),"keyup",function(){if(c.checked){var d=c.getAttribute("data-proportion");$G("width").value=Math.round(this.value*d)}else b.updateLocker();a()})},updateLocker:function(){var a=$G("width").value,b=$G("height").value,c={};a&&b&&a==parseInt(a)&&b==parseInt(b)?(c.disabled=!1,c.title=""):(c.checked=!1,c.disabled="disabled",c.title=lang.remoteLockError)},setImage:function(a){if(a.tagName&&("img"==a.tagName.toLowerCase()||a.getAttribute("src"))&&a.src){var b=a.getAttribute("data-word-image"),c=b?b.replace("&","&"):a.getAttribute("_src")||a.getAttribute("src",2).replace("&","&"),d=editor.queryCommandValue("imageFloat");c!==$G("url").value&&($G("url").value=c),c&&($G("width").value=a.width||"",$G("height").value=a.height||"",$G("border").value=a.getAttribute("border")||"0",$G("vhSpace").value=a.getAttribute("vspace")||"0",$G("title").value=a.title||a.alt||"",setAlign(d),this.setPreview(),this.updateLocker())}},getData:function(){var a={};for(var b in this.dom)a[b]=this.dom[b].value;return a},setPreview:function(){var a,b,c=$G("url").value,d=$G("width").value,e=$G("height").value,f=$G("border").value,g=$G("title").value,h=$G("preview");a=d&&e?Math.min(d,h.offsetWidth):h.offsetWidth,a=a+2*f>h.offsetWidth?a:h.offsetWidth-2*f,b=d&&e?a*e/d:"";const i=window.parent.location,j=i.protocol+"//"+i.host+i.pathname;c&&(h.innerHTML='<img src="'+encodeURI(j+c)+'" width="'+a+'" height="'+b+'" border="'+f+'px solid #000" title="'+g+'" />')},getInsertList:function(){var a=this.getData();if(a.url){var b={src:a.url,_src:a.url};return b._propertyDelete=[],b.style=[],a.width?(b.width=a.width,b.style.push("width:"+a.width+"px")):b._propertyDelete.push("width"),a.height?(b.height=a.height,b.style.push("height:"+a.height+"px")):b._propertyDelete.push("height"),a.border?b.border=a.border:b._propertyDelete.push("border"),a.align?b.floatStyle=a.align:b._propertyDelete.push("floatStyle"),a.vhSpace?b.vspace=a.vhSpace:b._propertyDelete.push("vspace"),a.title?b.alt=a.title:b._propertyDelete.push("alt"),b.style.length>0?b.style=b.style.join(";"):b._propertyDelete.push("style"),[b]}return[]}},UploadImage.prototype={init:function(){this.imageList=[],this.initContainer(),this.initUploader()},initContainer:function(){this.$queue=this.$wrap.find(".filelist")},initUploader:function(){function a(a){var b=h('<li id="'+a.id+'"><p class="title">'+a.name+'</p><p class="imgWrap"></p><p class="progress"><span></span></p></li>'),c=h('<div class="file-panel"><span class="cancel">'+lang.uploadDelete+'</span><span class="rotateRight">'+lang.uploadTurnRight+'</span><span class="rotateLeft">'+lang.uploadTurnLeft+"</span></div>").appendTo(b),d=b.find("p.progress span"),e=b.find("p.imgWrap"),g=h('<p class="error"></p>').hide().appendTo(b),i=function(a){switch(a){case"exceed_size":text=lang.errorExceedSize;break;case"interrupt":text=lang.errorInterrupt;break;case"http":text=lang.errorHttp;break;case"not_allow_type":text=lang.errorFileType;break;default:text=lang.errorUploadRetry}g.text(text).show()};"invalid"===a.getStatus()?i(a.statusText):(e.text(lang.uploadPreview),browser.ie&&browser.version<=7?e.text(lang.uploadNoPreview):f.makeThumb(a,function(a,b){if(a||!b)e.text(lang.uploadNoPreview);else{var c=h('<img src="'+b+'">');e.empty().append(c),c.on("error",function(){e.text(lang.uploadNoPreview)})}},t,u),w[a.id]=[a.size,0],a.rotation=0,a.ext&&z.indexOf(a.ext.toLowerCase())!=-1||(i("not_allow_type"),f.removeFile(a))),a.on("statuschange",function(e,f){"progress"===f?d.hide().width(0):"queued"===f&&(b.off("mouseenter mouseleave"),c.remove()),"error"===e||"invalid"===e?(i(a.statusText),w[a.id][1]=1):"interrupt"===e?i("interrupt"):"queued"===e?w[a.id][1]=0:"progress"===e&&(g.hide(),d.css("display","block")),b.removeClass("state-"+f).addClass("state-"+e)}),b.on("mouseenter",function(){c.stop().animate({height:30})}),b.on("mouseleave",function(){c.stop().animate({height:0})}),c.on("click","span",function(){var b,c=h(this).index();switch(c){case 0:return void f.removeFile(a);case 1:a.rotation+=90;break;case 2:a.rotation-=90}x?(b="rotate("+a.rotation+"deg)",e.css({"-webkit-transform":b,"-mos-transform":b,"-o-transform":b,transform:b})):e.css("filter","progid:DXImageTransform.Microsoft.BasicImage(rotation="+~~(a.rotation/90%4+4)%4+")")}),b.insertBefore(n)}function b(a){var b=h("#"+a.id);delete w[a.id],c(),b.off().find(".file-panel").off().end().remove()}function c(){var a,b=0,c=0,d=p.children();h.each(w,function(a,d){c+=d[0],b+=d[0]*d[1]}),a=c?b/c:0,d.eq(0).text(Math.round(100*a)+"%"),d.eq(1).css("width",Math.round(100*a)+"%"),e()}function d(a,b){if(a!==v){var c=f.getStats();switch(m.removeClass("state-"+v),m.addClass("state-"+a),a){case"pedding":j.addClass("element-invisible"),k.addClass("element-invisible"),o.removeClass("element-invisible"),p.hide(),l.hide(),f.refresh();break;case"ready":o.addClass("element-invisible"),j.removeClass("element-invisible"),k.removeClass("element-invisible"),p.hide(),l.show(),m.text(lang.uploadStart),f.refresh();break;case"uploading":p.show(),l.hide(),m.text(lang.uploadPause);break;case"paused":p.show(),l.hide(),m.text(lang.uploadContinue);break;case"confirm":if(p.show(),l.hide(),m.text(lang.uploadStart),c=f.getStats(),c.successNum&&!c.uploadFailNum)return void d("finish");break;case"finish":p.hide(),l.show(),c.uploadFailNum?m.text(lang.uploadRetry):m.text(lang.uploadStart)}v=a,e()}g.getQueueCount()?m.removeClass("disabled"):m.addClass("disabled")}function e(){var a,b="";"ready"===v?b=lang.updateStatusReady.replace("_",q).replace("_KB",WebUploader.formatSize(r)):"confirm"===v?(a=f.getStats(),a.uploadFailNum&&(b=lang.updateStatusConfirm.replace("_",a.successNum).replace("_",a.successNum))):(a=f.getStats(),b=lang.updateStatusFinish.replace("_",q).replace("_KB",WebUploader.formatSize(r)).replace("_",a.successNum),a.uploadFailNum&&(b+=lang.updateStatusError.replace("_",a.uploadFailNum))),l.html(b)}var f,g=this,h=jQuery,i=g.$wrap,j=i.find(".filelist"),k=i.find(".statusBar"),l=k.find(".info"),m=i.find(".uploadBtn"),n=(i.find(".filePickerBtn"),i.find(".filePickerBlock")),o=i.find(".placeholder"),p=k.find(".progress").hide(),q=0,r=0,s=window.devicePixelRatio||1,t=113*s,u=113*s,v="",w={},x=function(){var a=document.createElement("p").style,b="transition"in a||"WebkitTransition"in a||"MozTransition"in a||"msTransition"in a||"OTransition"in a;return a=null,b}(),y=editor.getActionUrl(editor.getOpt("imageActionName")),z=(editor.getOpt("imageAllowFiles")||[]).join("").replace(/\./g,",").replace(/^[,]/,""),A=editor.getOpt("imageMaxSize"),B=editor.getOpt("imageCompressBorder");return m.hide(),WebUploader.Uploader.support()?editor.getOpt("imageActionName")?(f=g.uploader=WebUploader.create({pick:{id:"#filePickerReady",label:lang.uploadSelectFile},accept:{title:"Images",extensions:z,mimeTypes:"image/*"},swf:"../../third-party/webuploader/Uploader.swf",server:"",fileVal:editor.getOpt("imageFieldName"),duplicate:!0,fileSingleSizeLimit:A,threads:1,headers:editor.getOpt("serverHeaders")||{},compress:!!editor.getOpt("imageCompressEnable")&&{enable:editor.getOpt("imageCompressEnable"),maxWidthOrHeight:B,maxSize:A}}),f.addButton({id:"#filePickerBlock"}),f.addButton({id:"#filePickerBtn",label:lang.uploadAddFile}),d("pedding"),f.on("beforeFileQueued",function(a){return!(!a.ext||z.indexOf(a.ext.toLowerCase())==-1)}),f.on("fileQueued",function(b){q++,r+=b.size,1===q&&(o.addClass("element-invisible"),k.show()),a(b);const c=editor.getOpt("uploadFunction");"function"==typeof c&&("ready"===v?d("uploading"):"pedding"===v&&(d("ready"),d("uploading")),b.setStatus("progress"),f.trigger("uploadProgress",b,0),c(b.source.source,"image").then(function(a){f.trigger("uploadProgress",b,1),b.setStatus("complete"),d("finish"),f.trigger("uploadSuccess",b,a),f.trigger("uploadComplete",b)}))}),f.on("fileDequeued",function(a){a.ext&&z.indexOf(a.ext.toLowerCase())!=-1&&a.size<=A&&(q--,r-=a.size),b(a),c()}),f.on("filesQueued",function(a){f.isInProgress()||"pedding"!=v&&"finish"!=v&&"confirm"!=v&&"ready"!=v||d("ready"),c()}),f.on("all",function(a,b){switch(a){case"uploadFinished":d("confirm",b);break;case"startUpload":var c=utils.serializeParam(editor.queryCommandValue("serverparam"))||"",e=utils.formatUrl(y+(y.indexOf("?")==-1?"?":"&")+"encode=utf-8&"+c);f.option("server",e),d("uploading",b);break;case"stopUpload":d("paused",b)}}),f.on("uploadBeforeSend",function(a,b,c){return y.toLowerCase().indexOf("jsp")!=-1&&(c["X-Requested-With"]="XMLHttpRequest"),!1}),f.on("uploadProgress",function(a,b){var d=h("#"+a.id),e=d.find(".progress span");e.css("width",100*b+"%"),w[a.id][1]=b,c()}),f.on("uploadSuccess",function(a,b){var d=h("#"+a.id);try{"SUCCESS"==b.state?(g.imageList.push(b),d.append('<span class="success"></span>'),editor.fireEvent("uploadsuccess",{res:b,type:"image"})):d.find(".error").text(b.state).show()}catch(e){d.find(".error").text(lang.errorServerUpload).show()}c()}),f.on("uploadError",function(a,b){}),f.on("error",function(b,c){"Q_TYPE_DENIED"!=b&&"F_EXCEED_SIZE"!=b||a(c)}),f.on("uploadComplete",function(a,b){}),m.on("click",function(){return!h(this).hasClass("disabled")&&void("ready"===v?f.upload():"paused"===v?f.upload():"uploading"===v&&f.stop())}),m.addClass("state-"+v),void c()):void h("#filePickerReady").after(h("<div>").html(lang.errorLoadConfig)).hide():void h("#filePickerReady").after(h("<div>").html(lang.errorNotSupport)).hide()},getQueueCount:function(){var a,b,c,d=0,e=this.uploader.getFiles();for(b=0;a=e[b++];)c=a.getStatus(),"queued"!=c&&"uploading"!=c&&"progress"!=c||d++;return d},destroy:function(){this.$wrap.remove()},getInsertList:function(){var a,b,c=[],d=getAlign();for(a=0;a<this.imageList.length;a++)b=this.imageList[a],c.push({src:b.url,_src:b.url,alt:b.original,floatStyle:d});return c}},OnlineImage.prototype={init:function(){this.reset(),this.initEvents()},initContainer:function(){this.container.innerHTML="",this.list=document.createElement("ul"),this.clearFloat=document.createElement("li"),domUtils.addClass(this.list,"list"),domUtils.addClass(this.clearFloat,"clearFloat"),this.list.appendChild(this.clearFloat),this.container.appendChild(this.list)},initEvents:function(){var a=this;domUtils.on($G("imageList"),"scroll",function(b){var c=this;c.scrollHeight-(c.offsetHeight+c.scrollTop)<10&&a.getImageData()}),domUtils.on(this.container,"click",function(a){var b=a.target||a.srcElement,c=b.parentNode;"li"==c.tagName.toLowerCase()&&(domUtils.hasClass(c,"selected")?domUtils.removeClasses(c,"selected"):domUtils.addClass(c,"selected"))})},initData:function(){this.state=0,this.listSize=editor.getOpt("imageManagerListSize"),this.listIndex=0,this.listEnd=!1,this.getImageData()},reset:function(){this.initContainer(),this.initData()},getImageData:function(){var _this=this;if(!_this.listEnd&&!this.isLoadingData){this.isLoadingData=!0;var url=editor.getActionUrl(editor.getOpt("imageManagerActionName")),isJsonp=utils.isCrossDomainUrl(url);ajax.request(url,{timeout:1e5,dataType:isJsonp?"jsonp":"",headers:editor.options.serverHeaders||{},data:utils.extend({start:this.listIndex,size:this.listSize},editor.queryCommandValue("serverparam")),method:"get",onsuccess:function(r){try{var json=isJsonp?r:eval("("+r.responseText+")");"SUCCESS"===json.state&&(_this.pushData(json.list),_this.listIndex=parseInt(json.start)+parseInt(json.list.length),_this.listIndex>=json.total&&(_this.listEnd=!0),_this.isLoadingData=!1)}catch(e){if(r.responseText.indexOf("ue_separate_ue")!=-1){var list=r.responseText.split(r.responseText);_this.pushData(list),_this.listIndex=parseInt(list.length),_this.listEnd=!0,_this.isLoadingData=!1}}},onerror:function(){_this.isLoadingData=!1}})}},pushData:function(a){var b,c,d,e,f=this;for(b=0;b<a.length;b++)a[b]&&a[b].url&&(c=document.createElement("li"),d=document.createElement("img"),e=document.createElement("span"),domUtils.on(d,"load",function(a){return function(){f.scale(a,a.parentNode.offsetWidth,a.parentNode.offsetHeight)}}(d)),d.width=113,d.setAttribute("src",a[b].url+(a[b].url.indexOf("?")==-1?"?noCache=":"&noCache=")+(+new Date).toString(36)),d.setAttribute("_src",a[b].url),domUtils.addClass(e,"icon"),c.appendChild(d),c.appendChild(e),this.list.insertBefore(c,this.clearFloat))},scale:function(a,b,c,d){var e=a.width,f=a.height;"justify"==d?e>=f?(a.width=b,a.height=c*f/e,a.style.marginLeft="-"+parseInt((a.width-b)/2)+"px"):(a.width=b*e/f,a.height=c,a.style.marginTop="-"+parseInt((a.height-c)/2)+"px"):e>=f?(a.width=b*e/f,a.height=c,a.style.marginLeft="-"+parseInt((a.width-b)/2)+"px"):(a.width=b,a.height=c*f/e,a.style.marginTop="-"+parseInt((a.height-c)/2)+"px")},getInsertList:function(){var a,b=this.list.children,c=[],d=getAlign();for(a=0;a<b.length;a++)if(domUtils.hasClass(b[a],"selected")){var e=b[a].firstChild,f=e.getAttribute("_src");c.push({src:f,_src:f,alt:f.substr(f.lastIndexOf("/")+1),floatStyle:d})}return c}}}();
         |