| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- console.log("base.js")
- manager.registerUI('bold', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
- className: "icon-bold",
- text: "",
- title: "加粗"
- });
- return btn;
- });
- manager.registerUI('italic', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
- className: "icon-italic",
- text: "",
- title: "斜体"
- });
- return btn;
- });
- manager.registerUI('underline', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
- className: "icon-underline",
- text: "",
- title: "下划线"
- });
- return btn;
- });
- manager.registerUI('undo', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-undo",
- text: "",
- title: "撤销",
- // cssRules: "float:right"
- });
- return btn;
- });
- manager.registerUI('redo', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-redo",
- text: "",
- title: "重做",
- // cssRules: "float:right"
- });
- return btn;
- });
- manager.registerUI('strikethrough', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
- className: "icon-strikethrough",
- text: "",
- title: "删除线"
- });
- return btn;
- });
- manager.registerUI('horizontal', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-hLine",
- text: "",
- title: "分隔线"
- });
- return btn;
- });
- manager.registerUI('removeformat', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "insideButton-removeFormat",
- text: "清除格式",
- title: "清除格式"
- });
- return btn;
- });
- manager.registerUI('fullscreen', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
- // text: "全屏",
- label: "全屏",
- title: "全屏",
- labelClassName: 'label-fullScreen',
- className: "rightBtn invertIcon-fullscreen",
- cssRules: "display:inline-block;float:right;margin-top: 6px;",
- onBtnClick: function (e) {
- var ueditor = wdeditor.getUeditor();
- var bool = ueditor.ui.isFullScreen();
- var ifr = ueditor.iframe;
- var height = parseInt($("body").height());
- var theight = parseInt(wdeditor.getToolsPanel().style.height);
- ueditor.ui.setFullScreen(!bool);
- if (!bool) {
- // var ifr = ueditor.iframe;
- // var height = parseInt($("body").height());
- // var theight = parseInt(wdeditor.getToolsPanel().style.height);
- ueditor.setHeight(height - theight);
- $(ueditor.body).height(height - theight - 26);
- } else {
- $(ueditor.body).css("height","");
- //ueditor.setHeight(wdeditor.getToolsPanel().style.height);
- }
- // this.getElement().value = !bool ? "还原" : "全屏";
- // this.setChecked(!bool);
- ueditor._selectionChange();
- },
- setSelectionChange: function () {
- var this_ = this;
- wdeditor.addListener("selectionchange", function () {
- var bool = wdeditor.getUeditor().ui.isFullScreen();
- this_.setChecked(bool);
- // this_.getElement().value = bool ? "还原" : "全屏";
- });
- }
- });
- return btn;
- });
- manager.registerUI('fontfamily', function (wdeditor, name) {
- var btn = new EditorManager.Combobox({
- name: name,
- command: name,
- labelCss: "",
- text: "字体",
- title: "字体",
- className: "ziti",
- cssRules: "height: 25px;line-height: 25px;position: relative;bottom: 3px;min-width:3em;",
- items: [{
- "text": "黑体", //菜单项的文字
- "value": "SimHei", //应用的样式
- "cssRules": "font-family:SimHei" //菜单项的样式
- }, {
- "text": "方正小标宋简体",
- "value": "方正小标宋简体",
- "cssRules": "font-family:方正小标宋简体"
- }, {
- "text": "Sans-serif",
- "value": "Sans-serif",
- "cssRules": "font-family:,Sans-serif"
- }, {
- "text": "新宋体",
- "value": "NSimSun",
- "cssRules": "font-family:NSimSun"
- }, {
- "text": "宋体",
- "value": "SimSun",
- "cssRules": "font-family:SimSun"
- }, {
- "text": "仿宋",
- "value": "FangSong",
- "cssRules": "font-family:FangSong"
- }, {
- "text": "楷体",
- "value": "KaiTi",
- "cssRules": "font-family:KaiTi"
- }, {
- "text": "仿宋_GB2312",
- "value": "FangSong_GB2312",
- "cssRules": "font-family:FangSong_GB2312"
- }, {
- "text": "楷体_GB2312",
- "value": "KaiTi_GB2312",
- "cssRules": "font-family:KaiTi_GB2312"
- }, {
- "text": "微软雅黑",
- "value": "Microsoft YaHei",
- "cssRules": "font-family:Microsoft YaHei"
- }, {
- "text": "隶书",
- "value": "LiSu",
- "cssRules": "font-family:LiSu"
- }, {
- "text": "幼圆",
- "value": "YouYuan",
- "cssRules": "font-family:YouYuan"
- }, {
- "text": "华文细黑",
- "value": "STXihei",
- "cssRules": "font-family:STXihei"
- }, {
- "text": "华文楷体",
- "value": "STKaiti",
- "cssRules": "font-family:STKaiti"
- }, {
- "text": "华文宋体",
- "value": "STSong",
- "cssRules": "font-family:STSong"
- }, {
- "text": "华文中宋",
- "value": "STZhongsong",
- "cssRules": "font-family:STZhongsong"
- }, {
- "text": "华文仿宋",
- "value": "STFangsong",
- "cssRules": "font-family:STFangsong"
- }, {
- "text": "方正舒体",
- "value": "FZShuTi",
- "cssRules": "font-family:FZShuTi"
- }, {
- "text": "方正姚体",
- "value": "FZYaoti",
- "cssRules": "font-family:FZYaoti"
- }, {
- "text": "华文彩云",
- "value": "STCaiyun",
- "cssRules": "font-family:STCaiyun"
- }, {
- "text": "华文琥珀",
- "value": "STHupo",
- "cssRules": "font-family:STHupo"
- }, {
- "text": "华文隶书",
- "value": "STLiti",
- "cssRules": "font-family:STLiti"
- }, {
- "text": "华文行楷",
- "value": "STXingkai",
- "cssRules": "font-family:STXingkai"
- }, {
- "text": "华文新魏",
- "value": "STXinwei",
- "cssRules": "font-family:STXinwei"
- }
- ],
- oninit: function () {
- this.defaultSelectValue = this.selectValue;
- this.selectValue = function (value) {
- this.element.style.fontFamily = "";
- this.element.style.cssText = "font-family:" + value + " !important;" + this.element.style.cssText;
- this.defaultSelectValue(value);
- }
- }
- });
- return btn;
- });
- manager.registerUI('helpstyle', function (wdeditor, name) {
- wdeditor.getUeditor().registerCommand(name, {
- queryCommandValue: function () {
- var sn = wdeditor.getUeditor().selection,
- range = sn.getRange(),
- startNode;
- startNode = range.getClosedNode() || sn.getStart();
- return startNode.className;
- },
- execCommand: function (cmdName, className) {
- var sn = wdeditor.getUeditor().selection,
- range = sn.getRange(),
- node;
- node = range.getClosedNode() || sn.getStart();
- node.className = className;
- }
- });
- var btn = new EditorManager.Combobox({
- name: name,
- command: name,
- label: "",
- labelCss: "",
- text: "帮助样式",
- title: "样式",
- // cssRules: "width:7em;",
- items: [{
- "text": "正文",
- "value": "help"
- }, {
- "text": "标题",
- "value": "help-title"
- }, {
- "text": "一级标题",
- "value": "help-title1"
- }, {
- "text": "二级标题",
- "value": "help-title2"
- }, {
- "text": "项目",
- "value": "help-item"
- }
- ],
- oninit: function () {
- this.defaultSelectValue = this.selectValue;
- this.selectValue = function (value) {
- this.element.style.fontFamily = "";
- this.element.style.cssText = "font-family:" + value + " !important;" + this.element.style.cssText;
- this.defaultSelectValue(value);
- }
- // $(wdeditor.getUeditor().document.head).append('<link rel="stylesheet" type="text/css" href="/zzfb_/theme/Green/general.css">')
- },
- onSelect: function (value) {
- wdeditor.execCommand("helpstyle", value);
- }
- });
- return btn;
- });
- manager.registerUI('mobilehelpstyle', function (wdeditor, name) {
- wdeditor.getUeditor().registerCommand(name, {
- queryCommandValue: function () {
- var sn = wdeditor.getUeditor().selection,
- range = sn.getRange(),
- startNode;
- startNode = range.getClosedNode() || sn.getStart();
- return startNode.className;
- },
- execCommand: function (cmdName, className) {
- var sn = wdeditor.getUeditor().selection,
- range = sn.getRange(),
- node;
- node = range.getClosedNode() || sn.getStart();
- node.className = className;
- }
- });
- var btn = new EditorManager.Combobox({
- name: name,
- command: name,
- label: "",
- labelCss: "",
- text: "帮助样式",
- title: "样式",
- // cssRules: "width:7em;",
- items: [{
- "text": "正文",
- "value": "mobileHelp-text"
- }, {
- "text": "一级标题",
- "value": "mobileHelp-title1Text"
- }
- ],
- oninit: function () {
- this.defaultSelectValue = this.selectValue;
- this.selectValue = function (value) {
- this.element.style.fontFamily = "";
- this.element.style.cssText = "font-family:" + value + " !important;" + this.element.style.cssText;
- this.defaultSelectValue(value);
- }
- // $(wdeditor.getUeditor().document.head).append('<link rel="stylesheet" type="text/css" href="/zzfb_/theme/Green/general.css">')
- },
- onSelect: function (value) {
- wdeditor.execCommand("mobilehelpstyle", value);
- }
- });
- return btn;
- });
- manager.registerUI('fontsize', function (wdeditor, name) {
- var its = [{
- "text": "初号",
- "value": "56px",
- "cssRules": "font-size:56px"
- }, {
- "text": "小初",
- "value": "48px",
- "cssRules": "font-size:48px"
- }, {
- "text": "一号",
- "value": "34.7px",
- "cssRules": "font-size:34.7px"
- }, {
- "text": "小一",
- "value": "32px",
- "cssRules": "font-size:32px"
- }, {
- "text": "二号",
- "value": "29.3px",
- "cssRules": "font-size:29.3px"
- }, {
- "text": "小二",
- "value": "24px",
- "cssRules": "font-size:24px"
- }, {
- "text": "三号",
- "value": "21px",
- "cssRules": "font-size:21px"
- }, {
- "text": "小三",
- "value": "20px",
- "cssRules": "font-size:20px"
- }, {
- "text": "四号",
- "value": "18.7px",
- "cssRules": "font-size:18.7px"
- }, {
- "text": "小四",
- "value": "16px",
- "cssRules": "font-size:16px"
- }, {
- "text": "五号",
- "value": "14px",
- "cssRules": "font-size:14px"
- }, {
- "text": "小五",
- "value": "12px",
- "cssRules": "font-size:12px"
- }
- ];
- var docele = wdeditor.getUeditor().iframe.contentDocument.documentElement;
- var size = parseInt(window.getComputedStyle(docele).fontSize);
- for (var iii = 0; iii < its.length; iii++) {
- var vvv = parseInt(its[iii].value);
- var rem = vvv / size;
- its[iii].value = rem + "rem";
- its[iii].cssRules = "font-size:" + rem + "rem";
- }
- console.log(size);
- console.log(its);
- var btn = new EditorManager.Combobox({
- name: name,
- command: name,
- text: "字号",
- title: "字号",
- cssRules: "height: 25px;line-height: 25px;position: relative;bottom: 3px;min-width:3em;",
- className: "zihao",
- items: its,
- baseSize: size,
- onBtnMouseDown: function () {
- var opts = this.getElement().options;
- var font = this.wdeditor.queryCommandValue("fontfamily");
- for (var i = 0; i < opts.length; i++) {
- opts[i].style.fontFamily = font;
- }
- },
- setSelectionChange: function () {
- var me=this;
- wdeditor.addListener("selectionchange", function () {
- var value = wdeditor.queryCommandValue(btn.getCommand());
- if (value.endsWith("px")) {
- value = parseInt(value) / me.baseSize + "rem";
- }
- me.selectValue(value);
- });
- },
- });
- return btn;
- });
- manager.registerUI('fontcolor', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-color",
- command: 'forecolor',
- wdeditor: wdeditor,
- text: "",
- title: "颜色",
- onBtnClick: function () {
- console.log(this.getElement().offsetTop);
- //this.prop.css({"top":this.getElement().offsetTop+this.getElement().offsetHeight,"left":""});
- var h = this.getElement().offsetHeight;
- var ofs = $(this.getElement()).offset();
- ofs.top += h + 3;
- this.popup.showAt(ofs);
- },
- _onPickColor: function (color) {
- wdeditor.execCommand(this.getCommand(), color);
- this.setColor && this.setColor(color);
- this.popup.hide();
- },
- _onpicknocolor: function (color) {
- this.popup.hide();
- },
- setSelectionChange: function () {
- wdeditor.addListener("selectionchange", function () {
- var value = wdeditor.queryCommandValue(btn.getCommand());
- if (btn.setColor) {
- btn.setColor(value);
- }
- });
- },
- setColor: function (color) {
- this.getElement().style.backgroundColor = color || 'black';
- },
- oninit: function () {
- var this_ = this;
- var picker = new baidu.editor.ui.ColorPicker({
- noColorText: wdeditor.getUeditor().getLang("clearColor"),
- editor: wdeditor.getUeditor(),
- onpickcolor: function (t, color) {
- this_._onPickColor(color);
- },
- onpicknocolor: function (t, color) {
- this_._onPickNoColor(color);
- }
- })
- var popup = new baidu.editor.ui.Popup({
- content: picker,
- editor: wdeditor.getUeditor()
- });
- this.popup = popup;
- }
- });
- return btn;
- });
- manager.registerUI('insertimage', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-image",
- text: "",
- title: "图片",
- command: "-",
- onBtnClick: function () {
- console.log(this.input)
- this.input.click();
- },
- oninit: function () {
- var ele = this.getElement();
- var uploaddiv = document.createElement("div");
- uploaddiv.id = btn.getBtnID() + new Date().toString(36);
- uploaddiv.style.display = "none";
- ele.parentNode.insertBefore(uploaddiv, ele);
- this.uploaddiv = uploaddiv;
- this.appendUploadFrame();
- },
- appendUploadFrame: function () {
- var this_ = this;
- var ele = this_.getElement();
- var input = document.createElement("input");
- input.type = "file";
- input.setAttribute("accept", "image/*");
- input.name = "upfile";
- var form = document.createElement("form");
- form.method = "post";
- form.enctype = "multipart/form-data";
- form.action = this_.wdeditor.getUeditor().getOpt("serverUrl");
- // var uploadHtml = '<form style="display:none;" method="POST" enctype="multipart/form-data" action="' + this.getUeditor().getOpt("serverUrl") + '"><input type="file" name="upfile" access="image/*"/>';
- form.appendChild(input);
- var frame = document.createElement("iframe");
- frame.style.display = "none";
- this_.uploaddiv.innerHTML = "";
- this_.uploaddiv.appendChild(frame);
- (frame.contentWindow || frame.contentDocument).document.body.appendChild(form);
- input.onchange = function () {
- this_.filechange(this)
- };
- this_.frame = frame;
- this_.input = input;
- this_.form = form;
- },
- filechange: function (input) {
- var this_ = this;
- var utils = UE.utils;
- var me = wdeditor.getUeditor();
- var domUtils = UE.dom.domUtils;
- if (!input.value)
- return;
- var loadingId = 'loading_' + (new Date()).getTime().toString(36);
- var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
- var imageActionUrl = me.getActionUrl(me
- .getOpt('imageActionName'));
- var allowFiles = me.getOpt('imageAllowFiles');
- me.focus();
- me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme + '/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
- function callback() {
- try {
- var link,
- json,
- loader,
- body = (this_.frame.contentDocument || this_.frame.contentWindow.document).body,
- result = body.innerText ||
- body.textContent || '';
- json = (new Function("return " + result))();
- link = me.options.imageUrlPrefix + json.url;
- if (json.state == 'SUCCESS' && json.url) {
- loader = me.document.getElementById(loadingId);
- loader.setAttribute("srcAttrName", "src");
- loader.setAttribute("tokentag", "true");
- // loader.setAttribute("source", json.url);
- loader.setAttribute('src', json.tokenURL);
- loader.setAttribute('_src', json.tokenURL);
- loader.setAttribute('title', json.title || '');
- loader.setAttribute('alt', json.original || '');
- loader.removeAttribute('id');
- domUtils.removeClasses(loader, 'loadingclass');
- } else {
- var size = this_.getSize();
- console.log(size)
- size.top += size.height;
- this_.popup.showMsg(json.state, size);
- showErrorLoader && showErrorLoader(json.state);
- }
- } catch (er) {
- this_.popup.showMsg(json.state, this.offset());
- showErrorLoader
- &&
- showErrorLoader(me
- .getLang('simpleupload.loadError'));
- }
- this_.form.reset();
- domUtils.un(this_.frame, 'load', callback);
- this_.appendUploadFrame();
- }
- function showErrorLoader(title) {
- if (loadingId) {
- var loader = me.document.getElementById(loadingId);
- loader && domUtils.remove(loader);
- me.fireEvent('showmessage', {
- 'id': loadingId,
- 'content': title,
- 'type': 'error',
- 'timeout': 4000
- });
- }
- }
- /* 判断后端配置是否没有加载成功 */
- if (!me.getOpt('imageActionName')) {
- showErrorLoader(me.getLang('autoupload.errorLoadConfig'));
- return;
- }
- // 判断文件格式是否错误
- var filename = input.value,
- fileext = filename ? filename
- .substr(filename.lastIndexOf('.')) : '';
- if (!fileext ||
- (allowFiles && (allowFiles.join('') + '.')
- .indexOf(fileext.toLowerCase() + '.') == -1)) {
- showErrorLoader(me
- .getLang('simpleupload.exceedTypeError'));
- return;
- }
- domUtils.on(btn.frame, 'load', callback);
- btn.form.action = utils.formatUrl(imageActionUrl +
- (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params); // + params) + getWdApp()。去掉 ?wdApplication=,不支持多个应用Lin
- btn.form.submit();
- }
- });
- var pop = new manager.msgPopup();
- pop.init();
- btn.popup = pop;
- return btn;
- });
- manager.registerUI('insertDoc', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-word",
- text: "",
- title: "word",
- command: "-",
- onBtnClick: function () {
- console.log(this.input)
- this.input.click();
- },
- oninit: function () {
- var ele = this.getElement();
- var uploaddiv = document.createElement("div");
- uploaddiv.id = btn.getBtnID() + new Date().toString(36);
- uploaddiv.style.display = "none";
- ele.parentNode.insertBefore(uploaddiv, ele);
- this.uploaddiv = uploaddiv;
- this.appendUploadFrame();
- },
- appendUploadFrame: function () {
- var this_ = this;
- var ele = this_.getElement();
- var input = document.createElement("input");
- input.type = "file";
- input.setAttribute("accept", ".doc,.docx");
- input.name = "upfile";
- input.onchange = function () {
- this_.filechange(this)
- };
- this_.input = input;
- },
- filechange: function (input) {
- // 没有选择文件
- if (!input.files[0]) {
- return;
- }
- wd.display.showLoad();
- var formData = new FormData();
- formData.append("file", input.files[0]);
- formData.append("name", input.name);
- $.ajax({
- type: "post",
- url: "/service?ssServ=u_uploadDoc",
- async: true,
- data: formData,
- processData: false,
- contentType: false,
- dataType: 'json',
- success: function (data) {
- if (data.msg != "success") {
- alert("插入失败!")
- wd.display.closeLoad();
- return;
- }
- $.ajax({
- type: "post",
- url: "/service?ssServ=u_docToHtml",
- async: true,
- data: {
- "filePath": data.data.src
- },
- success: function (data) {
- wdeditor.getUeditor().execCommand("insertHTML", data);
- wd.display.closeLoad();
- },
- error: function () {
- wdeditor.getUeditor().execCommand("insertHTML", "error");
- wd.display.closeLoad();
- }
- });
- },
- error: function () {
- alert("ERROR");
- wd.display.closeLoad();
- }
- });
- }
- });
- var pop = new manager.msgPopup();
- pop.init();
- btn.popup = pop;
- return btn;
- });
- manager.registerUI('insertExcel', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-excel",
- text: "",
- title: "excel",
- command: "-",
- onBtnClick: function () {
- console.log(this.input)
- this.input.click();
- },
- oninit: function () {
- var ele = this.getElement();
- var uploaddiv = document.createElement("div");
- uploaddiv.id = btn.getBtnID() + new Date().toString(36);
- uploaddiv.style.display = "none";
- ele.parentNode.insertBefore(uploaddiv, ele);
- this.uploaddiv = uploaddiv;
- this.appendUploadFrame();
- },
- appendUploadFrame: function () {
- var this_ = this;
- var ele = this_.getElement();
- var input = document.createElement("input");
- input.type = "file";
- input.setAttribute("accept", ".xls,.xlsx");
- input.name = "upfile";
- input.onchange = function () {
- this_.filechange(this)
- };
- this_.input = input;
- },
- filechange: function (input) {
- // 没有选择文件
- if (!input.files[0]) {
- return;
- }
- var formData = new FormData();
- formData.append("file", input.files[0]);
- formData.append("name", input.name);
- $.ajax({
- type: "post",
- url: "/service?ssServ=u_uploadDoc",
- async: true,
- data: formData,
- processData: false,
- contentType: false,
- dataType: 'json',
- success: function (data) {
- if (data.msg != "success") {
- alert("插入失败!")
- return;
- }
- $.ajax({
- type: "post",
- url: "/service?ssServ=u_docToHtml",
- async: true,
- data: {
- "filePath": data.data.src
- },
- success: function (data) {
- wdeditor.getUeditor().execCommand("insertHTML", data);
- },
- error: function () {
- wdeditor.getUeditor().execCommand("insertHTML", "error!");
- }
- });
- },
- error: function () {
- alert("ERROR");
- }
- });
- }
- });
- var pop = new manager.msgPopup();
- pop.init();
- btn.popup = pop;
- return btn;
- });
- manager.registerUI('customstyle', function (wdeditor, name) {
- console.log(wdeditor.options.template);
- //获取items
- var btn = new EditorManager.Combobox({
- name: name,
- command: name,
- className: "wenbenStyle",
- text: "文本样式",
- title: "文本样式",
- cssRules: "min-width:3em;line-height: 25px;position: relative;height:25px;margin-left:7px;",
- onBtnMouseDown: function () {
- var opts = this.getElement().options;
- var font = this.wdeditor.queryCommandValue(this.getCommand());
- for (var i = 0; i < opts.length; i++) {
- opts[i].style.fontFamily = font;
- }
- },
- oninit: function () {
- loadStyles();
- }
- });
- var loadStyles = window.loadStyles = function (json, callback) {
- var tmpl = wdeditor.options.template
- if (!tmpl) {
- btn.hide();
- } else {
- var items = [];
- if (json != null) {
- console.log(json)
- if (typeof(json) == "string") {
- json = JSON.parse(json);
- }
- for (var key in json) {
- var item = json[key];
- var _item = {
- "text": item.name,
- "cssRules": item.style,
- "tag": item.tag,
- value: {
- "tag": item.tag,
- "label": item.name,
- "style": item.style
- }
- };
- items.push(_item);
- }
- } else {
- console.log(wdeditor.options.template + "没有样式");
- }
- wdeditor.getUeditor().setOpt({
- "customstyle": items
- });
- btn.menu.setItems(items, true);
- if (callback) {
- callback();
- }
- }
- }
- return btn;
- });
- manager.registerUI('helpimage', function (wdeditor, name) {
- var btn = new EditorManager.Button({
- name: name,
- className: "icon-image",
- text: "",
- title: "帮助图片",
- command: "-",
- onBtnClick: function () {
- console.log(this.input)
- this.input.click();
- },
- oninit: function () {
- var ele = this.getElement();
- var uploaddiv = document.createElement("div");
- uploaddiv.id = btn.getBtnID() + new Date().toString(36);
- uploaddiv.style.display = "none";
- ele.parentNode.insertBefore(uploaddiv, ele);
- this.uploaddiv = uploaddiv;
- this.appendUploadFrame();
- },
- appendUploadFrame: function () {
- var this_ = this;
- var ele = this_.getElement();
- var input = document.createElement("input");
- input.type = "file";
- input.setAttribute("accept", "image/*");
- input.name = "upfile";
- var form = document.createElement("form");
- form.method = "post";
- form.enctype = "multipart/form-data";
- form.action = this_.wdeditor.getUeditor().getOpt("serverUrl");
- // var uploadHtml = '<form style="display:none;" method="POST" enctype="multipart/form-data" action="' + this.getUeditor().getOpt("serverUrl") + '"><input type="file" name="upfile" access="image/*"/>';
- form.appendChild(input);
- var frame = document.createElement("iframe");
- frame.style.display = "none";
- this_.uploaddiv.innerHTML = "";
- this_.uploaddiv.appendChild(frame);
- (frame.contentWindow || frame.contentDocument).document.body.appendChild(form);
- input.onchange = function () {
- this_.filechange(this)
- };
- this_.frame = frame;
- this_.input = input;
- this_.form = form;
- },
- filechange: function (input) {
- var this_ = this;
- var utils = UE.utils;
- var me = wdeditor.getUeditor();
- var domUtils = UE.dom.domUtils;
- if (!input.value)
- return;
- var loadingId = 'loading_' + (new Date()).getTime().toString(36);
- var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
- if ($("input[name='helpAppName']").size() > 0 && $("input[name='helpAppName']")[0].value != "") {
- params += "&helpAppName=" + $("input[name='helpAppName']")[0].value;
- }
- if ($("input[name='helpObjectName']").size() > 0 && $("input[name='helpObjectName']")[0].value != "") {
- params += "&helpObjectName=" + $("input[name='helpObjectName']")[0].value;
- }
- if ($("input[name='helpBusiness']").size() > 0 && $("input[name='helpBusiness']")[0].value != "") {
- params += "&helpBusiness=" + $("input[name='helpBusiness']")[0].value;
- }
- var imageActionUrl = me.getActionUrl(me
- .getOpt('imageActionName'));
- var allowFiles = me.getOpt('imageAllowFiles');
- me.focus();
- me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme + '/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
- function callback() {
- try {
- var link,
- json,
- loader,
- body = (this_.frame.contentDocument || this_.frame.contentWindow.document).body,
- result = body.innerText ||
- body.textContent || '';
- json = (new Function("return " + result))();
- link = me.options.imageUrlPrefix + json.url;
- if (json.state == 'SUCCESS' && json.url) {
- loader = me.document.getElementById(loadingId);
- loader.setAttribute("srcAttrName", "src");
- loader.setAttribute("tokentag", "0" == json.tokentag ? "false" : "true");
- // loader.setAttribute("source", json.url);
- loader.setAttribute('src', json.tokenURL);
- loader.setAttribute('_src', json.tokenURL);
- loader.setAttribute('title', json.title || '');
- loader.setAttribute('alt', json.original || '');
- loader.removeAttribute('id');
- domUtils.removeClasses(loader, 'loadingclass');
- } else {
- var size = this_.getSize();
- console.log(size)
- size.top += size.height;
- this_.popup.showMsg(json.state, size);
- showErrorLoader && showErrorLoader(json.state);
- }
- } catch (er) {
- this_.popup.showMsg(json.state, this.offset());
- showErrorLoader
- &&
- showErrorLoader(me
- .getLang('simpleupload.loadError'));
- }
- this_.form.reset();
- domUtils.un(this_.frame, 'load', callback);
- this_.appendUploadFrame();
- }
- function showErrorLoader(title) {
- if (loadingId) {
- var loader = me.document.getElementById(loadingId);
- loader && domUtils.remove(loader);
- me.fireEvent('showmessage', {
- 'id': loadingId,
- 'content': title,
- 'type': 'error',
- 'timeout': 4000
- });
- }
- }
- /* 判断后端配置是否没有加载成功 */
- if (!me.getOpt('imageActionName')) {
- showErrorLoader(me.getLang('autoupload.errorLoadConfig'));
- return;
- }
- // 判断文件格式是否错误
- var filename = input.value,
- fileext = filename ? filename
- .substr(filename.lastIndexOf('.')) : '';
- if (!fileext ||
- (allowFiles && (allowFiles.join('') + '.')
- .indexOf(fileext.toLowerCase() + '.') == -1)) {
- showErrorLoader(me
- .getLang('simpleupload.exceedTypeError'));
- return;
- }
- domUtils.on(btn.frame, 'load', callback);
- btn.form.action = utils.formatUrl(imageActionUrl +
- (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params) +"&ishelp=1"; // + params) + getWdApp() +。去掉 ?wdApplication=,不支持多个应用Lin
- btn.form.submit();
- }
- });
- var pop = new manager.msgPopup();
- pop.init();
- btn.popup = pop;
- return btn;
- });
|