2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-10-04 04:19:51 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Translate from '~/vue_shared/translate';
|
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';
|
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() {
|
|
|
|
$(document).on('todo:toggle', (e, count) => {
|
2020-07-16 20:09:37 -04:00
|
|
|
const updatedCount = count || e?.detail?.count || 0;
|
2020-09-11 05:08:44 -04:00
|
|
|
const $todoPendingCount = $('.js-todos-count');
|
2017-10-10 03:47:42 -04:00
|
|
|
|
2020-07-16 20:09:37 -04:00
|
|
|
$todoPendingCount.text(highCountTrim(updatedCount));
|
|
|
|
$todoPendingCount.toggleClass('hidden', updatedCount === 0);
|
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() {
|
|
|
|
const { currentEmoji, currentMessage } = setStatusModalWrapperEl.dataset;
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
return {
|
|
|
|
currentEmoji,
|
|
|
|
currentMessage,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
const { currentEmoji, currentMessage } = this;
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
return createElement(SetStatusModalWrapper, {
|
|
|
|
props: {
|
|
|
|
currentEmoji,
|
|
|
|
currentMessage,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.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;
|
|
|
|
|
|
|
|
$(el).on('shown.bs.dropdown', () => {
|
|
|
|
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-05-15 08:08:28 -04:00
|
|
|
const upgradeEl = document.querySelector('.js-upgrade-plan-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
|
|
|
|
2020-05-15 08:08:28 -04:00
|
|
|
if (el && upgradeEl) {
|
|
|
|
trackShowUserDropdownLink('show_upgrade_link', upgradeEl, el);
|
2020-04-09 11:09:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
requestIdleCallback(initStatusTriggers);
|
2020-09-09 17:08:33 -04:00
|
|
|
requestIdleCallback(initNavUserDropdownTracking);
|
2018-10-04 04:19:51 -04:00
|
|
|
});
|