欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CKEditor自定義按鈕插入服務(wù)端圖片

 更新時(shí)間:2017年06月21日 09:08:30   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了CKEditor自定義按鈕插入服務(wù)端圖片的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

CKEditor 富文本編輯器很好用,功能很強(qiáng)大,在加上支持服務(wù)端圖片上傳的CKFinder更是方便,

最近在使用CKFinder的時(shí)候發(fā)現(xiàn)存在很多問題,比如上傳圖片的時(shí)候,圖片不能按時(shí)間降序排列,另外CKFinder是也是收費(fèi)的,所以自己想實(shí)現(xiàn)一個(gè)簡單的類似CKFinder的功能,

本節(jié)只講在CKEditor實(shí)現(xiàn)服務(wù)器圖片的插入插件實(shí)現(xiàn)方法。

CKEditor版本是 ## CKEditor 4.4.4

第一、定義插件

1.在ckeditor\plugins文件夾下,新建serverimg文件夾,

2.在serverimg下新建plugin.js 文件,

CKEDITOR.plugins.add(
 "serverimg",
 {
 requires: ["dialog"],
 lang: ["en"],
 init: function (editor) {
 editor.addCommand("serverimg", new CKEDITOR.dialogCommand("serverimg"));
 editor.ui.addButton(
 "serverimg",
 {
 label: "插入服務(wù)端圖片",
 command: "serverimg",
 icon: this.path + "images/pic.png",
 toolbar: 'insert'
 });
 CKEDITOR.dialog.add("serverimg", this.path + "dialogs/code.js");
 }
 }
);

3.在serverimg下新建image,里面存放圖標(biāo)使用的圖片pic.png 

第二、定義插件中的對(duì)話框內(nèi)容

1.在serverimg中新建dialogs文件夾,

2.在dialogs文件內(nèi),分別創(chuàng)建code.js (用于執(zhí)行彈出對(duì)話框執(zhí)行的js代碼)和PicPreview.html(用于瀏覽服務(wù)器圖片)

3.code.js 代碼如下

CKEDITOR.dialog.add(
 "serverimg",
 function (editor) {
 var timestamp = Math.round(new Date().getTime() / 1000);
 var ckeditorPage = '../../ImgMgr/ImgBrowser.aspx?from=ckeditor&timestamp=' + timestamp;
 return {
 title: "插入代碼",
 minWidth: 800,
 minHeight: 600,
 contents:
 [
 {
  id: "tab1",
  label: "",
  title: "",
  expand: true,
  padding: 0,
  elements:
  [
  {
  type: "html",
  html: "<iframe id='img_browser'name='img_browser' src='" + ckeditorPage + "'></iframe>",
  style: "width:100%;height:600px;padding:0;"http:// style='width:800px;height:600px'
  }
  ]
 }
 ],
 onOk: function () { 
 
 //插入富文本編輯器內(nèi)容 window.frames["img_browser"].document.getElementById("hf_imgsrc");//
 var hf = document.getElementById('img_browser').contentWindow.document.getElementById("hf_imgsrc");
 if (hf != null) {
  var imgSrc = hf.value;  
  editor.insertHtml("<img src='" + imgSrc + "' />"); //將select插入編輯器
 
 } else {
  alert("hf is null");
 }
 
 },
 //onHide: function () { document.getElementById('img_browser').contentDocument.location.reload(); },
 //resizable: CKEDITOR.DIALOG_RESIZE_HEIGHT
 };
 }
);

4.說明,由于我在彈出的對(duì)話框中插入的是一個(gè)iframe,src正好是我自己做的一個(gè)瀏覽服務(wù)器圖片的頁面,當(dāng)選中圖片后,點(diǎn)擊對(duì)話框中的確定按鈕,即可獲取圖片路徑,

最終包裝成img ,插入到富文本編輯器里面 ,當(dāng)然你可以做的更好,允許圖片設(shè)置寬度和高度,這里就不在講了。 

第三、配置插件

    上面的插件開發(fā)完成后,頁面上并不會(huì)顯示我們開發(fā)的插件,還需要配置下config.js,找到ckeditor文件下的config.js 打開,在配置里面增加config.extraPlugins = 'serverimg';

第四、最終效果

 以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論