濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > ckeditor自定義插件使用方法詳解

ckeditor自定義插件使用方法詳解

熱門標(biāo)簽:智能電銷機(jī)器人真的好嗎 靈聲智能電話機(jī)器人招聘 企業(yè)電話機(jī)器人辦理 四平電話機(jī)器人哪家好 天津電銷卡外呼系統(tǒng)線路 興化400電話辦理多少錢 長(zhǎng)春銷售外呼系統(tǒng)業(yè)務(wù) 株洲外呼營(yíng)銷系統(tǒng)有哪些 長(zhǎng)春防封卡電銷卡套餐

ckeditor是一款功能很強(qiáng)大的富文本編輯的工具,給我們提供了絕大多數(shù)功能,滿足我們?nèi)粘i_(kāi)發(fā)所用,但由于特殊情況,可能會(huì)需要修改ckeditor的插件。ckeditor提供了給我們很方便擴(kuò)展插件的接口。

最經(jīng)由于項(xiàng)目的需要,需要重寫ckeditor的上傳圖片的功能,以下是自定義圖片上傳功能的部分代碼:

1、在ckeditor/plugins/目錄下新建editorupload目錄,用來(lái)存放自定義插件;在該目錄下新建目錄images用來(lái)存放自定以圖片,在images目錄下放入插件圖片image.png.

2、在editorupload目錄下新建plugin.js:

(function () {
  var a = {
      exec: function (editor) {
        //調(diào)用jsp中的函數(shù)彈出上傳框,
        var url = '../view/fileupload/upload.jsp';
        openDialog({  //openDialog打開(kāi)一個(gè)新窗口
          title: '插入圖片',
          url: url,
          height: 600,
          width: 900,
          callback:function(){

          }
        });

      }
    },
    b = 'editorupload';


  CKEDITOR.plugins.add('editorupload', {
    init: function (editor) {
      editor.addCommand(b, a);
      editor.ui.addButton('editorupload', {
        label: '添加圖片', //鼠標(biāo)懸停在插件上時(shí)顯示的名字
        icon: 'plugins/editorupload/images/image.png',  //自定義圖標(biāo)的路徑
        command: b
      });
    }
  });
})();

在上面代碼中,新建了一個(gè)upload.jsp頁(yè)面用來(lái)上傳圖片,使用了openDialog彈出一個(gè)新的窗口,設(shè)置了彈出框的高度和寬度。
CKEDITOR.plugins.add將自定義的editorupload加入到ckeditor中。

下面是部分upload.jsp頁(yè)面代碼:

div id="mainContent">
  /div>
  div class=" box">
    table class=" m-table">
      colgroup>
        col width="20%"/>
        col width="80%"/>
      /colgroup>
      tr>
        td style="vertical-align:top;">label class="module-name">圖片說(shuō)明/label>/td>
        td>
          ul>
            li>1、《PC首頁(yè)輪播圖片》長(zhǎng)寬為666×250顯示效果最好;《APP首頁(yè)輪播圖片》長(zhǎng)寬為422×262顯示效果最好;/li>
            li>3、圖片提交才會(huì)在首頁(yè)生效;/li>
          /ul>
        /td>
      /tr>
    /table>
  /div>

  div id="Pictures" class="detailWraper nopadding" style="display: none;height: auto;">
    input id="hidPicturesStatus" type="hidden" value="0"/>
    input id="hidCurrPictures" type="hidden" value=''/>
    input id="hidDictSuggestion" type="hidden" value=''/>
    table>
      tr>
        td>
          div id="fileQueue">/div>
          div id="picWrapper">/div>
          a id="fake-dlg-bigPic" href="javascript:void(0)" style="display: none;">/a>
          div id="dlg-bigPic" class="popImg" style="display: none;">
            a class="leftBtn" href="javascript:void(0)">/a>
            a class="rightBtn" href="javascript:void(0)">/a>
            a class="closeImgBtn" href="javascript:void(0)">/a>
            div class="imgList">
              ul>/ul>
            /div>
          /div>
          div class="validation-summary-valid">
            ul>
              li style="display: none">/li>
            /ul>
          /div>

        /td>
      /tr>
    /table>
  /div>
  div>
    button id="fileUpload">批量上傳/button>
    button id="submit" class="btn btn-primary" style="vertical-align: top;line-height:23px;width:112px;height: 35px;">提交照片
    /button>
  /div>
/div>

upload.jps頁(yè)面部分的js代碼:

