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

46 lines
1.4 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 }) {
2022-04-04 11:22:00 +05:30
const buttonEl = createImageBadge(noteId, coordinate, [
'gl-display-flex',
'gl-align-items-center',
'gl-justify-content-center',
'gl-font-sm',
'design-note-pin',
'on-image',
'gl-absolute',
]);
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;
2022-04-04 11:22:00 +05:30
// Add design pin to new comment
const avatarBadgeEl = el.querySelector(`#${noteId} .design-note-pin`);
2020-05-24 23:13:21 +05:30
avatarBadgeEl.textContent = badgeNumber;
2018-03-17 18:26:18 +05:30
avatarBadgeEl.classList.remove('hidden');
}