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

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-12-05 23:21:45 +05:30
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
2018-03-17 18:26:18 +05:30
import { highCountTrim } from '~/lib/utils/text_utility';
2018-12-05 23:21:45 +05:30
import SetStatusModalTrigger from './set_status_modal/set_status_modal_trigger.vue';
import SetStatusModalWrapper from './set_status_modal/set_status_modal_wrapper.vue';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
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) => {
const parsedCount = parseInt(count, 10);
const $todoPendingCount = $('.todos-count');
$todoPendingCount.text(highCountTrim(parsedCount));
$todoPendingCount.toggleClass('hidden', parsedCount === 0);
});
}
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');
const setStatusModalWrapperEl = document.querySelector('.js-set-status-modal-wrapper');
if (setStatusModalTriggerEl || setStatusModalWrapperEl) {
Vue.use(Translate);
// eslint-disable-next-line no-new
new Vue({
el: setStatusModalTriggerEl,
data() {
const { hasStatus } = this.$options.el.dataset;
return {
2019-02-15 15:39:39 +05:30
hasStatus: parseBoolean(hasStatus),
2018-12-05 23:21:45 +05:30
};
},
render(createElement) {
return createElement(SetStatusModalTrigger, {
props: {
hasStatus: this.hasStatus,
},
});
},
});
// eslint-disable-next-line no-new
new Vue({
el: setStatusModalWrapperEl,
data() {
const { currentEmoji, currentMessage } = this.$options.el.dataset;
return {
currentEmoji,
currentMessage,
};
},
render(createElement) {
const { currentEmoji, currentMessage } = this;
return createElement(SetStatusModalWrapper, {
props: {
currentEmoji,
currentMessage,
},
});
},
});
}
2019-03-02 22:35:43 +05:30
}
document.addEventListener('DOMContentLoaded', () => {
requestIdleCallback(initStatusTriggers);
2018-12-05 23:21:45 +05:30
});