標籤:
1,在plugins下建立檔案夾 multiimg
2,建立檔案plugin.js
(function() { CKEDITOR.plugins.add("multiimg", { requires: ["dialog"], init: function(a) { a.addCommand("multiimg", new CKEDITOR.dialogCommand("multiimg")); a.ui.addButton("multiimg", { label: "批量上傳圖片",//調用dialog時顯示的名稱 command: "multiimg", icon: this.path + "g.ico"//在toolbar中的表徵圖 }); CKEDITOR.dialog.add("multiimg", this.path + "dialogs/multiimg.js") } })})();
3,建立一個g.ico 放在multiimg目錄下
4,建立dialogs檔案夾,建立檔案multiimg
(function() { CKEDITOR.dialog.add("multiimg", function(a) { return { title: "批量上傳圖片", minWidth: "660px", minHeight:"400px", contents: [{ id: "tab1", label: "", title: "", expand: true, width: "420px", height: "300px", padding: 0, elements: [{ type: "html", style: "width:660px;height:400px", html: ‘<iframe id="uploadFrame" src="/image/image.html?v=‘ +new Date().getSeconds() + ‘" frameborder="0"></iframe>‘ }] }], onOk: function() { // 拿到對象,這個在iframe裡定義 var num = window.fff; //點擊確定按鈕後的操作 a.insertHtml("編輯器追加內容"+num); }, onShow: function () { document.getElementById("uploadFrame").setAttribute("src","/image/image.html?v=‘ +new Date().getSeconds() + ‘"); } } })})();
5,做那個上傳頁面,
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 <html> 4 <head> 5 <title></title> 6 7 <script type="text/javascript" src="/res/js/jquery-1.12.1.js"></script> 8 9 10 </head>11 <body>12 13 <img id="imgs">fuck</img>14 15 16 <script type="text/javascript">17 parent.fff =("fsdafsdafsdafsda");
//關鍵,可以在...被調用18 19 var a =$(window.parent.document).find("#title").val("================");20 21 </script>22 </body>23 24 </html>
config.extraPlugins += ‘multiimg‘;
自訂按鈕
config.toolbar = [
[‘Source‘, ‘Cut‘, ‘Copy‘, ‘Paste‘, ‘PasteText‘, ‘PasteFromWord‘, ‘-‘, ‘Undo‘, ‘Redo‘, ‘Bold‘, ‘Italic‘,
"Format","FontSize","TextColor" ,"Link" ,"Unlink","CodeSnippet"]
]
用CKEDITOR 做自助上傳的解決方案2