2018-10-04 04:19:51 -04:00
|
|
|
import Vue from 'vue';
|
2017-10-10 03:47:42 -04:00
|
|
|
import { highCountTrim } from '~/lib/utils/text_utility';
|
2020-04-09 11:09:29 -04:00
|
|
|
import Tracking from '~/tracking';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2017-03-11 02:30:44 -05:00
|
|
|
|
2017-10-10 03:47:42 -04:00
|
|
|
/**
|
|
|
|
* Updates todo counter when todos are toggled.
|
|
|
|
* When count is 0, we hide the badge.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
* @param {String} count
|
|
|
|
*/
|
2017-10-30 14:59:16 -04:00
|
|
|
export default function initTodoToggle() {
|
2022-06-29 17:09:23 -04:00
|
|
|
document.addEventListener('todo:toggle', (e) => {
|
|
|
|
const updatedCount = e.detail.count || 0;
|
|
|
|
const todoPendingCount = document.querySelector('.js-todos-count');
|
2017-10-10 03:47:42 -04:00
|
|
|
|
2022-06-29 17:09:23 -04:00
|
|
|
if (todoPendingCount) {
|
|
|
|
todoPendingCount.textContent = highCountTrim(updatedCount);
|
|
|
|
if (updatedCount === 0) {
|
|
|
|
todoPendingCount.classList.add('hidden');
|
|
|
|
} else {
|
|
|
|
todoPendingCount.classList.remove('hidden');
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 14:59:16 -04:00
|
|
|
});
|
|
|
|
}
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
function initStatusTriggers() {
|
2018-10-04 04:19:51 -04:00
|
|
|
const setStatusModalTriggerEl = document.querySelector('.js-set-status-modal-trigger');
|
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
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-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
Vue.use(Translate);
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: statusModalElement,
|
|
|
|
data() {
|
2020-11-17 10:09:28 -05:00
|
|
|
const {
|
|
|
|
currentEmoji,
|
|
|
|
defaultEmoji,
|
|
|
|
currentMessage,
|
|
|
|
currentAvailability,
|
2021-03-18 02:11:52 -04:00
|
|
|
currentClearStatusAfter,
|
2020-11-17 10:09:28 -05:00
|
|
|
} = setStatusModalWrapperEl.dataset;
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
return {
|
|
|
|
currentEmoji,
|
2020-11-17 10:09:28 -05:00
|
|
|
defaultEmoji,
|
2020-09-09 17:08:33 -04:00
|
|
|
currentMessage,
|
2020-11-17 10:09:28 -05:00
|
|
|
currentAvailability,
|
2021-03-18 02:11:52 -04:00
|
|
|
currentClearStatusAfter,
|
2020-09-09 17:08:33 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
2020-11-17 10:09:28 -05:00
|
|
|
const {
|
|
|
|
currentEmoji,
|
|
|
|
defaultEmoji,
|
|
|
|
currentMessage,
|
|
|
|
currentAvailability,
|
2021-03-18 02:11:52 -04:00
|
|
|
currentClearStatusAfter,
|
2020-11-17 10:09:28 -05:00
|
|
|
} = this;
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
return createElement(SetStatusModalWrapper, {
|
|
|
|
props: {
|
|
|
|
currentEmoji,
|
2020-11-17 10:09:28 -05:00
|
|
|
defaultEmoji,
|
2020-09-09 17:08:33 -04:00
|
|
|
currentMessage,
|
2020-11-17 10:09:28 -05:00
|
|
|
currentAvailability,
|
2021-03-18 02:11:52 -04:00
|
|
|
currentClearStatusAfter,
|
2020-09-09 17:08:33 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2018-10-04 04:19:51 -04:00
|
|
|
});
|
|
|
|
}
|
2019-01-08 06:25:02 -05:00
|
|
|
}
|
|
|
|
|
2020-05-15 08:08:28 -04:00
|
|
|
function trackShowUserDropdownLink(trackEvent, elToTrack, el) {
|
|
|
|
const { trackLabel, trackProperty } = elToTrack.dataset;
|
|
|
|
|
2022-06-29 17:09:23 -04:00
|
|
|
el.addEventListener('shown.bs.dropdown', () => {
|
2020-05-15 08:08:28 -04:00
|
|
|
Tracking.event(document.body.dataset.page, trackEvent, {
|
|
|
|
label: trackLabel,
|
|
|
|
property: trackProperty,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-04-09 11:09:29 -04:00
|
|
|
export function initNavUserDropdownTracking() {
|
|
|
|
const el = document.querySelector('.js-nav-user-dropdown');
|
2020-06-11 05:08:16 -04:00
|
|
|
const buyEl = document.querySelector('.js-buy-pipeline-minutes-link');
|
2020-04-09 11:09:29 -04:00
|
|
|
|
|
|
|
if (el && buyEl) {
|
2020-05-15 08:08:28 -04:00
|
|
|
trackShowUserDropdownLink('show_buy_ci_minutes', buyEl, el);
|
|
|
|
}
|
2020-04-09 11:09:29 -04:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:09:06 -05:00
|
|
|
requestIdleCallback(initStatusTriggers);
|
|
|
|
requestIdleCallback(initNavUserDropdownTracking);
|