2017-06-01 86 views
0

我正在使用Froala v2.6.1,並且我想在用戶單擊div時恰好在最後一個插入位置處將編碼字符串插入編輯器,但始終插入字符串在編輯器的最後。Froala編輯器:單擊div時插入插入位置

這裏是我做的事:

<div class="variable" data-value="{{user_id}}">USER ID</div> 

的Jquery:

$('div.variable').click(function() { 
    $("#template_editor").froalaEditor('html.insert', $(this).data('value'), true); 
}); 

任何人都知道如何解決,這將是很大的幫助。

+0

您可以在這個例子中添加自定義按鈕,工具欄froala,如:https://www.froala.com/wysiwyg-editor/examples/insert-html – Slonski

回答

0

看起來你有一個外部按鈕。爲此編輯器有一個內置的機制,突出顯示在demo。在你的情況下,它會是這樣的:

$('#template_editor') 
    .on('froalaEditor.initialized', function (e, editor) { 
    editor.events.bindClick($('body'), 'div.variable', function (ev) { 
     var that = ev.originalEvent && ev.originalEvent.originalTarget; 
     editor.html.insert($(that).data('value')); 
    }); 
    }) 
    .froalaEditor()