debian-mirror-gitlab/app/assets/javascripts/milestone.js

69 lines
2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import axios from './lib/utils/axios_utils';
import flash from './flash';
2018-10-15 14:42:47 +05:30
import { mouseenter, debouncedMouseleave, togglePopover } from './shared/popover';
2018-03-17 18:26:18 +05:30
export default class Milestone {
constructor() {
this.bindTabsSwitching();
// Load merge request tab if it is active
// merge request tab is active based on different conditions in the backend
this.loadTab($('.js-milestone-tabs .active a'));
this.loadInitialTab();
}
bindTabsSwitching() {
return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
const $target = $(e.target);
location.hash = $target.attr('href');
this.loadTab($target);
});
}
// eslint-disable-next-line class-methods-use-this
loadInitialTab() {
const $target = $(`.js-milestone-tabs a[href="${location.hash}"]`);
if ($target.length) {
$target.tab('show');
2016-09-13 17:45:13 +05:30
}
2018-03-17 18:26:18 +05:30
}
// eslint-disable-next-line class-methods-use-this
loadTab($target) {
const endpoint = $target.data('endpoint');
const tabElId = $target.attr('href');
if (endpoint && !$target.hasClass('is-loaded')) {
axios.get(endpoint)
.then(({ data }) => {
2017-08-17 22:00:37 +05:30
$(tabElId).html(data.html);
$target.addClass('is-loaded');
2018-03-17 18:26:18 +05:30
})
.catch(() => flash('Error loading milestone tab'));
}
}
2018-10-15 14:42:47 +05:30
static initDeprecationMessage() {
const deprecationMesssageContainer = document.querySelector('.js-milestone-deprecation-message');
if (!deprecationMesssageContainer) return;
const deprecationMessage = deprecationMesssageContainer.querySelector('.js-milestone-deprecation-message-template').innerHTML;
const $popover = $('.js-popover-link', deprecationMesssageContainer);
const hideOnScroll = togglePopover.bind($popover, false);
$popover.popover({
content: deprecationMessage,
html: true,
placement: 'bottom',
})
.on('mouseenter', mouseenter)
.on('mouseleave', debouncedMouseleave())
.on('show.bs.popover', () => {
window.addEventListener('scroll', hideOnScroll, { once: true });
});
}
2018-03-17 18:26:18 +05:30
}