1. 创建p_w_picpath.js

(function () {    var p_w_picpathUploadId = "p_w_picpathUploadId_" + new Date().getTime() + parseInt(Math.random() * 1000); // 生成唯一编号    function init(editor) {        return {            title: editor.lang.p_w_picpath["title"],            minWidth: 420,            minHeight: 360,            onShow: function () {                var selectedImg = editor.getSelectedHtml();                var imgSrc = $(selectedImg["$"].firstChild).attr("src");                var imgStyle = $(selectedImg["$"].firstChild).attr("style");                $("#" + p_w_picpathUploadId + " img.previewImage").attr("src", imgSrc);                $("#" + p_w_picpathUploadId + " img.previewImage").attr("style", imgStyle);            },            onOk: function () {                var previewImg = $("#" + p_w_picpathUploadId + " img.previewImage");                var previewImageSrc = previewImg.attr("src");                var previewImageStyle = previewImg.attr("style");                if (previewImageSrc == null || previewImageSrc == "") {                    return;                }                var p_w_picpath = editor.document.createElement('img');                p_w_picpath.setAttribute("src", previewImageSrc);                p_w_picpath.setAttribute("style", previewImageStyle);                editor.insertElement(p_w_picpath);            },            onLoad: function () {            },            onHide: function () {                $("#" + p_w_picpathUploadId + " img.previewImage").attr("src", "");                $("#" + p_w_picpathUploadId + " .width").val("");                $("#" + p_w_picpathUploadId + " .height").val("");                $("#" + p_w_picpathUploadId + " img.previewImage").css("width", "inherit");                $("#" + p_w_picpathUploadId + " img.previewImage").css("height", "inherit");            },            contents: [                {                    id: "info",                    label: editor.lang.p_w_picpath.infoTab,                    accessKey: "I",                    elements: [{                        type: "html",                        html: "
" +                                  "
" +                                      "
上传文件" +                                      "
宽度
px" +                                      "
高度
px" +                                  "" +                                  "
" +                              ""                    }]                }]        }    };    CKEDITOR.dialog.add("p_w_picpath", function (editor) {        return init(editor)    });    // 注册事件    $("#" + p_w_picpathUploadId + " .uploadFile").ysSimpleUploadFile({        changeCallback: function (file) {            var fileReader = new FileReader();            fileReader.onload = function () {                $("#" + p_w_picpathUploadId + " img.previewImage").attr("src", this.result);            };            fileReader.readAsDataURL(file);        }    });    $(document).on("keyup", "#" + p_w_picpathUploadId + " .width", function (e) {        e.stopPropagation();        e.preventDefault();        var val = $(this).val();        if (isNaN(parseInt(val))) {            return;        }        $("#" + p_w_picpathUploadId + " img.previewImage").css("width", val);    });    $(document).on("keyup", "#" + p_w_picpathUploadId + " .height", function (e) {        e.stopPropagation();        e.preventDefault();        var val = $(this).val();        if (isNaN(parseInt(val))) {            return;        }        $("#" + p_w_picpathUploadId + " img.previewImage").css("height", val);    });})();

2. 创建 ys_simple_file_upload.js

(function($){    var defaultSettings = {        acceptTypes:["jpg","png"], // 接受的上传文件类型        changeCallback:function(file){        } // 自定义input[type=file] change事件    };    var renderHtml = "
";    // 添加隐藏的    function renderInputFile(target,settings){        // 生成dialog唯一标识        var id = "ys_simple_file_upload_"+new Date().getTime()+""+parseInt(Math.random());        $(target).attr("ys_simple_file_upload",id);        $(renderHtml).attr("id",id).appendTo("html"); // 添加到文档中去        return $("#"+id);    }    function bindEventHandlers(container,settings){        var changeCallback = settings.changeCallback;        $(container).change(function(e){            e.preventDefault();            e.stopPropagation();            var file = e.target.files[0];            if(file==null){                return;            }            if(!validateFileType(file,settings)){                alert("文件类型不正确!");                return;            }            changeCallback(file);            // 清除value            $(this).val("");        });    }    // 验证文件类型    function validateFileType(file,settings){        var acceptTypes = settings.acceptTypes;        var name = file.name;        var fileSuffix = name.substr(name.lastIndexOf(".")+1);        for(var i=0;i

3. editor.html

    
    
    

4. 效果