/* Js for https://www.zentao.net/index.html, Version=1690191377 */
 v.lang = {"confirmDelete":"\u60a8\u786e\u5b9a\u8981\u6267\u884c\u5220\u9664\u64cd\u4f5c\u5417\uff1f","deleteing":"\u5220\u9664\u4e2d","doing":"\u5904\u7406\u4e2d","loading":"\u52a0\u8f7d\u4e2d","updating":"\u66f4\u65b0\u4e2d...","timeout":"\u7f51\u7edc\u8d85\u65f6,\u8bf7\u91cd\u8bd5","errorThrown":"\u6267\u884c\u51fa\u9519\uff1a","continueShopping":"\u7ee7\u7eed\u8d2d\u7269","required":"\u5fc5\u586b","back":"\u8fd4\u56de","continue":"\u7ee7\u7eed","bindWechatTip":"\u53d1\u5e16\u529f\u80fd\u8bbe\u7f6e\u4e86\u7ed1\u5b9a\u5fae\u4fe1\u7684\u9650\u5236\uff0c\u8bf7\u5148\u7ed1\u5b9a\u5fae\u4fe1\u4f1a\u5458\u3002","importTip":"\u53ea\u5bfc\u5165\u4e3b\u9898\u7684\u98ce\u683c\u548c\u6837\u5f0f","fullImportTip":"\u5c06\u4f1a\u5bfc\u5165\u6d4b\u8bd5\u6570\u636e\u4ee5\u53ca\u66ff\u6362\u7ad9\u70b9\u6587\u7ae0\u3001\u4ea7\u54c1\u7b49\u6570\u636e"};;
  $(function(){
    $("#siteNav a[href*='register']").remove();
    $("#siteNav a[href*='login']").text('登录/注册');
    $("#siteNav a[href*='login']").click(function(elem)
    {
      if(window.qrCodeTimer) window.clearInterval(window.qrCodeTimer);
      const id = 'loginModal';
      showModalLogin(id, elem.target, 13, 0, 1);
      $('body').css('padding-right', 'unset');
      return false;
    });

  });
;if($('.btn-test').length) {
    $('.carousel-caption').append($('.btn-test')[0]);
};var swiper = new Swiper(".product .swiper", {
    autoplay: false,
    loop: true,
    slidesPerView: 4,
    spaceBetween: 30,
    freeMode: true,
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    }
});;// $(document).ready(function(){
//     $('#block1380').insertBefore('.news1');
//     $('.items .item').wrap('<div class="col-md-4"></div>');
// });;

var currentBlockID = 1380;


if(typeof($('#block' + currentBlockID).parent('.col').data('grid')) === 'undefined' && $('#block' + currentBlockID).parent('.col').data('probability') === 'undefined')
{
    var grid = $('#block' + currentBlockID).parents('.blocks').data('grid');
    grid = typeof(grid) == 'undefined' ? 12 : grid;

    $('#block' + currentBlockID).parent('.col').attr('data-grid', grid).attr('class', 'col col-' + grid);
}

$('.articleTitleA').each(function()
{
    $(this).css('max-width', $(this).parents('li').width() - $(this).prev('.category').width() - $(this).next('.sticky').width() - $(this).parent().next('.article-date').width() - 10);
})
$('.articleTitleB').each(function()
{
    $(this).css('max-width', $(this).parent('li').width() - $(this).next('.sticky').width() - 10);
})
;$('#block1454 .panel-heading').append('<a href="/blog/agile-guidelines.html">More</a>');;$('#block1455 .panel-heading').append('<a href="/blog/project-management-overview.html">More</a>');;

var currentBlockID = 128;


if(typeof($('#block' + currentBlockID).parent('.col').data('grid')) === 'undefined' && $('#block' + currentBlockID).parent('.col').data('probability') === 'undefined')
{
    var grid = $('#block' + currentBlockID).parents('.blocks').data('grid');
    grid = typeof(grid) == 'undefined' ? 12 : grid;

    $('#block' + currentBlockID).parent('.col').attr('data-grid', grid).attr('class', 'col col-' + grid);
}

$('.articleTitleA').each(function()
{
    $(this).css('max-width', $(this).parents('li').width() - $(this).prev('.category').width() - $(this).next('.sticky').width() - $(this).parent().next('.article-date').width() - 10);
})
$('.articleTitleB').each(function()
{
    $(this).css('max-width', $(this).parent('li').width() - $(this).next('.sticky').width() - 10);
})
;$(document).ready(function()
{          
    // add "index" class to the body element.
    $('body').addClass('index');

    $('.nav-system-home:first').addClass('active');
    $('#navbar li.active').parents('li').addClass('active');
})
$('#words').attr('placeholder','全站搜索');
$('#foot').insertBefore('#footer');

