Skip to content

Commit

Permalink
added optional EmojiMart picker
Browse files Browse the repository at this point in the history
  • Loading branch information
w8tcha committed Mar 21, 2024
1 parent cf52e2c commit 543feb6
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/plugins/emojis.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,52 @@
emojis = editor.opts.emojis || [],
perLine = Math.sqrt(Object.keys(emojis).length);

var line = document.createElement('div');
if (!emojis.length) {
const pickerOptions = { onEmojiSelect: handleSelect };
const picker = new EmojiMart.Picker(pickerOptions);

sceditor.utils.each(emojis,
function (_, emoji) {
const emojiElem = document.createElement('span');
content.appendChild(picker);
} else {
var line = document.createElement('div');

emojiElem.className = 'sceditor-option';
emojiElem.style = 'cursor:pointer';
sceditor.utils.each(emojis,
function (_, emoji) {
const emojiElem = document.createElement('span');

emojiElem.appendChild(document.createTextNode(emoji));
emojiElem.className = 'sceditor-option';
emojiElem.style = 'cursor:pointer';

emojiElem.addEventListener('click',
function (e) {
editor.closeDropDown(true);
emojiElem.appendChild(document.createTextNode(emoji));

editor.insert(e.target.innerHTML);
emojiElem.addEventListener('click',
function (e) {
editor.closeDropDown(true);

e.preventDefault();
});
editor.insert(e.target.innerHTML);

if (line.children.length >= perLine) {
line = document.createElement('div');
}
e.preventDefault();
});

content.appendChild(line);
if (line.children.length >= perLine) {
line = document.createElement('div');
}

line.appendChild(emojiElem);
});
content.appendChild(line);

line.appendChild(emojiElem);
});
}

editor.createDropDown(caller, 'emojis', content);
};

base.init = function () {
const opts = this.opts;
const emojis = opts.emojis;
function handleSelect(emoji) {
editor.insert(emoji.native);

if (!emojis) {
return;
editor.closeDropDown(true);
}
};

base.init = function () {
this.commands.emojis = {
exec: emojisCmd,
txtExec: emojisCmd,
Expand Down

0 comments on commit 543feb6

Please sign in to comment.