/* Js for , Version=1791278525 */
 if(typeof(v) != "object") v = {};v.theme = {"template":"default","theme":"wide","device":"desktop"};;v.lang = {"confirmDelete":"您确定要执行删除操作吗？","deleteing":"删除中","doing":"处理中","loading":"加载中","updating":"更新中...","timeout":"网络超时,请重试","errorThrown":"执行出错：","continueShopping":"继续购物","required":"必填","back":"返回","continue":"继续","bindWechatTip":"发帖功能设置了绑定微信的限制，请先绑定微信会员。","importTip":"只导入主题的风格和样式","fullImportTip":"将会导入测试数据以及替换站点文章、产品等数据"};;
$(function()
{
    var $link = $('#navbar').find('.js-try-for-free');
    if(!$link.length) return;

    var raw = $.cookie('siteContext');
    if(!raw) return;

    var siteContext = {};
    try
    {
        siteContext = JSON.parse(raw) || {};
    }
    catch(e)
    {
        return;
    }

    var siteNumber = parseInt(siteContext.siteNumber, 10);
    if(isNaN(siteNumber)) siteNumber = 0;

    var defaultTryUrl = $link.data('defaultTryUrl');
    var chooseSiteUrl = $link.data('chooseSiteUrl');
    var loginSiteTpl  = $link.data('loginSiteTpl');
    var siteID        = siteContext.siteID || '';
    var userSite      = siteContext.userSite || '';

    if(defaultTryUrl) $link.attr('href', defaultTryUrl);

    if(siteNumber > 1)
    {
        $link.attr('href', chooseSiteUrl);
        return;
    }

    if(siteNumber === 1 && userSite && siteID && loginSiteTpl)
    {
        $link.attr('href', loginSiteTpl.replace('__SITE_ID__', siteID));
    }
});
;v.fullScreen = 0;;$(document).ready(function()
{
    $('.nav-system-book').addClass('active');
    $('#navbar li.active').parents('li').addClass('active');
    $('#article' + v.objectID).addClass('active');
    $('#article' + v.objectID).parents('dd').each(function()
    {
        $(this).attr('class', $(this).attr('class').replace('closed', 'opened'));
        $(this).addClass('active');
    });

    $('dd > span').click(function()
    {
        if($(this).parent().attr('class').indexOf('closed') != '-1')
        {
            $(this).parent().attr('class', $(this).parent().attr('class').replace('closed', 'opened'));
        }
        else
        {
            $(this).parent().attr('class', $(this).parent().attr('class').replace('opened', 'closed'));
        }
    });

    $('dd a').click(function()
    {
        if($('.article.book-content-wrapper').length !== 0)
        {
            getContent(this);
            return false;
        }
    });

    $('body').on("click",".icon-next a, .icon-previous a, .previous a, .next a",function()
    {
        if($('.article.book-content-wrapper').length !== 0)
        {
            getContent(this);
            return false;
        }
    });

    $('body').on("blur",'.popover input',function()
    {
        $('[data-toggle="popover"]').popover('hide');
        return false;
    });


    function getContent(obj)
    {
        if($(obj).parent().attr('class').indexOf('disabled') != '-1') return false;
        var url = $(obj).attr('href');
        if($('.article.book-content-wrapper').length !== 0)
        {
            $('.book-content-wrapper').load(url + ' .book-content-wrapper > div', function(response)
            {
                if($(response).find('.book-content-wrapper').length === 0)
                {
                    $('.book-content-wrapper').html("<div class='article book-content-wrapper'>" + $(response).find('.modal-dialog').html() + "</div>")
                }
                $('.breadcrumb').html($(response).find('.breadcrumb').html());
                init();
            });
        }
    }

    function init()
    {
        var objectID = $('#id').val();
        $('.article').removeClass('active');
        $('#article' + objectID).addClass('active');
        $('#article' + objectID).parents('dd').each(function()
        {
            $(this).attr('class', $(this).attr('class').replace('closed', 'opened'));
            $(this).addClass('active');
        })
        if($(".books dd.article.active > a").attr('href'))
        {
            if($(".qrcode-mobile").length)
            {
                articleID = $(".books dd.article.active").attr('id').substr('7');
                if($(".qrcode-mobile").attr('data-src'))
                {
                    length = $(".qrcode-mobile").attr('data-src').indexOf('qrcode');
                    $(".qrcode-mobile").attr('data-src', createLink('misc', 'qrcode', 'articleID=' + articleID));
                }
                else
                {
                    length = $(".qrcode-mobile").attr('src').indexOf('qrcode');
                    $(".qrcode-mobile").attr('src', createLink('misc', 'qrcode', 'articleID=' + articleID));
                }
            }
        }
        $('[data-toggle="popover"]').popover(
        { 
            content : v.scheme + "://" + v.httpHost + $(".books dd.article.active a").attr('href'),
            template : '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><input class="form-control" type="text" value=' + v.scheme + "://" + v.httpHost + $(".books dd.article.active a").attr('href') + '></div></div>',
            trigger : 'click',
        });
        $('[data-toggle="popover"]').tooltip({placement : 'right', title : v.copySuccess, trigger : 'manual'});
    }

    $(window).keydown(function(e)
    {
        if(e.keyCode == 37) getContent($('.previous a'));
        if(e.keyCode == 39) getContent($('.next a'));
    });

    init();

    $('.parent-category').off('click').click(function()
    {
        $('.book-catalog-wrap').toggleClass('active');
        $('.category-overlay').toggle();
    });
});
var lang = $.cookie('browseLang');
if (!lang) {
  lang = /^zh/i.test(navigator.language || '') ? 'zh-cn' : 'en';

  $.cookie('browseLang', lang, {
      expires: 365,
      path: '/',
      secure: true,
      sameSite: 'lax'
  });

  var url = new URL(location.href);
  var isCnPath =
      url.pathname === '/cn' ||
      url.pathname.indexOf('/cn/') === 0;

  if (lang === 'en' && isCnPath) {
      // /cn、/cn/XXX -> /、/XXX
      url.pathname = url.pathname.substring(3) || '/';
      location.replace(url.href);
  } else if (lang === 'zh-cn' && !isCnPath) {
      // /、/XXX -> /cn/、/cn/XXX
      url.pathname = '/cn' + url.pathname;
      location.replace(url.href);
  }
}
;
$(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));
    });
})
