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('') }, 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('') }, 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 = '