Reputation: 679
I'm attempting to use summernote to allow users to edit email templates. I want to give them the ability to insert template/token items for example {{name}}. Ideally i'd like it to hi light this stuff to show them where they have their templates when editing said template.
Code Example:
$('summernote').summernote({
height: 225,
callbacks: {
onBlur: function(contents, $editable) {
var rx = /{([^}]+)}/;
var instance = new Mark("div.panel-body");
var regex = new RegExp(rx, 'g');
instance.markRegExp(regex);
},
},
hint: {
mentions: ['name', 'test'],
match: /\B{{(\w*)$/,
search: function (keyword, callback) {
callback($.grep(this.mentions, function (item) {
return item.indexOf(keyword) == 0;
}));
},
content: function (item) {
return '{{' + item + '}}';
}
}
});
In thinking about this implementation writing a plugin for summernote based off of something like this: https://github.com/Nanakii/summernote-plugins/blob/master/plugin/template/summernote-ext-template.js and then a function to strip out the special tags upon save seems like my best bet, however if someone has done this, or this already exists i'd rather not reinvent the wheel.
tldr
Upvotes: 0
Views: 910
Reputation: 31
You could interrupt the form submission if you have summernote initialised using a textarea
inside a form. Do the necessary changes via javascript, then programatically submit the form.
I do a similar process with my summernote-save-button plugin (https://github.com/DiemenDesign/summernote-save-button).
This currently checks if the content has been saved if the user attempts to navigate away from the current page to remind them to save. I have another version within my CMS that encodes the textarea data before submitting the form to get around some server admins having strict data filtering for stuff like iframes for uses that want to embed youtube videos using iframes.
BTW, I'm also one of the newer devs on the project, and I'm happy to help with your issues.
Upvotes: 0