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

41 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
export function setPositionDataAttribute(el, options) {
// Update position data attribute so that the
// new comment form can use this data for ajax request
const { x, y, width, height } = options;
2018-11-08 19:23:39 +05:30
const { position } = el.dataset;
2020-05-24 23:13:21 +05:30
const positionObject = { ...JSON.parse(position), x, y, width, height };
2018-03-17 18:26:18 +05:30
el.setAttribute('data-position', JSON.stringify(positionObject));
}
export function updateDiscussionAvatarBadgeNumber(discussionEl, newBadgeNumber) {
const avatarBadgeEl = discussionEl.querySelector('.image-diff-avatar-link .badge');
2020-05-24 23:13:21 +05:30
avatarBadgeEl.textContent = newBadgeNumber;
2018-03-17 18:26:18 +05:30
}
export function updateDiscussionBadgeNumber(discussionEl, newBadgeNumber) {
const discussionBadgeEl = discussionEl.querySelector('.badge');
2020-05-24 23:13:21 +05:30
discussionBadgeEl.textContent = newBadgeNumber;
2018-03-17 18:26:18 +05:30
}
export function toggleCollapsed(event) {
const toggleButtonEl = event.currentTarget;
const discussionNotesEl = toggleButtonEl.closest('.discussion-notes');
const formEl = discussionNotesEl.querySelector('.discussion-form');
const isCollapsed = discussionNotesEl.classList.contains('collapsed');
if (isCollapsed) {
discussionNotesEl.classList.remove('collapsed');
} else {
discussionNotesEl.classList.add('collapsed');
}
// Override the inline display style set in notes.js
if (formEl && !isCollapsed) {
formEl.style.display = 'none';
} else if (formEl && isCollapsed) {
formEl.style.display = 'block';
}
}