/**
 * Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */

jQuery.noConflict();
jQuery(document).ready(function ($) {
    jQuery('body').tooltip({
        selector: '[data-toggle="tooltip"]',
        delay: { "show": 300, "hide": 50 },
        trigger : 'hover',
        html: true
    });

    jQuery(document).on('shown.bs.tooltip', '.withLeftOffset[data-toggle=tooltip]', function () {
        let $j = jQuery(this).siblings('.tooltip');
        let offset = parseInt($j.width() / 2 - $j.width() * 0.3);
        let leftPosOfArrow = parseInt($j.find('.tooltip-arrow').position().left);
        $j.css('left', parseInt($j.css('left')) + offset + 'px')
            .find('.tooltip-arrow').css({left: parseInt(leftPosOfArrow - offset) + 'px'});

        setTimeout(() => {
            $j.addClass('showTooltip');
        }, 100);
    });

    jQuery(document).on('hide.bs.tooltip', '.withLeftOffset[data-toggle=tooltip]', function () {
        jQuery(this).siblings('.tooltip').removeClass('showTooltip');
    });
});