//提交照片
    photoTaskDetail.submit = function () {
      var pictures = window.picManager._getPictures();
      if (pictures.length  1) {
        alert('請(qǐng)至少上傳1張圖片');
        return false;
      }
      for (var i in pictures) {
        var imgPath = "img src='" + staticFileRoot + pictures[i].URL + "'/>";
        var element = window.parent.CKEDITOR.dom.element.createFromHtml(imgPath);
        window.parent.CKEDITOR.instances.editorContent.insertElement(element);
      }
      parent.closeDialog(false);
    }

上面代碼中,可以上傳多張照片,分別將照片放入到ckeditor中。
配置ckeditor的config.js:

config.extraPlugins += (config.extraPlugins ? ',editorupload' : 'editorupload');
CKEDITOR.editorConfig = function( config ) {
  config.font_names= '宋體/宋體;黑體/黑體;仿宋/仿宋_GB2312;楷體/楷體_GB2312;隸書/隸書;幼圓/幼圓;微軟雅黑/微軟雅黑;'+ config.font_names;
  config.language = 'zh-cn';
  config.extraPlugins += (config.extraPlugins ? ',lineheight' : 'lineheight');
  config.extraPlugins += (config.extraPlugins ? ',editorupload' : 'editorupload');
  CKEDITOR.config.lineheight_sizes = CKEDITOR.config.lineheight_sizes +  '30px'; 
  config.height = 650;
  config.toolbarCanCollapse = true;
  config.uiColor = '#90B8E9';
  config.toolbar = 'Full';
  config.toolbar_Full = [
   { name: 'document',  items: [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
   { name: 'clipboard',  items: [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
   { name: 'links',    items:['Link','Unlink']},
   { name: 'insert',   items:['HorizontalRule','Table','Image'] },

   '/',
   { name: 'basicstyles', items: [ 'Bold','Underline','Strike','Subscript','Superscript','-','RemoveFormat'] },
   { name: 'paragraph',  items: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
   { name: 'styles',items: ['lineheight','Format','Font','FontSize']},
   { name: 'colors',items: ['TextColor', 'BGColor']},
   { name: 'tools', items : [ 'Maximize','editorupload'] }
];

將editorupload插件加入到ckeditor中。
以下是實(shí)現(xiàn)的部分截圖:

實(shí)現(xiàn)總結(jié):在自定義插件過(guò)程中,必須把原插件的圖片插入的功能給打開(kāi),負(fù)責(zé)上傳的圖片不會(huì)被放入到ckeditor中,圖片地址會(huì)被自動(dòng)的過(guò)濾掉。這可能是ckeditor版本的bug導(dǎo)致。有解決方案的歡迎指導(dǎo)。

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

您可能感興趣的文章:
  • CKEditor擴(kuò)展插件:自動(dòng)排版功能autoformat插件實(shí)現(xiàn)方法詳解
  • FCKeditor 插件開(kāi)發(fā) 示例(詳細(xì)版本)
  • CKEditor 附插入代碼的插件
  • 添加FCKeditor插件需要注意的地方
  • ckeditor插件開(kāi)發(fā)簡(jiǎn)單實(shí)例
  • fckeditor 插件實(shí)例 制作步驟
  • autogrow 讓FCKeditor高度隨內(nèi)容增加的插件
  • CKEditor中加入syntaxhighlighter代碼高亮插件
  • FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
  • ckeditor一鍵排版功能實(shí)現(xiàn)方法分析

標(biāo)簽:漯河 青海 貴港 巴彥淖爾 石嘴山 新疆 運(yùn)城 黑龍江

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ckeditor自定義插件使用方法詳解》,本文關(guān)鍵詞  ckeditor,自定義,插件,使用方法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ckeditor自定義插件使用方法詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ckeditor自定義插件使用方法詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    阿拉尔市| 锡林浩特市| 宁晋县| 子长县| 苏尼特右旗| 京山县| 金华市| 营口市| 陇南市| 新龙县| 镇雄县| 竹溪县| 常山县| 中宁县| 饶阳县| 宜兴市| 常德市| 长葛市| 织金县| 龙胜| 海伦市| 兴仁县| 沙坪坝区| 湘潭县| 漳浦县| 昂仁县| 宝清县| 武平县| 深水埗区| 靖州| 桂林市| 涪陵区| 衢州市| 精河县| 庆云县| 淳安县| 工布江达县| 壤塘县| 和硕县| 青浦区| 金寨县|