debian-mirror-gitlab/app/assets/javascripts/image_diff/helpers/badge_helper.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import { spriteIcon } from '~/lib/utils/common_utils';
2018-03-17 18:26:18 +05:30
export function createImageBadge(noteId, { x, y }, classNames = []) {
const buttonEl = document.createElement('button');
const classList = classNames.concat(['js-image-badge']);
2021-03-08 18:12:59 +05:30
classList.forEach((className) => buttonEl.classList.add(className));
2018-03-17 18:26:18 +05:30
buttonEl.setAttribute('type', 'button');
buttonEl.setAttribute('disabled', true);
buttonEl.dataset.noteId = noteId;
buttonEl.style.left = `${x}px`;
buttonEl.style.top = `${y}px`;
return buttonEl;
}
export function addImageBadge(containerEl, { coordinate, badgeText, noteId }) {
2019-02-15 15:39:39 +05:30
const buttonEl = createImageBadge(noteId, coordinate, ['badge', 'badge-pill']);
2020-05-24 23:13:21 +05:30
buttonEl.textContent = badgeText;
2018-03-17 18:26:18 +05:30
containerEl.appendChild(buttonEl);
}
export function addImageCommentBadge(containerEl, { coordinate, noteId }) {
const buttonEl = createImageBadge(noteId, coordinate, ['image-comment-badge']);
2019-12-21 20:55:43 +05:30
buttonEl.innerHTML = spriteIcon('image-comment-dark');
2018-03-17 18:26:18 +05:30
containerEl.appendChild(buttonEl);
}
export function addAvatarBadge(el, event) {
const { noteId, badgeNumber } = event.detail;
// Add badge to new comment
const avatarBadgeEl = el.querySelector(`#${noteId} .badge`);
2020-05-24 23:13:21 +05:30
avatarBadgeEl.textContent = badgeNumber;
2018-03-17 18:26:18 +05:30
avatarBadgeEl.classList.remove('hidden');
}