Commit 45734995 authored by Scott Hampton's avatar Scott Hampton

Merge branch 'jnnkl-remove-eventlistener-profiles-show' into 'master'

Remove obsolete DOMContentLoadedEventListener

See merge request gitlab-org/gitlab!56684
parents 4464c511 cf798a30
...@@ -7,46 +7,44 @@ import { __ } from '~/locale'; ...@@ -7,46 +7,44 @@ import { __ } from '~/locale';
import EmojiMenu from './emoji_menu'; import EmojiMenu from './emoji_menu';
const defaultStatusEmoji = 'speech_balloon'; const defaultStatusEmoji = 'speech_balloon';
const toggleEmojiMenuButtonSelector = '.js-toggle-emoji-menu';
const toggleEmojiMenuButton = document.querySelector(toggleEmojiMenuButtonSelector);
const statusEmojiField = document.getElementById('js-status-emoji-field');
const statusMessageField = document.getElementById('js-status-message-field');
document.addEventListener('DOMContentLoaded', () => { const toggleNoEmojiPlaceholder = (isVisible) => {
const toggleEmojiMenuButtonSelector = '.js-toggle-emoji-menu';
const toggleEmojiMenuButton = document.querySelector(toggleEmojiMenuButtonSelector);
const statusEmojiField = document.getElementById('js-status-emoji-field');
const statusMessageField = document.getElementById('js-status-message-field');
const toggleNoEmojiPlaceholder = (isVisible) => {
const placeholderElement = document.getElementById('js-no-emoji-placeholder'); const placeholderElement = document.getElementById('js-no-emoji-placeholder');
placeholderElement.classList.toggle('hidden', !isVisible); placeholderElement.classList.toggle('hidden', !isVisible);
}; };
const findStatusEmoji = () => toggleEmojiMenuButton.querySelector('gl-emoji'); const findStatusEmoji = () => toggleEmojiMenuButton.querySelector('gl-emoji');
const removeStatusEmoji = () => { const removeStatusEmoji = () => {
const statusEmoji = findStatusEmoji(); const statusEmoji = findStatusEmoji();
if (statusEmoji) { if (statusEmoji) {
statusEmoji.remove(); statusEmoji.remove();
} }
}; };
const selectEmojiCallback = (emoji, emojiTag) => { const selectEmojiCallback = (emoji, emojiTag) => {
statusEmojiField.value = emoji; statusEmojiField.value = emoji;
toggleNoEmojiPlaceholder(false); toggleNoEmojiPlaceholder(false);
removeStatusEmoji(); removeStatusEmoji();
toggleEmojiMenuButton.innerHTML += emojiTag; toggleEmojiMenuButton.innerHTML += emojiTag;
}; };
const clearEmojiButton = document.getElementById('js-clear-user-status-button'); const clearEmojiButton = document.getElementById('js-clear-user-status-button');
clearEmojiButton.addEventListener('click', () => { clearEmojiButton.addEventListener('click', () => {
statusEmojiField.value = ''; statusEmojiField.value = '';
statusMessageField.value = ''; statusMessageField.value = '';
removeStatusEmoji(); removeStatusEmoji();
toggleNoEmojiPlaceholder(true); toggleNoEmojiPlaceholder(true);
}); });
const emojiAutocomplete = new GfmAutoComplete(); const emojiAutocomplete = new GfmAutoComplete();
emojiAutocomplete.setup($(statusMessageField), { emojis: true }); emojiAutocomplete.setup($(statusMessageField), { emojis: true });
const userNameInput = document.getElementById('user_name'); const userNameInput = document.getElementById('user_name');
userNameInput.addEventListener('input', () => { userNameInput.addEventListener('input', () => {
const EMOJI_REGEX = emojiRegex(); const EMOJI_REGEX = emojiRegex();
if (EMOJI_REGEX.test(userNameInput.value)) { if (EMOJI_REGEX.test(userNameInput.value)) {
// set field to invalid so it gets detected by GlFieldErrors // set field to invalid so it gets detected by GlFieldErrors
...@@ -54,9 +52,9 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -54,9 +52,9 @@ document.addEventListener('DOMContentLoaded', () => {
} else { } else {
userNameInput.setCustomValidity(''); userNameInput.setCustomValidity('');
} }
}); });
Emoji.initEmojiMap() Emoji.initEmojiMap()
.then(() => { .then(() => {
const emojiMenu = new EmojiMenu( const emojiMenu = new EmojiMenu(
Emoji, Emoji,
...@@ -84,4 +82,3 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -84,4 +82,3 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}) })
.catch(() => createFlash(__('Failed to load emoji list.'))); .catch(() => createFlash(__('Failed to load emoji list.')));
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment