有一个文本编辑功能用到了xheditor,产品要求加上查找与替换的功能。目前所做的就是简单的替换,主要是单步查找时如高亮显示,不知道如何解决。
var beforeEditorData = null;
$(document).ready(function(){
var plugins = {
searchReplace:{c:'xheIcon xheBtnCut',t:'查找替换',s:'ctrl+9',h:1,e:function(){
var _this=this;
var jTest=$('<div>查找替换</div><div style="text-align:left;">查找:<input type="text" id="bText" /><br/>替换:<input type="text" id="aText" /><input type="button" id="xheSave" value="确定" /></div>');
var jSave=$('#xheSave',jTest);
_this.showDialog(jTest);
jSave.click(function(){
var dataBefore = $('#bText',jTest).val();
var dataAfter = $('#aText',jTest).val();
if(dataBefore.length > 0 && dataAfter.length > 0){
beforeEditorData = _this.getSource();
var data = _this.getSource();
dataBefore = dataBefore.replace("?", "\\?");
data = data.replace(new RegExp(dataBefore,"gm"), dataAfter);
_this.setSource(data);
}
_this.hidePanel();
return false;
});
}}
}
var editors = $("#contentInfo").xheditor({
plugins: plugins,
tools:'full',
skin:'default',
html5Upload:false,
upMultiple:false,
wordDeepClean:false,
upImgUrl: "/upload/upload.action?_charset_=utf-8",
upImgExt: "jpg,jpeg,gif,bmp,png"
});
$('#btnTest2').click(function(){editors.exec('searchReplace');});