2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
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() {
|
|
|
|
$(document).on('todo:toggle', (e, count) => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const updatedCount = count || e?.detail?.count || 0;
|
2020-11-24 15:15:51 +05:30
|
|
|
const $todoPendingCount = $('.js-todos-count');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
$todoPendingCount.text(highCountTrim(updatedCount));
|
|
|
|
$todoPendingCount.toggleClass('hidden', updatedCount === 0);
|
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;
|
|
|
|
|
|
|
|
$(el).on('shown.bs.dropdown', () => {
|
|
|
|
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-05-24 23:13:21 +05:30
|
|
|
const upgradeEl = document.querySelector('.js-upgrade-plan-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
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
if (el && upgradeEl) {
|
|
|
|
trackShowUserDropdownLink('show_upgrade_link', upgradeEl, el);
|
2020-04-22 19:07:51 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
requestIdleCallback(initStatusTriggers);
|
|
|
|
requestIdleCallback(initNavUserDropdownTracking);
|