BigW Consortium Gitlab

dom_helper.js 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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;
  const position = el.dataset.position;
  const positionObject = Object.assign({}, JSON.parse(position), {
    x,
    y,
    width,
    height,
  });

  el.setAttribute('data-position', JSON.stringify(positionObject));
}

export function updateDiscussionAvatarBadgeNumber(discussionEl, newBadgeNumber) {
  const avatarBadgeEl = discussionEl.querySelector('.image-diff-avatar-link .badge');
  avatarBadgeEl.innerText = newBadgeNumber;
}

export function updateDiscussionBadgeNumber(discussionEl, newBadgeNumber) {
  const discussionBadgeEl = discussionEl.querySelector('.badge');
  discussionBadgeEl.innerText = newBadgeNumber;
}

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';
  }
}