-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from maykinmedia/emoji
Emoji
- Loading branch information
Showing
11 changed files
with
130 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,61 @@ | ||
import { EmojiButton } from '@joeattardi/emoji-button' | ||
import emojis from 'emojibase-data/nl/data.json' | ||
|
||
/** @type {NodeList} All the emoji buttons. */ | ||
const EMOJI_BUTTONS = document.querySelectorAll('.emoji-button') | ||
const emojiElements = document.querySelectorAll('.emoji') | ||
|
||
/** | ||
* Allows selecting emojis. | ||
*/ | ||
class EmojiButtonSelector { | ||
/** | ||
* Constructor method. | ||
* @param {HTMLElement} node | ||
*/ | ||
class Emoji { | ||
constructor(node) { | ||
/** @type {HTMLElement} */ | ||
this.node = node | ||
|
||
/** @type {EmojiButton} */ | ||
this.picker = this.getPicker() | ||
|
||
this.bindEvents() | ||
this.content = document.getElementById('id_content') | ||
this.search = node.querySelector('.emoji__search') | ||
this.button = node.querySelector('.emoji__button') | ||
this.popup = node.querySelector('.emoji__popup') | ||
this.container = node.querySelector('.emoji__emojis') | ||
this.close = this.popup.querySelector('.material-icons') | ||
this.populatePopup() | ||
this.addListeners() | ||
} | ||
|
||
/** | ||
* Binds events to callbacks. | ||
*/ | ||
bindEvents() { | ||
this.node.addEventListener('click', () => | ||
this.getPicker().togglePicker(this.node) | ||
) | ||
this.getPicker().on('emoji', this.onEmoji.bind(this)) | ||
addListeners() { | ||
this.button.addEventListener('click', (event) => { | ||
event.preventDefault() | ||
this.popup.classList.toggle('emoji__popup--open') | ||
}) | ||
document.addEventListener('keyup', (event) => { | ||
if (event.key === 'Escape') { | ||
this.popup.classList.remove('emoji__popup--open') | ||
} | ||
}) | ||
this.close.addEventListener('click', (event) => { | ||
this.popup.classList.remove('emoji__popup--open') | ||
}) | ||
this.search.addEventListener('keyup', this.searchEmoji.bind(this)) | ||
} | ||
|
||
/** | ||
* Returns the input to add emoji's to. | ||
* @return {HTMLElement} | ||
*/ | ||
getInput() { | ||
return this.node.parentElement?.parentElement?.querySelector( | ||
'input, textarea' | ||
) | ||
} | ||
|
||
/** | ||
* Returns/instantiates the picker instances. | ||
* @return {EmojiButton} | ||
*/ | ||
getPicker() { | ||
if (!this.picker) { | ||
this.picker = new EmojiButton() | ||
} | ||
|
||
return this.picker | ||
searchEmoji(event) { | ||
const searchValue = event.currentTarget.value.toUpperCase() | ||
document.querySelectorAll('.emoji__emoji-button').forEach((button) => { | ||
const label = button.dataset.label.toUpperCase() | ||
if (label.includes(searchValue)) { | ||
button.classList.remove('emoji__emoji-button--hidden') | ||
} else { | ||
button.classList.add('emoji__emoji-button--hidden') | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Gets called when an emoji is selected. | ||
* @param {Object} selection | ||
*/ | ||
onEmoji(selection) { | ||
const input = this.getInput() | ||
const emoji = selection.emoji | ||
input.value += emoji | ||
populatePopup() { | ||
emojis.forEach((emoji) => { | ||
const emojiButton = document.createElement('div') | ||
emojiButton.classList.add('emoji__emoji-button') | ||
emojiButton.append(emoji.emoji) | ||
emojiButton.title = emoji.label | ||
emojiButton.setAttribute('data-label', emoji.label) | ||
emojiButton.addEventListener('click', (event) => { | ||
this.content.append(emoji.emoji) | ||
}) | ||
this.container.append(emojiButton) | ||
}) | ||
} | ||
} | ||
|
||
// Start1 | ||
;[...EMOJI_BUTTONS].forEach((node) => new EmojiButtonSelector(node)) | ||
;[...emojiElements].forEach((emojiElement) => new Emoji(emojiElement)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.emoji { | ||
&__header { | ||
display: grid; | ||
grid-template-columns: 1fr 25px; | ||
align-items: center; | ||
padding: 8px 0 0 8px; | ||
gap: 8px; | ||
} | ||
|
||
&__search { | ||
// grid-column: 1 / span 8; | ||
min-width: 0; | ||
} | ||
|
||
.material-icons { | ||
cursor: pointer; | ||
} | ||
|
||
&__emoji-button { | ||
cursor: pointer; | ||
|
||
&--hidden { | ||
display: none; | ||
} | ||
} | ||
|
||
&__popup { | ||
display: none; | ||
position: absolute; | ||
background-color: #fff; | ||
border: 1px solid #000; | ||
width: 260px; | ||
|
||
&--open { | ||
display: block; | ||
} | ||
} | ||
|
||
&__emojis { | ||
display: grid; | ||
gap: var(--spacing-medium); | ||
grid-template-columns: repeat(8, 1fr); | ||
padding: var(--spacing-medium); | ||
max-height: 200px; | ||
overflow: auto; | ||
text-align: center; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/open_inwoner/templates/utils/widgets/message_file_input.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<input type="{{ widget.type }}" name="{{ widget.name }}" data-init="{{ widget.value|default:'' }}"{% include "django/forms/widgets/attrs.html" %}> | ||
<label> | ||
<input type="text" name="{{ widget.init_name }}" id="{{ widget.init_id }}" {% if widget.value %} value="{{ widget.value.instance.uuid }}"{% endif %} class="message-file__init" style="display: none"> | ||
<input type="text" name="{{ widget.init_name }}" id="{{ widget.init_id }}" {% if widget.value %} value="{{ widget.value.instance.uuid }}"{% endif %} class="message-file__init"> | ||
</label> | ||
|