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

111 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-12-05 23:21:45 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import { highCountTrim } from '~/lib/utils/text_utility';
2020-04-22 19:07:51 +05:30
import Tracking from '~/tracking';
2021-03-11 19:13:27 +05:30
import Translate from '~/vue_shared/translate';
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
/**
* Updates todo counter when todos are toggled.
* When count is 0, we hide the badge.
*
* @param {jQuery.Event} e
* @param {String} count
*/
export default function initTodoToggle() {
2022-08-13 15:12:31 +05:30
document.addEventListener('todo:toggle', (e) => {
const updatedCount = e.detail.count || 0;
const todoPendingCount = document.querySelector('.js-todos-count');
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
if (todoPendingCount) {
todoPendingCount.textContent = highCountTrim(updatedCount);
if (updatedCount === 0) {
todoPendingCount.classList.add('hidden');
} else {
todoPendingCount.classList.remove('hidden');
}
}
2018-03-17 18:26:18 +05:30
});
}
2018-12-05 23:21:45 +05:30
2019-03-02 22:35:43 +05:30
function initStatusTriggers() {
2018-12-05 23:21:45 +05:30
const setStatusModalTriggerEl = document.querySelector('.js-set-status-modal-trigger');
2020-11-24 15:15:51 +05:30
if (setStatusModalTriggerEl) {
setStatusModalTriggerEl.addEventListener('click', () => {
import(
/* webpackChunkName: 'statusModalBundle' */ './set_status_modal/set_status_modal_wrapper.vue'
)
.then(({ default: SetStatusModalWrapper }) => {
const setStatusModalWrapperEl = document.querySelector('.js-set-status-modal-wrapper');
const statusModalElement = document.createElement('div');
setStatusModalWrapperEl.appendChild(statusModalElement);
2018-12-05 23:21:45 +05:30
2020-11-24 15:15:51 +05:30
Vue.use(Translate);
2018-12-05 23:21:45 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: statusModalElement,
data() {
2021-01-29 00:20:46 +05:30
const {
currentEmoji,
defaultEmoji,
currentMessage,
currentAvailability,
2021-04-29 21:17:54 +05:30
currentClearStatusAfter,
2021-01-29 00:20:46 +05:30
} = setStatusModalWrapperEl.dataset;
2018-12-05 23:21:45 +05:30
2020-11-24 15:15:51 +05:30
return {
currentEmoji,
2021-01-29 00:20:46 +05:30
defaultEmoji,
2020-11-24 15:15:51 +05:30
currentMessage,
2021-01-29 00:20:46 +05:30
currentAvailability,
2021-04-29 21:17:54 +05:30
currentClearStatusAfter,
2020-11-24 15:15:51 +05:30
};
},
render(createElement) {
2021-01-29 00:20:46 +05:30
const {
currentEmoji,
defaultEmoji,
currentMessage,
currentAvailability,
2021-04-29 21:17:54 +05:30
currentClearStatusAfter,
2021-01-29 00:20:46 +05:30
} = this;
2018-12-05 23:21:45 +05:30
2020-11-24 15:15:51 +05:30
return createElement(SetStatusModalWrapper, {
props: {
currentEmoji,
2021-01-29 00:20:46 +05:30
defaultEmoji,
2020-11-24 15:15:51 +05:30
currentMessage,
2021-01-29 00:20:46 +05:30
currentAvailability,
2021-04-29 21:17:54 +05:30
currentClearStatusAfter,
2020-11-24 15:15:51 +05:30
},
});
},
});
})
.catch(() => {});
2018-12-05 23:21:45 +05:30
});
}
2019-03-02 22:35:43 +05:30
}
2020-05-24 23:13:21 +05:30
function trackShowUserDropdownLink(trackEvent, elToTrack, el) {
const { trackLabel, trackProperty } = elToTrack.dataset;
2022-08-13 15:12:31 +05:30
el.addEventListener('shown.bs.dropdown', () => {
2020-05-24 23:13:21 +05:30
Tracking.event(document.body.dataset.page, trackEvent, {
label: trackLabel,
property: trackProperty,
});
});
}
2020-04-22 19:07:51 +05:30
export function initNavUserDropdownTracking() {
const el = document.querySelector('.js-nav-user-dropdown');
2020-06-23 00:09:42 +05:30
const buyEl = document.querySelector('.js-buy-pipeline-minutes-link');
2020-04-22 19:07:51 +05:30
if (el && buyEl) {
2020-05-24 23:13:21 +05:30
trackShowUserDropdownLink('show_buy_ci_minutes', buyEl, el);
}
2020-04-22 19:07:51 +05:30
}
2021-03-11 19:13:27 +05:30
requestIdleCallback(initStatusTriggers);
requestIdleCallback(initNavUserDropdownTracking);