diff options
Diffstat (limited to 'app/assets/javascripts/projects/star.js')
-rw-r--r-- | app/assets/javascripts/projects/star.js | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/app/assets/javascripts/projects/star.js b/app/assets/javascripts/projects/star.js index 578e22ca25d..5bbace11b15 100644 --- a/app/assets/javascripts/projects/star.js +++ b/app/assets/javascripts/projects/star.js @@ -1,31 +1,33 @@ -import $ from 'jquery'; import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import { spriteIcon } from '~/lib/utils/common_utils'; import { __, s__ } from '~/locale'; export default class Star { - constructor(container = '.project-home-panel') { - $(`${container} .toggle-star`).on('click', function toggleStarClickCallback() { - const $this = $(this); - const $starSpan = $this.find('span'); - const $starIcon = $this.find('svg'); - const iconClasses = $starIcon.attr('class').split(' '); + constructor(containerSelector = '.project-home-panel') { + const container = document.querySelector(containerSelector); + const starToggle = container.querySelector('.toggle-star'); + starToggle.addEventListener('click', function toggleStarClickCallback() { + const starSpan = starToggle.querySelector('span'); + const starIcon = starToggle.querySelector('svg'); + const iconClasses = Array.from(starIcon.classList.values()); axios - .post($this.data('endpoint')) + .post(starToggle.dataset.endpoint) .then(({ data }) => { - const isStarred = $starSpan.hasClass('starred'); - $this.parent().find('.count').text(data.star_count); + const isStarred = starSpan.classList.contains('starred'); + starToggle.parentNode.querySelector('.count').textContent = data.star_count; if (isStarred) { - $starSpan.removeClass('starred').text(s__('StarProject|Star')); - $starIcon.remove(); - $this.prepend(spriteIcon('star-o', iconClasses)); + starSpan.classList.remove('starred'); + starSpan.textContent = s__('StarProject|Star'); + starIcon.remove(); + starSpan.insertAdjacentHTML('beforebegin', spriteIcon('star-o', iconClasses)); } else { - $starSpan.addClass('starred').text(__('Unstar')); - $starIcon.remove(); - $this.prepend(spriteIcon('star', iconClasses)); + starSpan.classList.add('starred'); + starSpan.textContent = __('Unstar'); + starIcon.remove(); + starSpan.insertAdjacentHTML('beforebegin', spriteIcon('star', iconClasses)); } }) .catch(() => |