/* 版权所有 2009-2021 荆门泽优软件有限公司 保留所有版权。 产品:http://www.ncmem.com/webapp/wordpaster/index.aspx 控件:http://www.ncmem.com/webapp/wordpaster/pack.aspx 示例:http://www.ncmem.com/webapp/wordpaster/versions.aspx 版本:2.4.6 更新记录: 2021-01-18 优化代码 2020-05-12 优化UE插件按钮注册方式。 2012-07-04 增加对IE9的支持。 */ function debugMsg(m) { $("#msg").append(m);} /* 上传对象管理器 关联HTML元素: 文件上传列表:FilePostLister 文件上传列表项模板:UploaderTemplate 文件上传列表分隔线:FilePostLine */ function WordPasterManager() { var _this = this; UE.registerUI('wordpaster', function (editor, uiName) { editor.registerCommand(uiName, { execCommand: function () { editor.focus(); _this.SetEditor(editor); _this.PasteManual(); } }); var iconUrl = editor.options.UEDITOR_HOME_URL + 'WordPaster/css/paster.png'; var btn = new UE.ui.Button({ name: "Word一键粘贴", //提示 title: 'Word一键粘贴', cssRules: 'background: url("' + iconUrl + '") no-repeat 2px 2px !important', onclick: function () { editor.focus(); _this.SetEditor(editor); _this.PasteManual(); } }); editor.addListener('selectionchange', function () { var state = editor.queryCommandState(uiName); if (state == -1) { btn.setDisabled(true); btn.setChecked(false); } else { btn.setDisabled(false); btn.setChecked(state); } }); editor.addListener('ready', function () { _this.SetEditor(editor); }); editor.addListener("firstBeforeExecCommand", function () { _this.SetEditor(editor); }); return btn; }); UE.registerUI('netpaster', function (editor, uiName) { editor.registerCommand(uiName, { execCommand: function () { editor.focus(); _this.SetEditor(editor); _this.UploadNetImg(); } }); var iconUrl = editor.options.UEDITOR_HOME_URL + 'WordPaster/css/net.png'; var btn = new UE.ui.Button({ name: "自动上传网络图片", title: '自动上传网络图片', cssRules: 'background: url("' + iconUrl + '") no-repeat 2px 2px !important', onclick: function () { editor.focus(); _this.SetEditor(editor); _this.UploadNetImg(); } }); editor.addListener('selectionchange', function () { var state = editor.queryCommandState(uiName); if (state == -1) { btn.setDisabled(true); btn.setChecked(false); } else { btn.setDisabled(false); btn.setChecked(state); } }); editor.addListener('ready', function () { _this.SetEditor(editor); }); editor.addListener("firstBeforeExecCommand", function () { _this.SetEditor(editor); }); return btn; }); UE.registerUI('ppt', function (editor, uiName) { editor.registerCommand(uiName, { execCommand: function () { editor.focus(); _this.SetEditor(editor); _this.PastePPT(); } }); var iconUrl = editor.options.UEDITOR_HOME_URL + 'WordPaster/css/ppt.png'; var btn = new UE.ui.Button({ name: "PowerPoint一键粘贴", title: 'PowerPoint一键粘贴', cssRules: 'background: url("' + iconUrl + '") no-repeat 2px 2px !important', onclick: function () { editor.focus(); _this.SetEditor(editor); _this.PastePPT(); } }); editor.addListener('selectionchange', function () { var state = editor.queryCommandState(uiName); if (state == -1) { btn.setDisabled(true); btn.setChecked(false); } else { btn.setDisabled(false); btn.setChecked(state); } }); editor.addListener('ready', function () { _this.SetEditor(editor); }); editor.addListener("firstBeforeExecCommand", function () { _this.SetEditor(editor); }); return btn; }); this.Editor = null; this.Fields = {}; //符加信息 this.UploadDialogCreated = false; this.PasteDialogCreated = false; this.imgPasterDlg = null;//jquery obj this.imgUploaderDlg = null;//jquery obj this.imgIco = null;//jquery obj this.imgMsg = null;//jquery obj this.imgPercent = null;//jquery obj this.ui = { setup: null, single: null }; this.layerPaste = 0; this.data={ browser:{name:navigator.userAgent.toLowerCase(),ie:true,ie64:false,chrome:false,firefox:false,edge:false,arm64:false,mips64:false,platform:window.navigator.platform.toLowerCase()}, error:{ "0": "连接服务器错误", "1": "发送数据错误", "2": "接收数据错误", "3": "未设置文件路径", "4": "本地文件不存在", "5": "打开本地文件错误", "6": "不能读取本地文件", "7": "公司未授权", "8": "未设置IP", "9": "域名未授权", "10": "文件大小超出限制", "11": "不能设置回调函数", "12": "Native控件错误", "13": "Word图片数量超过限制" }, type:{local:0/*本地图片*/,network:1/*网络图片*/,word:2/*word图片*/} }; this.ffPaster = null; this.ieParser = null; this.ffPasterName = "ffPaster" + new Date().getTime(); this.iePasterName = "iePaster" + new Date().getTime(); this.setuped = false;//控件是否安装 this.websocketInited = false; this.natInstalled = false; this.filesPanel = null;//jquery obj this.fileItem = null;//jquery obj this.line = null;//jquery obj this.Config = { "EncodeType" : "GB2312" , "Company" : "荆门泽优软件有限公司" , "Version" : "1,5,140,60764" , "License2" : "" , "Debug" : false//调试模式 , "LogFile" : "f:\\log.txt"//日志文件路径 , "PasteWordType" : "" //粘贴WORD的图片格式。JPG/PNG/GIF/BMP,推荐使用JPG格式,防止出现大图片。 , "PasteImageType" : "" //粘贴文件,剪帖板的图片格式,为空表示本地图片格式。JPG/PNG/GIF/BMP , "PasteImgSrc" : "" //shape:优先使用源公式图片,img:使用word自动生成的图片 , "JpgQuality" : "100" //JPG质量。0~100 , "QueueCount" : "5" //同时上传线程数 , "CryptoType" : "uuid"//名称计算方式,md5,crc,sha1,uuid,其中uuid为随机名称 , "ThumbWidth" : "0" //缩略图宽度。0表示不使用缩略图 , "ThumbHeight" : "0" //缩略图高度。0表示不使用缩略图 , "FileFieldName" : "file"//自定义文件名称名称 , "ImageMatch" : ""//服务器返回数据匹配模式,正则表达式,提取括号中的地址 , "ImageUrl" : ""//自定义图片地址,格式"{url}",{url}为固定变量,在此变量前后拼接图片路径,此变量的值为posturl返回的图片地址 , "FileCountLimit" : 300//图片数量限制 , "AppPath" : "" , "Cookie" : "" , "Servers" : [{"url":"www.ncmem.com"},{"url":"www.xproerui.com"}]//内部服务器地址(不下载此地址中的图片) , "Proxy" : {url: ""/**http://192.168.0.1:8888 */,pwd: ""/**admin:123456 */}//代理 , "WebImg" : {urlEncode:true/*下载外部图片地址是URL是否自动编码,默认情况下自动编码,部分网站URL没有进行编码*/} , "IcoError" : "http://www.ncmem.com/products/word-imagepaster/ckeditor353/WordPaster/error.png" , "IcoUploader" : "http://www.ncmem.com/products/word-imagepaster/ckeditor353/WordPaster/upload.gif" , "PostUrl" : "http://www.ncmem.com/products/word-imagepaster/fckeditor2461/asp.net/upload.aspx" //x86 ,ie:{name:"Xproer.WordParser2",clsid:"2404399F-F06B-477F-B407-B8A5385D2C5E",path:"http://res2.ncmem.com/download/WordPaster/fast/2.0.29/WordPaster.cab"} ,ie64:{name:"Xproer.WordParser2x64",clsid:"7C3DBFA4-DDE6-438A-BEEA-74920D90764B",path:"http://res2.ncmem.com/download/WordPaster/fast/2.0.29/WordPaster64.cab"} //Firefox , "XpiType" : "application/npWordPaster2" , "XpiPath" : "http://res2.ncmem.com/download/WordPaster/fast/2.0.29/WordPaster.xpi" //Chrome , "CrxName" : "npWordPaster2" , "CrxType" : "application/npWordPaster2" , "CrxPath" : "http://res2.ncmem.com/download/WordPaster/fast/2.0.29/WordPaster.crx" //Edge , edge: { protocol: "wordpaster", port: 9200, visible: false } , "ExePath": "http://res2.ncmem.com/download/WordPaster/fast/2.0.29/WordPaster.exe" , "mac": { path: "http://res2.ncmem.com/download/WordPaster/mac/1.0.17/WordPaster.pkg" } , "linux": { path: "http://res2.ncmem.com/download/WordPaster/linux/1.0.8/com.ncmem.wordpaster_2020.12.3-1_amd64.deb" } , "arm64": { path: "http://res2.ncmem.com/download/WordPaster/arm64/1.0.5/com.ncmem.wordpaster_2020.12.3-1_arm64.deb" } , "mips64": { path: "http://res2.ncmem.com/download/WordPaster/mips64/1.0.1/com.ncmem.wordpaster_2020.12.3-1_mips64el.deb" } }; this.EditorContent = ""; //编辑器内容。当图片上传完后需要更新此变量值 this.CurrentUploader = null; //当前上传项。 this.UploaderList = new Object(); //上传项列表 //已上传图片列表 //模型:LocalUrl:ServerUrl this.UploaderListCount = 0; //上传项总数 this.dialogOpened=false; this.fileMap = new Object();//文件映射表。 this.postType = this.data.type.word;//默认是word this.working = false;//正在上传中 this.pluginInited = false; this.edgeApp = new WebServer(this); this.app = WordPasterApp; this.app.ins = this; var browserName = navigator.userAgent.toLowerCase(); this.data.browser.ie = this.data.browser.name.indexOf("msie") > 0; //IE11 this.data.browser.ie = this.data.browser.ie ? this.data.browser.ie : this.data.browser.name.search(/(msie\s|trident.*rv:)([\w.]+)/) != -1; this.data.browser.firefox = this.data.browser.name.indexOf("firefox") > 0; this.data.browser.chrome = this.data.browser.name.indexOf("chrome") > 0; this.data.browser.chrome45 = false; this.data.browser.edge = this.data.browser.name.indexOf("Edge") > 0; this.data.browser.arm64 = this.data.browser.platform.indexOf("aarch64")>0; this.data.browser.mips64 = this.data.browser.platform.indexOf("mips64")>0; this.chrVer = navigator.appVersion.match(/Chrome\/(\d+)/); this.ffVer = this.data.browser.name.match(/Firefox\/(\d+)/); if (this.data.browser.edge) { this.data.browser.ie = this.data.browser.firefox = this.data.browser.chrome = this.data.browser.chrome45 = false; } //Win64 if (window.navigator.platform == "Win64") { $.extend(this.Config.ie,this.Config.ie64); }//macOS else if (window.navigator.platform == "MacIntel") { this.data.browser.edge = true; this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; this.Config.ExePath = this.Config.mac.path; } else if (window.navigator.platform == "Linux x86_64") { this.data.browser.edge = true; this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; this.Config.ExePath = this.Config.linux.path; } else if (this.data.browser.arm64) { this.data.browser.edge = true; this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; this.Config.ExePath = this.Config.arm64.path; } else if (this.data.browser.mips64) { this.data.browser.edge = true; this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; this.Config.ExePath = this.Config.mips64.path; }//Firefox else if (this.data.browser.firefox) { this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; this.data.browser.edge = true; } //chrome else if (this.data.browser.chrome) { _this.Config["XpiPath"] = _this.Config["CrxPath"]; _this.Config["XpiType"] = _this.Config["CrxType"]; this.data.browser.edge = true; this.app.postMessage = this.app.postMessageEdge; this.edgeApp.run = this.edgeApp.runChr; } else if (this.data.browser.edge) { this.app.postMessage = this.app.postMessageEdge; } this.pluginLoad = function () { if (!this.pluginInited) { if (this.data.browser.edge) { this.edgeApp.connect(); } } }; this.pluginCheck = function () { if (!this.pluginInited) { this.setup_tip(); this.pluginLoad(); return false; } return true; }; this.setup_tip = function () { var dom = this.ui.setup.find("div").html("控件加载中,如果未加载成功请先安装控件"); var lnk = dom.find('a[name="w-exe"]'); lnk.attr("href", this.Config["ExePath"]); this.layerPaste = layer.open({ type: 1, title: "安装提示", closeBtn: 1, area: ['291px', '124px'], skin: 'layui-layer-nobg', scrollbar: false, content: _this.ui.setup }); }; this.need_update = function () { var dom = this.ui.setup.html("发现新版本,请更新"); var lnk = dom.find('a[name="w-exe"]'); lnk.attr("href", this.Config["ExePath"]); this.layerPaste = layer.open({ type: 1, title: "更新提示", closeBtn: 1, area: ['170px', '113px'], skin: 'layui-layer-nobg', content: _this.ui.setup }); }; this.setupTipClose = function () { var dom = this.imgMsg.html("图片上传中......"); this.imgPercent.show(); this.imgIco.show(); this.CloseDialogPaste(); this.setuped = true; }; this.CheckUpdate = function () { if (this.Browser.CheckVer()) { this.OpenDialogPaste(); var dom = this.imgMsg.html("控件有新版本,请更新控件"); var lnk = dom.find('a[name="aCtl"]'); lnk.attr("href", this.Config["ExePath"]); this.imgPercent.hide(); this.imgIco.hide(); } }; //加载控件及HTML元素 this.GetHtml = function () { //Word图片粘贴 var acx = ""; /* 静态加截控件代码,在复杂WEB系统中或者框架页面中请静态方式加截Word解析组件(Xproer.WordParser)。 */ if (!this.data.browser.chrome45) acx += ''; //Word解析组件 acx += ' '; if (this.data.browser.edge) acx = ''; //单张图片上传窗口 acx += '
'; //安装提示 acx += '