織夢(mèng)kindeditor文本編輯器增加“查找替換”功能效果演示
1、items 里面增加 search 按鈕
['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','baidumap','pagebreak','anchor','link','unlink','|','about','search']
2、增加語(yǔ)言 和 執(zhí)行函數(shù)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <script type="text/javascript"> // 自定義插件 查找與替換 KindEditor.lang({ search: '查找與替換' }); KindEditor.ready(function(K) { editor1 = K.create('textarea[name="{$fname}"]', { cssPath : '{$GLOBALS['cfg_cmspath']}/include/kindeditor/plugins/code/prettify.css', uploadJson : '$uploadJson', fileManagerJson : '$fileManagerJson', extraFileUploadParams: { PHPSESSID : '{$session_id}' }, $extendconfig $itemconfig allowFileManager : {$allowFileManager}, afterBlur: function(){this.sync();} }); prettyPrint(); }); //點(diǎn)擊“確定”按鈕所執(zhí)行的事情www.dedecms51.com網(wǎng) function FindReplace() { var findVal = document.getElementById("txtFind").value; var replaceVal = document.getElementById("txtReplace").value; if (findVal.length == 0) { alert("查找內(nèi)容不能夠?yàn)榭?"); return false; } var editorHtml = editor1.html(); //利用正則表達(dá)式,實(shí)現(xiàn)對(duì)編輯器內(nèi)文本進(jìn)行全文掃描并替換 editorHtml = editorHtml.replace(new RegExp(findVal, "gi"), replaceVal); //重新加載編輯器內(nèi)值 editor1.html(editorHtml); } </script> |
3、增加按鈕點(diǎn)擊后出來(lái)小窗口
kindeditor\plugins 文件夾下新建 search 文件夾,里面再建立個(gè)search.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // 自定義插件 查找與替換 KindEditor.plugin('search', function (K) { var self = this, name = 'search'; self.clickToolbar(name, function () { menu = self.createMenu({ name: name }); var wrapperDiv = "<div style='width:250px; height:140px;background:#ffffff;'>" + "<br><b style='padding-left:10px;padding-top:20px;'>查找與替換</b>" + "<div style='padding-left:10px;padding-top:10px;'>查找:<input type='text' id='txtFind'/></div>" + "<div style='padding-left:10px;padding-top:10px;'>替換:<input type='text' id='txtReplace'/></div>" + "<div style='text-align:right;padding-right:5px;padding-top:10px;'><input type='button' value='確定' onclick='FindReplace()'/></div>" + "</div>"; menu.div.append(wrapperDiv); }); }); |
完成
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)kindeditor文本編輯器增加“查找替換”功能