$(document).ready(function(){
    if(typeof headerList != 'undefined') return ;
    headerList = true;
    $('#footer #icpInfo').after('<a class="privacy" href="/page/zentao-privacypolicy.html">隐私政策</a>');
    $('#footer #powerby').append('<a class="ipip" href="https://www.ipip.net/" target="_blank">本站IP数据由IPIP.NET提供</a>');
    $('#siteNav').append('<a class="language" href="http://www.zentao.pm/" target="_blank"><i class="icon icon-globe"></i>English</a>');
    $('.m-user-register .form-horizontal .agreement-form span').after('<span>和《<a href="/page/zentao-privacypolicy.html" target="_blank">隐私政策</a>》</span>');
});

$('.m-faq #top #toggleToc').text('隐藏目录').addClass('hide');
var isAdvanced = false;
$('.m-faq #top #toggleToc').on('click', function() {
   isAdvanced = !isAdvanced;
   if (isAdvanced) {
       $(this).text('显示目录').addClass('show').removeClass('hide');
   } else {
       $(this).text('隐藏目录').addClass('hide').removeClass('show');
   }
});

var windowScrollHeight = window.innerHeight;
var footerHeight = $('html').hasClass('m-book-read') ? 1 : $('#foot').height() + 54;
var headerHeight = $('html').hasClass('m-user-login') ? -130 : $('#header').height();
var minScrollHeight = windowScrollHeight - headerHeight - $('#footer').height() - footerHeight;
if($('.page-wrapper').height() < minScrollHeight) {
    $('.page-wrapper').css('minHeight', minScrollHeight)
}

$(window).scroll(function(){
    // if($(window).scrollTop()>230){
    //     $(".m-faq #top #toggleToc").addClass('fixed');
    // }else{
    //     $(".m-faq #top #toggleToc").removeClass('fixed');
    // }
    if ($(window).scrollTop() > 80) {
        $('#header').addClass('header-fixed');
        $('.page-wrapper').css('marginTop', '120px');
        $('.m-blog #blogNav').addClass('nav-fixed');
    } else if($(window).scrollTop() == 0){
        $('#header').removeClass('header-fixed');
        $('.page-wrapper').css('marginTop', 0);
        $('.m-blog #blogNav').removeClass('nav-fixed');
    }
});

$('.m-faq table:last-child').before('<hr>');

$(document).on('click', '#loginModal, #privacyagreement, #agreement', function(e) {
    e.stopPropagation();
})
function showModalLogin(id, elem,  moreTop, moreLeft, showHeader, style, callback)
{
    var isVisible = document.getElementById(id) && document.getElementById(id).offsetParent;
    if(isVisible) return false;
    if(!style) {
        style = {}
    }
    var calcTopLeft = function (elem,  moreTop, moreLeft) {
        var bound = elem.getBoundingClientRect();
        var realLeft = bound.left + moreLeft;
        var realTop = bound.top + bound.height + moreTop;
        var bodyWidth = document.documentElement.clientWidth;
        realLeft = realLeft + 410 > bodyWidth ? bodyWidth - 410 : realLeft;
        return {top: realTop, left: realLeft};
    }
    var position = calcTopLeft(elem, moreTop, moreLeft);
    var resetModalPos = function () {
        $('#' + id).css({
            'top' : position.top,
            'left': position.left,
        });
        $('#' + id).css(style);
    };
    var modalLoginOptions =
    {
        url      : "/user-loginmodal.html",
        width    : '410',
        height   : '440',
        backdrop : false,
        name     : id,
        position : 0,
        keyboard: false,
        loaded   : function() {
            $('#' + id).css({
                'position'  : 'fixed',
                'top'       : position.top,
                'left'      : position.left,
            });
            $('#' + id).css(style);
            $('#' + id + ' .modal-dialog').css({
                'margin': '0',
            });
            $('#' + id).addClass('modalLogin');
            if(showHeader == 0) $('#' + id + ' .close').hide();
            window.addEventListener('resize', resetModalPos);
            callback && callback();
        },
        onHide: function(){
            if(window.smsTimer) clearInterval(window.smsTimer);
            if(window.qrCodeTimer) clearInterval(window.qrCodeTimer);
            window.removeEventListener('resize', resetModalPos);
        }
    };
    var myModalTrigger = new $.zui.ModalTrigger(modalLoginOptions);
    myModalTrigger.show();
}
var demoModalTrigger;
function shwoDemoQuestion(url) {
    var modalDemoOptions =
    {
        url      : "/user-getquestionnaire-1.html",
        width    : '508',
        height   : '772',
        backdrop  : 'static',
        showHeader: false,
        keyboard: false,
        name:   'demo'
    };
    demoModalTrigger = new $.zui.ModalTrigger(modalDemoOptions);
    if(!$('#demo').is(':visible')) {
        demoModalTrigger.show({
            shown: function() {
                console.log(1);
                $('#intentVersion').val(sessionStorage.getItem('intentVersion'));
            },
            onHide: function() {
                window.open(url);
            }
        });
    }
}
document.querySelectorAll('.navbar a').forEach(item => {
    if($(item).attr('href').includes('/demo')) {
        $(item).off('click').click(function(e){
            e.preventDefault();
            var version = $(item).parent().parent('.dropdown-menu').siblings('a').text();
            var type = $(item).text();
            var intentVersion = $.trim(version) === '演示' ? type : `${version},${type}`;
            sessionStorage.setItem('intentVersion', intentVersion);
            $.get('/user-getquestionnaire-1.html', function(res)
            {
               if(res.result !== 'fail')
               {
                    shwoDemoQuestion($(item).attr('href'));
               }
               else 
               {
                   window.open($(item).attr('href'));
               }
            });
        });
    }
});

