editor:init
event that we trigger, as that receives both the Froala object as well as XF's editor object as arguments. data-froala.editor
.edObj.edit.off()
.Thanks a lot for this, butThis should work:
JavaScript:$('.js-editor').on('editor:init', function(e, editor) { editor.html.insert(mystring, true); });
<script>
function testinsert(){
$('.js-editor').on('editor:init', function(e, editor)
{
editor.html.insert("mystring", true);
});
}
</script>
<div class="button" onclick="testinsert();">
<span class="button-text">Insert stuff</span>
</div>
Thanks again, and sorry in advance, but this is throwing this error in the console :Try this instead:
JavaScript:var froala; $('.js-editor').on('editor:init', function(e, editor) { froala = editor; }); function testinsert() { froala.html.insert("mystring", true); }
Uncaught TypeError: Cannot read properties of undefined (reading 'html')
at testinsert ((index):1421:14)
at HTMLDivElement.onclick (VM4957 :1424:54)
function testinsert()
{
$(".js-editor")[0]["data-froala.editor"].html.insert('This should work fine');
}
!function($, window, document, _undefined)
{
XF.CustomEditorFunction = XF.Element.newHandler({
options: {
string: ''
},
froala: null,
init: function()
{
var t = this;
$('.js-editor').on('editor:init', function(e, editor)
{
t.froala = editor;
});
this.$target.on('click', $.proxy(this, 'insert'))
},
insert: function(e)
{
this.froala.html.insert(this.options.string, true);
}
});
XF.Element.register('custom-editor-function', 'XF.CustomEditorFunction');
}
(jQuery, window, document);
<button data-xf-init="custom-editor-function" data-string="test">Click me!</button>
Uncaught ReferenceError: jQuery is not defined
at (index):1442:2
(jQuery, window, document);
Not the best place but try this instead:I'm trying those script at the bottom of the "editor" template, inside <script> tags.
<xf:js>
js here without <script> tag.
</xf:js>
This place was just choosen to run the testing, this was suppose to be the resting place of the button only.Not the best place but try this instead:
Code:<xf:js> js here without <script> tag. </xf:js>
If the code works, location doesn't meter. I have tested the code and works well for me, inserting the string at caret position. I'm using Chrome on Ubuntu.I can try running the script from somewhere else if you think it would be better
We use essential cookies to make this site work, and optional cookies to enhance your experience.