HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/timetracker.panomity.com/assets/js/plugins/KimaiThemeInitializer.js
/*
 * This file is part of the Kimai time-tracking app.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/*!
 * [KIMAI] KimaiThemeInitializer: initialize theme functionality
 */

import { Tooltip } from 'bootstrap';
import KimaiPlugin from '../KimaiPlugin';

export default class KimaiThemeInitializer extends KimaiPlugin {

    init()
    {
        // the tooltip do not use data-bs-toggle="tooltip" so they can be mixed with data-toggle="modal"
        [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]')).map(function (tooltipTriggerEl) {
            return new Tooltip(tooltipTriggerEl);
        });

        // activate all form plugins
        /** @type {KimaiForm} FORMS */
        const FORMS = this.getContainer().getPlugin('form');
        FORMS.activateForm('div.page-wrapper form');

        this._registerModalAutofocus('#remote_form_modal');

        this.overlay = null;

        // register a global event listener, which displays an overlays upon notification
        document.addEventListener('kimai.reloadContent', (event) => {
            // do not allow more than one loading screen at a time
            if (this.overlay !== null) {
                return;
            }

            // at which element we append the loading screen
            let container = 'body';
            if (event.detail !== undefined && event.detail !== null) {
                container = event.detail;
            }

            const temp = document.createElement('div');
            temp.innerHTML = '<div class="overlay"><div class="fas fa-sync fa-spin"></div></div>';
            this.overlay = temp.firstElementChild;
            document.querySelector(container).append(this.overlay);
        });

        // register a global event listener, which hides an overlay upon notification
        document.addEventListener('kimai.reloadedContent', () => {
            if (this.overlay !== null) {
                this.overlay.remove();
                this.overlay = null;
            }
        });
    }

    /**
     * Helps to set the autofocus on modals.
     *
     * @param {string} selector
     */
    _registerModalAutofocus(selector) {
        // on mobile you do not want to trigger the virtual keyboard upon modal open
        if (this.isMobile()) {
            return;
        }

        const modal = document.querySelector(selector);
        if (modal === null) {
            return;
        }

        modal.addEventListener('shown.bs.modal', () => {
            const form = modal.querySelector('form');
            let formAutofocus = form.querySelectorAll('[autofocus]');
            if (formAutofocus.length < 1) {
                formAutofocus = form.querySelectorAll('input[type=text],input[type=date],textarea,select');
            }
            if (formAutofocus.length > 0) {
                formAutofocus[0].focus();
            }
        });
    }
}