if($('#item1039').length) 
{
    $('#item1161.item-content, #item1160.item-content, #item1159.item-content, #item1074.item-content, #item1072.item-content, #item1070.item-content, #item1068.item-content, #item1066.item-content, #item1064.item-content, #item1062.item-content, #item1060.item-content, #item1054.item-content, #item1052.item-content, #item1050.item-content, #item1046.item-content, #item1049.item-content, #item1044.item-content, #item1042.item-content, #item1040.item-content, #item1039.item-content, #item1037.item-content, #item1035.item-content, #item1076.item-content, #item1075.item-content').prev().hide();
}

$('a[href="/form-information-94.html"]').hide();

function getZentaoChangeLog(type, version) {
    if($('.icon-spin').length) return;
    $('.change-log').after('<i class="icon icon-spin icon-spinner-indicator"></i>');
    var options = {
        name: 'logModal',
        title: $('#article h1').text(),
        width: '700px'
    };
    $.get(`/zentaoversion-get-${type}-${version}.html`, function(response) {
        options.custom = response.changelog.replace(/\n/g, '<br>');
        var logModalTrigger = new $.zui.ModalTrigger(options);
        logModalTrigger.show();
        $('.icon-spin').remove();
    });
}

function checkUaIsMobile() {
    return /(iPhone|iPad|iPod|iOS|Android|Linux armv8l|Linux armv7l|Linux aarch64)/i.test(
        navigator.userAgent
    );
}

$('#header .input-group-btn .btn').click(function()
{
    var value = $(this).parent().prev('input').val();
    if(value)
    {
        $('#searchForm').submit();
    }
});

$('#header .input-group #words').keypress(function(e) 
{
    if(e.keyCode === 13) 
    {
        var value = $(this).val();   
        if(value)
        {
            $('#searchForm').submit();
        }
        return false;
    }
});$(".see-wrap .see").mouseover(function(){
    $(".see-wrap .seex").removeClass("curr");
});
$(".see-wrap .see").mouseout(function(){
    $(".see-wrap .seex").addClass("curr");
});
;
$(document).ready(function()
{
    $('a[data-download=1]').each(function()
    {   
        link = window.btoa(window.encodeURIComponent($(this).attr('href')));
        fileName = window.btoa(window.encodeURIComponent($(this).text()));
        $(this).attr('data-toggle', 'modal').attr('href', createLink('misc', 'download', 'link=' + link + '&fileName=' + fileName));
    }); 
})
;
function loadCartInfo(twinkle)
{
    $('#siteNav').load(createLink('misc', 'printTopBar'),
        function()
        {
            if(twinkle) 
            {
                bootbox.dialog(
                {  
                    message: v.addToCartSuccess,  
                    buttons:
                    {  
                        back:
                        {  
                            label:     v.lang.continueShopping,
                            className: 'btn-primary',  
                            callback:  function(){location.reload();}  
                        },
                        cart:
                        {  
                            label:     v.gotoCart,  
                            className: 'btn-primary',  
                            callback:  function(){location.href = createLink('cart', 'browse');}  
                        }  
                    }  
                });
            }
        }
    );
}
;
    var userBehaviorData = JSON.parse(localStorage.getItem('userBehavior'));
    if(!userBehaviorData){ userBehaviorData = []; }
    userBehaviorData.push({
        referrer: document.referrer,
        url: document.URL,
        title: document.title,
        timestamp: Date.parse(new Date()) / 1000
    })
    localStorage.setItem('userBehavior', JSON.stringify(userBehaviorData));
