2017-05-18 3 views
3

TinyMCEを使用してメールの返信を作成/編集しています。その一環として、Gmailでできるように、途中でEnterキーを押してブロッククォートを解除する機能が必要です。これを可能にするためのTinyMCEの設定はありません。私はそれを逃したことがありますか?または、この機能をプログラムで取得する方法はありますか?TinyMCEで、Gmailのようにenterキーを押してブロック引用を解除してください。

答えて

2

私はTinyMCEの最新バージョンで作業するために、必要なように聞こえるオープンソースのプラグインを調整しました。

ます(詳細はhttps://www.tinymce.com/docs/advanced/creating-a-plugin/を参照)プラグインフォルダにコードをコピーするために、我々が探しているものではありません

デモhttp://fiddle.tinymce.com/7Qfaab/3

/* 
    Original Source: https://github.com/Tauop/tinymce_splitblockquote-plugin/blob/master/tiny_mce/plugins/splitblockquote/editor_plugin_src.js  
    NOTE: Modified by K Scandrett to work with current TinyMCE (~4.6.1) 
*/ 

/* @author Patrick Guiran <[email protected]> 
* @license GNU GENERAL PUBLIC LICENSE, Version 2 
* @copyright Copyright © 2010, Linagora, Patrick Guiran <[email protected]> 
*/ 

tinymce.PluginManager.add('SplitBlockquote', function(ed, url) { 
    ed.on('click', function (e) { 
    var parts, i, node, bq_node, openTags, closeTags, splitToken; 

    if (e.keyCode != 13) { 
     return; /* do nothing */ 
     } 

    // get the top-most blockquote parent node 
    function getMostTopBlockquote(n, r) { 
     var last_bq = null; 
     while (n) { 
     if (n == r) 
      break; 
     if (n.nodeName === 'BLOCKQUOTE') 
      last_bq = n; 
     n = n.parentNode; 
     } 
     return last_bq; 
    }; 



    function getClose(n, r) { 
     // get the htnk "close-tag" of a node 
     function getCloseTag(n) { 
     if (n.nodeName === 'FONT' && ed.settings.convert_fonts_to_spans) { 
      return "</span>"; 
     } else { 
      return "</" + n.nodeName.toLowerCase() + ">"; 
     } 
     } 

     var result = ''; 
     while (n) { 
     if (n == r) 
      break; 
     result += getCloseTag(n); 
     n = n.parentNode; 
     } 
     return result; 
    } 

    function getOpen(n, r) { 
     // get the html "open-tag" of a node 
     function getOpenTag(n) { 
     var attr, copy; 
     copy = n.cloneNode(false); 
     copy.innerHTML = ''; 
     attr = ed.dom.getOuterHTML(copy) 
       .replace(new RegExp('<' + copy.nodeName, "i"), '') 
       .replace(new RegExp('</' + copy.nodeName + '>', "i"), ''); 
     return '<' + copy.nodeName.toLowerCase() + attr; 
     }; 

     var result = ''; 
     while (n) { 
     if (n == r) 
      break; 
     result = getOpenTag(n) + result; 
     n = n.parentNode; 
     } 
     return result; 
    } 

    node = ed.selection.getNode(); 
    bq_node = getMostTopBlockquote(node, ed.getBody()); 
    if (!bq_node) // we aren't in a blockquote 
     return; 

    /* Create an unique splitToken */ 
    splitToken = '_$'+ (new Date()).getTime() + '$_'; 
    ed.selection.setContent(splitToken, {formar: 'raw'}); 
    parts = ed.getContent().split(splitToken); 

    /* blockquote can handle DOM tree. So we have to close 
    * and open DOM element correctly, and not wildly split 
    * the editor content. Plus, openTags has to keep all 
    * attributes to keep makeup of DOM elements, we split. 
    */ 
    openTags = getOpen(node, bq_node); 
    closeTags = getClose(node, bq_node); 

    if (ed.settings.convert_fonts_to_spans && openTags != '') { 
     /* juste convert </span> to </font> 
     * if <font> are converted to <span> 
     * as n.nodeName returns "FONT" for <span> node :/ 
     * @see tinymce.Editor.-_convertFonts() for more information 
     */ 
     (function() { 
     var font_count = (openTags.match(/<font/ig) || []).length; 
     for (i=0; i<font_count; ++i) { 
      start_idx = parts[1].indexOf('</span>'); 
      if (start_idx != -1) { 
      parts[1] = parts[1].substring(0, start_idx) 
        + '</font>' 
        + parts[1].substring(start_idx + 7); 
      } 
     } 
     })(); 
    } 

    /* Update the editor content : 
    * - part[0] : content before the selection, before split 
    * - closeTags : </tag> to close correctly html tags 
    * - </blockquote> : close the blockquote 
    * - <br id='__' /> : <br /> are converted to "<p> </p>". The id 
    *      is used to change the location of the selection (cursor) 
    * - <blockquote> : open the new blockquote 
    * - openTags : re-open splited DOM nodes correctly 
    * - part[1] : content after the selection, before split 
    */ 
    ed.setContent( parts[0] + closeTags 
        + "</blockquote><br id=\"__\"><blockquote>" 
        + openTags + parts[1]); 

    /* delete empty <p>aragraphe at the end of the first blockquote 
    * and at the beginnig at the second blockquote. 
    * Delete id attributes to */ 
    function clean_node(node) { 
     var node_html; 
     if (node == null || node.nodeName != 'P') { 
     return; 
     } 
     node_html = node.innerHTML.trim(); 
     if (node_html == '' || node_html == '<br mce_bogus="1">' || node_html == '<br>') { 
     ed.dom.remove(node); 
     } 
    } 

    bq_node = ed.getBody().getElementsByTagName('blockquote'); 
    for (i = 0; i < bq_node.length; ++i) { 
     if (bq_node[i] == null) { continue; } /* paranoiac mode */ 
     clean_node(bq_node[i].firstChild); 
     clean_node(bq_node[i].lastChild); 
     if (bq_node[i].innerHTML.trim() === '') { 
     ed.dom.remove(bq_node[i]); 
     } 
    } 

    /* get the <br id="__"> element and put cursor on it */ 
    node = ed.dom.get('__'); 
    node.removeAttribute('id'); 
    ed.selection.select(node); 
    ed.selection.collapse(true); 

    /* Don't interpret <ENTER> again, to prevent a new "<p> </p>" to be added */ 
    return tinymce.dom.Event.cancel(e); 
    }); 
}); 
+0

が必要になります。ブロッククォート内のテキストの既存の塊を取る。私たちはそのブロック内に入る能力を必要とし、何回か入力することでそのブロッククォートを2つのブロッククォートに分割します。 –

+0

@MarkFletcher私の回答を更新しました –

+0

これは素晴らしいことです!私は1つの変更を加えなければならなかった。イベントを「クリック」から「キーアップ」に変更する必要がありました。そうでなければ、私にとってはうまくいかないでしょう。 –

関連する問題