试题公式开发解决方案:kindeditor集成jmeditor公式web编辑器
搞一套在线的考试系统,一直为即支持公式编辑又得支持各种附件上传、图片上传、视频音频上传、文字编辑 的web编辑器而犯愁。于是乎试着把 kindeditor和jmeditor集成一下,多了不说了直接上图

kindeditor版本: http://kindeditor.net/
jmeditor版本 http://www.jmeditor.com/
1、复制 \jmeditor\ckeditor\plugins\jme文件夹 到 kindeditor-/plugins/, 然后在复制\jmeditor\文件夹到 kindeditor-/plugins/ jme/。
2、修改kindeditor-/kindeditor.js。添加jme
items : [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'jme'
],
3、修改 kindeditor-/plugins/jme/plugin.js,并重命名为 代码如下:
('jme', function(e){
var editor = this, name = 'jme', lang = (name + '.');
(name, function() {
var dialog = ({
name : name,
width : 500,
height : 300,
title : (name),
body : '<div style="width:500px;height:300px;">' +
'<iframe style="width:500px;height:300px;" frameborder="no" src="/"></iframe></div>',
closeBtn : {
name : '关闭',
click : function(e) {
();
}
},
yesBtn : {
name : '确定',
click : function(e) {
var thedoc = ? ('math_frame').document : getIFrameDOM("math_frame");
var mathHTML = '<span class="mathquill-rendered-math" style="font-size:'
+ '20px' + ';" >' + $("#jme-math",thedoc).html() + '</span><span> </span>';
(mathHTML).hideDialog().focus();
return;
}
}
});
});
});
function getIFrameDOM(fid){
var fm = getIFrame(fid);
return fm.document||fm.contentDocument;
}
function getIFrame(fid){
return document.getElementById(fid)||[fid];
}
4、修改 kindeditor-/plugins/jme/dialogs/dialog.js,主要修改 为当前工作目录和全局变量,修改如下:这里 需要注意的是后面的延时函数,如果提示 $ 没有定义 可以适当延时,等待 jquery加载完成。
var KindEditor = || {};
(
"<link href=\"" + KindEditor.basePath + "plugins/jme//mathquill.css\" rel=\"stylesheet\" type=\"text/css\" />" +
"<script type=\"text/javascript\" src=\"" + KindEditor.basePath + "../jquery/\"></script>" +
"<script type=\"text/javascript\" src=\"" + KindEditor.basePath + "plugins/jme//mathquill.min.js\"></script>");
var jmeMath = [
[
"{/}frac{}{}","^{}/_{}","x^{}","x_{}","x^{}_{}","{/}bar{}","{/}sqrt{}","{/}nthroot{}{}",
"{/}sum^{}_{n=}","{/}sum","{/}log_{}","{/}ln","{/}int_{}^{}","{/}oint_{}^{}"
],
[
"{/}alpha","{/}beta","{/}gamma","{/}delta","{/}varepsilon","{/}varphi","{/}lambda","{/}mu",
"{/}rho","{/}sigma","{/}omega","{/}Gamma","{/}Delta","{/}Theta","{/}Lambda","{/}Xi",
"{/}Pi","{/}Sigma","{/}Upsilon","{/}Phi","{/}Psi","{/}Omega"
],
[
"+","-","{/}pm","{/}times","{/}ast","{/}div","/","{/}bigtriangleup",
"=","{/}ne","{/}approx",">","<","{/}ge","{/}le","{/}infty",
"{/}cap","{/}cup","{/}because","{/}therefore","{/}subset","{/}supset","{/}subseteq","{/}supseteq",
"{/}nsubseteq","{/}nsupseteq","{/}in","{/}ni","{/}notin","{/}mapsto","{/}leftarrow","{/}rightarrow",
"{/}Leftarrow","{/}Rightarrow","{/}leftrightarrow","{/}Leftrightarrow"
]
];
function mathHtml(obj){
var cols = 8;//一行放几个var slidLen = 34;//每个图标的宽或高var html="<div class='mathIcon'>";
for(var i = 0 ; i < obj.count ; i ++){
html += "<li onclick=\"insert('" + jmeMath[][i] + "')\" style=\"background-position:-" + (obj.x + (i%8)*slidLen) + "px -" + (obj.y + (i/8)*slidLen) + "px;\"></li>";
}
html += "</div>";
if(obj.count > cols * 2){
html += "<div class='more' mrows='" + ((obj.count + cols - 1) / cols) + "' isOpen='0'>更多</div>"
}
return html;
}
function insert(q){
$("#jme-math").focus().mathquill("write", ("{/}","\\"));
}
setTimeout(function(){
$(document).ready(function(){
//隐藏内容div
$(".tabContent div.mathBox").hide();
//菜单点击事件
$(".tabTitle li").click(function(){
$(".tabContent div.mathBox").hide();
var n = 0;
var obj = this;
$(".tabTitle li").each(function(i,o){
if(obj == o){
n = i;
}
});
$(".tabTitle li").removeClass("current");
$(obj).addClass("current");
$(".tabContent div.mathBox:eq(" + n + ")").show();
});
//缺省显示第一个
$(".tabTitle li:eq(0)").click();
//公式定义
$(".tabContent div.mathBox:eq(0)").html(mathHtml({
groupid:0,
x:0,
y:272,
count:14
}));
$(".tabContent div.mathBox:eq(2)").html(mathHtml({
groupid:2,
x:0,
y:0,
count:36
}));
$(".tabContent div.mathBox:eq(1)").html(mathHtml({
groupid:1,
x:0,
y:170,
count:22
}));
//常用公式,更多按钮绑定的事件
$(".tabContent div.mathBox div.more").click(function(){
var rowHei = 40;
var mi = $(this).parent().find(".mathIcon");
if($(this).attr("isOpen") == '0'){
({"height":(rowHei * Number($(this).attr("mrows")))+"px"});
$(this).html("↑ 收起");
$(this).attr("isOpen",'1');
}else{
({"height":(rowHei * 2)+"px"});
$(this).html("更多");
$(this).attr("isOpen",'0');
}
});
//公式编辑框
$("#jme-math").html("").css("font-size", '30px').mathquill('editable').mathquill('write', "");
//验证版本信息if(){
$.ajax({
url:"",
type:"post",
dataType:"html",
async:true,
data: {
versionCode:
},
success:function(data){
$(".ad").html(data);
},
error:function(){
//alert("err"); }
});
}
});
},1000);
5、拷贝 kindeditor-/plugins/jme//mathquill.css 代码 到 kindeditor-/plugins/code/prettify.css里面
6、新建到 web工程/您希望放的位置 ps: 注意 第3步骤 跳转到该页面
<%@ page language="java" import=".*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<base href="<%=basePath%20%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>插入公式</title>
<link href="<%=basePath%20%>common/kindeditor-/plugins/jme/dialogs/dialog.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="tabMenu">
<div class="tabTitle">
<li>
常用公式
</li>
<li>
字母
</li>
<li>
符号
</li>
</div>
<div class="tabContent">
<div class="mathBox">
</div>
<div class="mathBox">
</div>
<div class="mathBox">
</div>
</div>
</div>
<div>
<p>
<span></span>
</p>
<p> </p>
</div>
<div class="ad">
</div>
<script type="text/javascript" src="<%=basePath%20%>common/kindeditor-/plugins/jme/dialogs/dialog.js"></script>
</body>
</html>
7、拷贝kindeditor-/plugins/jme/icons/ 公式图标logo 到kindeditor-/themes/default/ 文件夹下
8、修改kindeditor-/themes/default/default.css (加载公式图标logo)
在
.ke-toolbar .ke-disabled {
cursor: default;
}下方
添加
.ke-icon-jme{
background: url() 0 0 no-repeat;
width: 16px;
height: 16px;
}
9、修改kindeditor-/lang/zh_CN.js 添加
jme : '插入公式',
unlink : '取消超级链接',
fullscreen : '全屏显示',
about : '关于',
jme : '插入公式',
以上步骤完成 jmeditor的公式插件已集成到kindeditor里面
10、新建测试页面,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><html xmlns=""><head><base href="<%=basePath%20%>"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>新增试题</title><!-- web编辑器str --><link rel="stylesheet" href="<%=basePath%20%>common/kindeditor-/themes/default/default.css"/><link rel="stylesheet" href="<%=basePath%20%>common/kindeditor-/plugins/code/prettify.css"/><script charset="utf-8" src="<%=basePath%20%>common/kindeditor-/kindeditor.js"></script><script charset="utf-8" src="<%=basePath%20%>common/kindeditor-/lang/zh_CN.js"></script><script charset="utf-8" src="<%=basePath%20%>common/kindeditor-/plugins/code/prettify.js"></script><!-- web编辑器end --><script type="text/javascript">
(function(K) {
var editor1 = ('textarea[name="paperTitle"]', {
cssPath : '<%=basePath%20%>common/kindeditor-/plugins/code/prettify.css',
uploadJson : '<%=basePath%20%>common/kindeditor-/jsp/upload_json.jsp',
fileManagerJson : '<%=basePath%20%>common/kindeditor-/jsp/file_manager_json.jsp',
allowFileManager : true,
autoHeightMode : true,
afterCreate : function() {
var self =this;
(document, 13, function() {
();
['example'].submit();
});
(self.edit.doc, 13, function() {
();
['example'].submit();
});
}
});
prettyPrint();
});
</script></head><body><div class="control-group"><label class="control-label" style="float:left;">
试题题目:
</label><textarea id="paperTitle" name="paperTitle" cols="100" rows="5" style="width:750px;height:260px;visibility:hidden;float:left;">${}</textarea><div class="clear"></div></div></body></html>
so 我们已经完成所有步骤。




