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

59 lines
1.7 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 addCommentIndicator(containerEl, { x, y }) {
const buttonEl = document.createElement('button');
buttonEl.classList.add('btn-transparent');
buttonEl.classList.add('comment-indicator');
buttonEl.setAttribute('type', 'button');
buttonEl.style.left = `${x}px`;
buttonEl.style.top = `${y}px`;
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 removeCommentIndicator(imageFrameEl) {
const commentIndicatorEl = imageFrameEl.querySelector('.comment-indicator');
const imageEl = imageFrameEl.querySelector('img');
2019-09-04 21:01:54 +05:30
const willRemove = Boolean(commentIndicatorEl);
2018-03-17 18:26:18 +05:30
let meta = {};
if (willRemove) {
meta = {
x: parseInt(commentIndicatorEl.style.left, 10),
y: parseInt(commentIndicatorEl.style.top, 10),
image: {
width: imageEl.width,
height: imageEl.height,
},
};
commentIndicatorEl.remove();
}
2020-05-24 23:13:21 +05:30
return { ...meta, removed: willRemove };
2018-03-17 18:26:18 +05:30
}
export function showCommentIndicator(imageFrameEl, coordinate) {
const { x, y } = coordinate;
const commentIndicatorEl = imageFrameEl.querySelector('.comment-indicator');
if (commentIndicatorEl) {
commentIndicatorEl.style.left = `${x}px`;
commentIndicatorEl.style.top = `${y}px`;
} else {
addCommentIndicator(imageFrameEl, coordinate);
}
}
export function commentIndicatorOnClick(event) {
// Prevent from triggering onAddImageDiffNote in notes.js
event.stopPropagation();
const buttonEl = event.currentTarget;
const diffViewerEl = buttonEl.closest('.diff-viewer');
const textareaEl = diffViewerEl.querySelector('.note-container .note-textarea');
textareaEl.focus();
}