Froala编辑器:单击div时插入插入符位置 [英] Froala editor: insert into caret position when clicking a div

查看:117
本文介绍了Froala编辑器:单击div时插入插入符位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Froala v2.6.1,我想在用户单击div时将字符串恰好在插入符的最后一个位置插入到编辑器中,但是该字符串始终插入编辑器的末尾.

I'm using Froala v2.6.1 and I want to insert a string into the editor exactly at the last caret position when user click a divs, but the string is always inserted at the end of the editor.

这是我做的事情:

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

jQuery:

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

任何人都知道如何解决这个问题会很有帮助.

Anyone know how to solve this would be great help.

推荐答案

看起来您那里有一个外部按钮.为此,编辑器具有内置机制,在演示

It looks you have an external button there. For that the editor has a built-in mechanism, highlighted in a demo. In your case it would be something like this:

$('#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()

这篇关于Froala编辑器:单击div时插入插入符位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