Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Emoji Toolbox Plugin #956

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/plugins/emojis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* SCEditor Paragraph Formatting Plugin
* http://www.sceditor.com/
*
* Copyright (C) 2011-2024, Sam Clarke (samclarke.com)
*
* SCEditor is licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* @fileoverview SCEditor Paragraph Formatting Plugin
* @author Sam Clarke
*/

(function(sceditor) {
'use strict';

sceditor.plugins.emojis = function() {
const base = this;

/**
* Function for the exec and txtExec properties
*
* @param {node} caller
* @private
*/
var emojisCmd = function(caller) {
const editor = this,
content = document.createElement('div'),
emojis = editor.opts.emojis || [],
perLine = Math.sqrt(Object.keys(emojis).length);

if (!emojis.length) {
const pickerOptions = { onEmojiSelect: handleSelect };
const picker = new EmojiMart.Picker(pickerOptions);
samclarke marked this conversation as resolved.
Show resolved Hide resolved

content.appendChild(picker);
} else {
var line = document.createElement('div');

sceditor.utils.each(emojis,
function (_, emoji) {
const emojiElem = document.createElement('span');

emojiElem.className = 'sceditor-option';
emojiElem.style = 'cursor:pointer';

emojiElem.appendChild(document.createTextNode(emoji));

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

editor.insert(e.target.innerHTML);

e.preventDefault();
});

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

content.appendChild(line);

line.appendChild(emojiElem);
});
}

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

function handleSelect(emoji) {
editor.insert(emoji.native);

editor.closeDropDown(true);
}
};

base.init = function () {
this.commands.emojis = {
exec: emojisCmd,
txtExec: emojisCmd,
tooltip: 'Insert emoji',
shortcut: 'Ctrl+E'
};
};
};
})(sceditor);
1 change: 1 addition & 0 deletions src/themes/icons/famfamfam.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ div.sceditor-grip, .sceditor-button div {
.sceditor-button-format div { background-position: 0px -448px; }
.sceditor-button-font div { background-position: 0px -464px; }
.sceditor-button-emoticon div { background-position: 0px -480px; }
.sceditor-button-emojis div { background-position: 0px -660px; }
.sceditor-button-email div { background-position: 0px -496px; }
.sceditor-button-date div { background-position: 0px -512px; }
.sceditor-button-cut div { background-position: 0px -528px; }
Expand Down
Binary file modified src/themes/icons/famfamfam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/themes/inc/defaultbase.less
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ div.sceditor-dropdown div {
cursor: pointer;
margin: 2px;
}

.sceditor-emojis span {
padding: 0;
cursor: pointer;
margin: 2px;
}

.sceditor-emojis > div > div:not(:last-child) {
margin-bottom: 6px;
}

.sceditor-more {
border-top: 1px solid #bbb;
Expand Down
Loading