/* Js for https://www.zentao.net/book/zentaopmshelp/90.html, Version=1671831795 */
 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;
    });

  });
;v.copySuccess = "\u590d\u5236\u6210\u529f";;v.objectType = "book";;v.objectID = 90;;v.scheme = "https";;v.httpHost = "www.zentao.net";;
$(function()
{
    var videoContainer = "<video id=\"VIDEO_ID\" class=\"video-js vjs-default-skin vjs-big-play-centered\" controls preload=\"auto\" loop=\"loop\" data-setup='{\"autoplay\": VIDEO_AUTOSTART, \"width\": VIDEO_WIDTH, \"height\": VIDEO_HEIGHT, \"controlBar\": {\"fullscreenToggle\": VIDEO_FULLSCREEN}}'><source src=\"VIDEO_SRC\" type=\"video\/VIDEO_TYPE\" \/> <\/video>";
    $('embed').each(function(index)
    {
        if($(this).hasClass('videojs')) 
        {
            var $embed      = $(this),
                src         = $embed.attr('src'),
                w           = $embed.width(),
                h           = $embed.height(),
                type        = src.match(/t=\w+/g),
                autostart   = $embed.attr('autostart'),
                fullscreen  = $embed.attr('allowfullscreen'),
                containerID = 'video_' + index;

            $container = videoContainer.replace(/VIDEO_SRC/g, src);
            $container = $container.replace(/VIDEO_WIDTH/, w);
            $container = $container.replace(/VIDEO_HEIGHT/, h);
            $container = $container.replace(/VIDEO_ID/, containerID);
            $container = $container.replace(/VIDEO_AUTOSTART/, autostart);
            $container = $container.replace(/VIDEO_FULLSCREEN/, fullscreen);
            $container = $container.replace(/VIDEO_TYPE/, type[0].replace('t=', ''));
            $(this).replaceWith($container);
        }
    })
});
;$(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');
    })
    if(v.fullScreen)
    {
        $('html, body').css('height', '100%');

        var hash = window.location.hash;
        if(hash.indexOf('#article') === 0)
        {
            var $selected = $(hash);
            if($selected.length) $selected[0].scrollIntoView();
        }

        $('.article').each(function()
        {
            var $article = $(this);
            var $a = $article.children('a');
            if($a.length) $a.attr('href', $a.attr('href') + '#' + $article.attr('id'));
        });
    }

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

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

    $('body').on("click",".icon-next a, .icon-previous a, .previous a, .next a",function()
    {
        if($('.article.book-content').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').length !== 0)
        {
            $('.col-md-9').load(url + ' .col-md-9 > div', function(response)
            {   
                if($(response).find('.col-md-9').length === 0)
                {
                    $('.col-md-9').html("<div class='article book-content'>" + $(response).find('.modal-dialog').html() + "</div>")
                }
                $('.breadcrumb').html($(response).find('.breadcrumb').html());
                init();
                if($('#commentBox').length) $('#commentBox').load(v.messageUrl);
            });
        }
        else
        {
            $.get(url, function(data)
            {   
                $('.fullScreen-content').html($(data).find('.fullScreen-content').html());
                $('.fullScreen-nav').html($(data).find('.fullScreen-nav').html());
                init();
            })
        }
    }

    function init()
    {
        window.scrollTo({top: 0});
        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'});

        fancyImage();
    }

    function fancyImage() {
        $('.article-content img').each(function()
        {
            const _this = $(this);
            _this.wrap(`<a class="box-group" data-fancybox rel="group" href=${_this.attr('src')}></a>`);
        });
    
        Fancybox.bind("[data-fancybox]", {
            groupAll : true,
            modal: true
        });
    }

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

    if(!$('html').hasClass('m-book-browse'))
    {
        init();
    }
    else
    {
        $('.catalogue').removeClass('closed').addClass('opened');
			  $(window).scroll(function()
        {
	   	 		$('.dropdown').removeClass('open');
        });
    }
});
$(document).ready(function()
{
    var clipboard = new ClipboardJS('.url-copy');
    clipboard.on('success', function(e) {
        $(e.trigger).tooltip('show');
        setTimeout(function(){$(e.trigger).tooltip('hide');}, 2000);
        $(e.trigger).popover('hide');
    });
    if($('.fullScreen-nav .nav-content').height() < $(window).height())
    {
        $('.fullScreen-nav .nav-content').css('padding-top', '0px');
    }

    $('.fullScreen-nav .nav-content a').click(function()
    {
        $('.fullScreen-nav .nav-content a').removeClass('active');
        $(this).addClass('active');
    });
    
    $('body').tooltip(
    {
         html: true,
         selector: "[data-toggle=tooltip]",
         container: "body"
    });

    $('.fullScreen-content').on("scroll", function()
    {
        var count = $(".fullScreen-nav li").length;
        if(!count) return false;
        for(var i=0;i<count;i++)
        {
            if($('#' + i).offset().top <= '80')
            {
                $('.fullScreen-nav .nav-content a').removeClass('active');
                $(".fullScreen-nav .nav-content a[href='#" + i + "']").addClass('active');
            }
        }
    });
    /* Scroll function. */
    function yrScroll()
    {
         var listTitleHeight = $(".book-catalog .panel-heading").height();

         var catalogWidth  = $('.book-catalog').width();
         var catalogHeight = $(window).height() - 10;
         $(".book-catalog").css({'max-height': catalogHeight, 'overflow-y': 'auto', 'overflow-x': 'hidden'});

         if($('.books .active').length)
         {
             var listScrollTop =  $(".books .active").position().top;
             var listMoveSize = listScrollTop > ( $(".bookScrollListsBox").height() - listTitleHeight ) / 2 ? listScrollTop : 0;
             var scrollMoveSize = listMoveSize / $(".books").height(); 
             $(".bookScrollListsBox").scrollTop
             (
                 $(".bookScrollListsBox .books").height() * scrollMoveSize -($(".bookScrollListsBox").height() / 2 - $(".bookScrollListsBox .panel-heading").height() - 47)
             );
         }


         /* Bind scroll event */
         $(document).on("scroll", function ()
         {
              if( $("#book").offset()) var headerHeight = $("#book").offset().top;
              if( $('.col-md-9').offset()) { var footerHeight = $('.col-md-9').offset().top + $('.col-md-9').height() - $(window).height();}

              $(".page-wrapper").css({"min-height":$(".book-catalog").height()})
              if($(document).scrollTop() > headerHeight )
              {
                   $('.book-catalog').css({'position': 'fixed', 'top':'0', 'width': catalogWidth});

                   if($(document).scrollTop() > footerHeight)
                   {
                       catalogHeight2 = $(window).height() - $('.blocks.all-bottom').outerHeight() - $('#footer').outerHeight() - 60;
                       $('.book-catalog').css({'max-height': catalogHeight2, 'overflow-y': 'auto', 'overflow-x': 'hidden'});
                   }
                   else
                   {
                       $('.book-catalog').css({'max-height': catalogHeight, 'overflow-y': 'auto', 'overflow-x': 'hidden'});
                   }
              }
              else if( $(document).scrollTop() < headerHeight )
              {
                   $('.book-catalog').css({'position': 'relative' });
              }
         });
    };
    yrScroll();

    $('.previous > a, .next > a').css('max-width', (($('.pager').width() - $('.pager > .back > a').width()) * 0.45));

    if($('.previous > a > span').width() > $('.previous > a').width())
    {
        previousSpanWidth = $('.previous > a').width() - $('.previous .icon-arrow-left').width() - 5;
        $('.previous > a > span').css('width', previousSpanWidth);
    }

    if($('.next > a > span').width() > $('.next > a').width())
    {
        nextSpanWidth = $('.next > a').width() - $('.next .icon-arrow-right').width() - 5;
        $('.next > a > span').css('width', nextSpanWidth);
    }
});

(function($, document, Math) {
    'use strict';

    var NAME     = 'zui.droppable',
        DEFAULTS = {
        // container: '',
        // selector: '',
        // handle: '',
        // flex: false,
        // nested: false,
        target: '.droppable-target',
        deviation: 5,
        sensorOffsetX: 0,
        sensorOffsetY: 0,
        dropToClass: 'drop-to',
         // mouseButton: -1 // 0, 1, 2, -1, all, left,  right, middle
    };
    var idIncrementer = 0;

    var Droppable = function(element, options) {
        var that     = this;
        that.id      = idIncrementer++;
        that.$       = $(element);
        that.options = $.extend({}, DEFAULTS, that.$.data(), options);
        that.init();
    };

    Droppable.DEFAULTS = DEFAULTS;
    Droppable.NAME     = NAME;

    Droppable.prototype.trigger = function(name, params) {
        return $.zui.callEvent(this.options[name], params, this);
    };

    Droppable.prototype.init = function() {
        var that           = this,
            $root          = that.$,
            setting        = that.options,
            deviation      = setting.deviation,
            eventSuffix    = '.' + NAME + '.' + that.id,
            mouseDownEvent = 'mousedown' + eventSuffix,
            mouseUpEvent   = 'mouseup' + eventSuffix,
            mouseMoveEvent = 'mousemove' + eventSuffix,
            selector       = setting.selector,
            handle         = setting.handle,
            flex           = setting.flex,
            container      = setting.container,
            canMoveHere    = setting.canMoveHere,
            dropToClass    = setting.dropToClass,
            $ele           = $root,
            isMouseDown    = false,
            $container     = container ? $(setting.container).first() : (selector ? $root : $('body')),
            $targets,
            $target,
            $shadow,
            isIn,
            isSelf,
            oldCssPosition,
            startOffset,
            startMouseOffset,
            containerOffset,
            clickOffset,
            mouseOffset,
            lastMouseOffset,
            mouseDownBackEventCall;

        var mouseMove = function(event) {
            if(!isMouseDown) return;

            mouseOffset = {left: event.pageX, top: event.pageY};

            // ignore small move
            if(Math.abs(mouseOffset.left - startMouseOffset.left) < deviation && Math.abs(mouseOffset.top - startMouseOffset.top) < deviation) return;

            if($shadow === null) // create shadow
            {
                var cssPosition = $container.css('position');
                if(cssPosition != 'absolute' && cssPosition != 'relative' && cssPosition != 'fixed') {
                    oldCssPosition = cssPosition;
                    $container.css('position', 'relative');
                }

                $shadow = $ele.clone().removeClass('drag-from').addClass('drag-shadow').css({
                    position:   'absolute',
                    width:      $ele.outerWidth(),
                    transition: 'none'
                }).appendTo($container);
                $ele.addClass('dragging');

                that.trigger('start', {
                    event:   event,
                    element: $ele,
                    shadowElement: $shadow,
                    targets: $targets
                });
            }

            var offset = {
                left: mouseOffset.left - clickOffset.left,
                top:  mouseOffset.top - clickOffset.top
            };
            var position = {
                left: offset.left - containerOffset.left,
                top:  offset.top - containerOffset.top
            };
            $shadow.css(position);
            $.extend(lastMouseOffset, mouseOffset);

            var isNew = false;
                isIn = false;

            if(!flex) {
                $targets.removeClass(dropToClass);
            }

            var $newTarget = null;
            $targets.each(function() {
                var t    = $(this),
                    tPos = t.offset(),
                    tW   = t.outerWidth(),
                    tH   = t.outerHeight(),
                    tX   = tPos.left + setting.sensorOffsetX,
                    tY   = tPos.top + setting.sensorOffsetY;

                if(mouseOffset.left > tX && mouseOffset.top > tY && mouseOffset.left < (tX + tW) && mouseOffset.top < (tY + tH)) {
                    if($newTarget) $newTarget.removeClass(dropToClass);
                    $newTarget = t;
                    if(!setting.nested) return false;
                }
            });

            if($newTarget) {
                isIn = true;
                var id = $newTarget.data('id');
                if($ele.data('id') != id) isSelf = false;
                if($target === null || ($target.data('id') !== id && (!isSelf))) isNew = true;
                $target = $newTarget;
                if(flex) {
                    $targets.removeClass(dropToClass);
                }
                $target.addClass(dropToClass);
            }


            if(!flex) {
                $ele.toggleClass('drop-in', isIn);
                $shadow.toggleClass('drop-in', isIn);
            } else if($target !== null && $target.length) {
                isIn = true;
            }

            if(!canMoveHere || canMoveHere($ele, $target) !== false) {
                that.trigger('drag', {
                    event: event,
                    isIn: isIn,
                    target: $target,
                    element: $ele,
                    isNew: isNew,
                    selfTarget: isSelf,
                    clickOffset: clickOffset,
                    offset: offset,
                    position: {
                        left: offset.left - containerOffset.left,
                        top: offset.top - containerOffset.top
                    },
                    mouseOffset: mouseOffset
                });
            }

            event.preventDefault();
        };

        var mouseUp = function(event) {
            $(document).off(eventSuffix);
            clearTimeout(mouseDownBackEventCall);
            if(!isMouseDown) return;

            isMouseDown = false;

            if(oldCssPosition) {
                $container.css('position', oldCssPosition);
            }

            if($shadow === null) {
                $ele.removeClass('drag-from');
                that.trigger('always', {
                    event: event,
                    cancel: true
                });
                return;
            }

            if(!isIn) $target = null;
            var isSure = true;
            mouseOffset = event ? {
                left: event.pageX,
                top: event.pageY
            } : lastMouseOffset;
            var offset = {
                left: mouseOffset.left - clickOffset.left,
                top: mouseOffset.top - clickOffset.top
            };
            var moveOffset = {
                left: mouseOffset.left - lastMouseOffset.left,
                top: mouseOffset.top - lastMouseOffset.top
            };
            lastMouseOffset.left = mouseOffset.left;
            lastMouseOffset.top = mouseOffset.top;
            var eventOptions = {
                event: event,
                isIn: isIn,
                target: $target,
                element: $ele,
                isNew: (!isSelf) && $target !== null,
                selfTarget: isSelf,
                offset: offset,
                mouseOffset: mouseOffset,
                position: {
                    left: offset.left - containerOffset.left,
                    top: offset.top - containerOffset.top
                },
                lastMouseOffset: lastMouseOffset,
                moveOffset: moveOffset
            };

            isSure = that.trigger('beforeDrop', eventOptions);

            if(isSure && isIn) {
                that.trigger('drop', eventOptions);
            }

            $targets.removeClass(dropToClass);
            $ele.removeClass('dragging').removeClass('drag-from');
            $shadow.remove();
            $shadow = null;

            that.trigger('finish', eventOptions);
            that.trigger('always', eventOptions);

            if(event) event.preventDefault();
        };

        var mouseDown = function(event) {
            var mouseButton = $.zui.getMouseButtonCode(setting.mouseButton);
            if(mouseButton > -1 && event.button !== mouseButton) {
                return;
            }

            var $mouseDownEle = $(this);
            if(selector) {
                $ele = handle ? $mouseDownEle.closest(selector) : $mouseDownEle;
            }

            if($ele.hasClass('drag-shadow')) {
                return;
            }

            if(setting['before']) {
                if(setting['before']({
                    event: event,
                    element: $ele
                }) === false) return;
            }

            isMouseDown = true;
            $targets         = typeof setting.target === 'function' ? setting.target($ele, $root) : $container.find(setting.target),
            $target          = null,
            $shadow          = null,
            isIn             = false,
            isSelf           = true,
            oldCssPosition   = null,
            startOffset      = $ele.offset(),
            containerOffset  = $container.offset();
            containerOffset.top = containerOffset.top - $container.scrollTop();
            containerOffset.left = containerOffset.left - $container.scrollLeft();
            startMouseOffset = {left: event.pageX, top: event.pageY};
            lastMouseOffset  = $.extend({}, startMouseOffset);
            clickOffset      = {
                left: startMouseOffset.left - startOffset.left,
                top: startMouseOffset.top - startOffset.top
            };

            $ele.addClass('drag-from');
            $(document).on(mouseMoveEvent, mouseMove).on(mouseUpEvent, mouseUp);
            mouseDownBackEventCall = setTimeout(function() {
                $(document).on(mouseDownEvent, mouseUp);
            }, 10);
            event.preventDefault();
            if(setting.stopPropagation) {
                event.stopPropagation();
            }
        };

        if(handle) {
            $root.on(mouseDownEvent, handle, mouseDown);
        } else if(selector) {
            $root.on(mouseDownEvent, selector, mouseDown);
        } else {
            $root.on(mouseDownEvent, mouseDown);
        }
    };

    Droppable.prototype.destroy = function() {
        var eventSuffix = '.' + NAME + '.' + this.id;
        this.$.off(eventSuffix);
        $(document).off(eventSuffix);
        this.$.data(NAME, null);
    };

    Droppable.prototype.reset = function() {
        this.destroy();
        this.init();
    };

    $.fn.droppable = function(option) {
        return this.each(function() {
            var $this = $(this);
            var data = $this.data(NAME);
            var options = typeof option == 'object' && option;

            if(!data) $this.data(NAME, (data = new Droppable(this, options)));

            if(typeof option == 'string') data[option]();
        });
    };

    $.fn.droppable.Constructor = Droppable;

}(jQuery, document, Math));

(function($, window, undefined) {
    'use strict';

    /* Check jquery */
    if(typeof($) === 'undefined') throw new Error('ZUI requires jQuery');

    /* ZUI shared object */
    if(!$.zui) $.zui = function(obj) {
        if($.isPlainObject(obj)) {
            $.extend($.zui, obj);
        }
    };

    var MOUSE_BUTTON_CODES = {
        all: -1,
        left: 0,
        middle: 1,
        right: 2
    };

    var lastUuidAmend = 0;
    $.zui({
        uuid: function(asNumber) {
            var uuidNumber = (Date.now() - 1580890015292) * 10e4 + Math.floor(Math.random() * 10e3) * 10 + (lastUuidAmend++) % 10;
            return asNumber ? uuidNumber : uuidNumber.toString(36);
        },

        callEvent: function(func, event, proxy) {
            if(typeof func === 'function') {
                if(proxy !== undefined) {
                    func = func.bind(proxy);
                }
                var result = func(event);
                if(event) event.result = result;
                return !(result !== undefined && (!result));
            }
            return 1;
        },

        strCode: function(str) {
            var code = 0;
            if (typeof str !== 'string') str = String(str);
            if(str && str.length) {
                for(var i = 0; i < str.length; ++i) {
                    code += (i + 1) * str.charCodeAt(i);
                }
            }
            return code;
        },

        getMouseButtonCode: function(mouseButton) {
            if(typeof mouseButton !== 'number') {
                mouseButton = MOUSE_BUTTON_CODES[mouseButton];
            }
            if(mouseButton === undefined || mouseButton === null) mouseButton = -1;
            return mouseButton;
        },

        /**
         * default language name
         * @type {string}
         */
        defaultLang: 'en',

        /**
         * Get client language name
         * @return {string}
         */
        clientLang: function() {
            var lang;
            var config = window.config;
            if(typeof(config) != 'undefined' && config.clientLang) {
                lang = config.clientLang;
            }
            if(!lang) {
                var hl = $('html').attr('lang');
                lang = hl ? hl : (navigator.userLanguage || navigator.userLanguage || $.zui.defaultLang);
            }
            return lang.replace('-', '_').toLowerCase();
        },

        /**
         * @type {object}
         * @example
         * {
         *      'zui.pager': {
         *          'zh-cn': {
         *              prev: '上一页',
         *          }
         *      }
         * }
         */
        langDataMap: {},

        /**
         * Add lang data for components
         * @param {string} [langName]
         * @param {string} [componentName]
         * @param {object} data
         * @example
         * // Add lang data to specify language and specify component
         * $.zui.addLangData('zh-cn', 'zui.pager', {
         *      prev: '上一页',
         *      next: '下一页',
         * });
         *
         * // Add lang data to specify language and multiple components
         * $.zui.addLangData('zh-cn', {
         *      'zui.pager': {
         *          prev: '上一页',
         *          next: '下一页',
         *      },
         *      'chosen': {
         *      }
         * });
         *
         * // Add lang data to multiple languages and multiple components
         * $.zui.addLangData({
         *      'zh-cn': {
         *          'zui.pager': {
         *              prev: '上一页',
         *              next: '下一页',
         *          },
         *          'chosen': {
         *          }
         *      },
         *      'zh-tw': {
         *          'zui.pager': {
         *              prev: '上一页',
         *              next: '下一页',
         *          }
         *      }
         * });
         */
        addLangData: function(langName, componentName, data) {
            var langData = {};
            if (data && componentName && langName) {
                langData[componentName] = {};
                langData[componentName][langName] = data;
            } else if (langName && componentName && !data) {
                data = componentName;
                $.each(data, function(comName) {
                    langData[comName] = {};
                    langData[comName][langName] = data[comName];
                });
            } else if (langName && !componentName && !data) {
                $.each(data, function(theLangName) {
                    var comsData = data[theLangName];
                    $.each(comsData, function(comName) {
                        if (!langData[comName]) {
                            langData[comName] = {};
                        }
                        langData[comName][theLangName] = comsData[comName];
                    });
                });
            }
            $.extend(true, $.zui.langDataMap, langData);
        },

        /**
         * Get lang data
         * @example
         * $.zui.getLangData('zui.pager');
         *
         * $.zui.getLangData('zui.pager', 'zh-cn');
         *
         * $.zui.getLangData('zui.pager', 'zh-cn', {
         *      prev: '上一页',
         *      next: '下一页',
         * });
         */
        getLangData: function(componentName, langName, initialData) {
            if (!arguments.length) {
                return $.extend({}, $.zui.langDataMap);
            }
            if (arguments.length === 1) {
                return $.extend({}, $.zui.langDataMap[componentName]);
            }
            if (arguments.length === 2) {
                var comData = $.zui.langDataMap[componentName];
                if (comData) {
                    return langName ? comData[langName] : comData;
                }
                return {};
            }
            if (arguments.length === 3) {
                langName = langName || $.zui.clientLang();
                var comData = $.zui.langDataMap[componentName];
                var langData = comData ? comData[langName] : {};
                return $.extend(true, {}, initialData[langName] || initialData.en || initialData.zh_cn, langData);
            }
            return null;
        },

        lang: function() {
            if (arguments.length && $.isPlainObject(arguments[arguments.length - 1])) {
                return $.zui.addLangData.apply(null, arguments);
            }
            return $.zui.getLangData.apply(null, arguments);
        },

        _scrollbarWidth: 0,
        checkBodyScrollbar: function() {
            if(document.body.clientWidth >= window.innerWidth) return 0;
            if(!$.zui._scrollbarWidth) {
                var scrollDiv = document.createElement('div');
                scrollDiv.className = 'scrollbar-measure';
                document.body.appendChild(scrollDiv);
                $.zui._scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
                document.body.removeChild(scrollDiv);
            }
            return $.zui._scrollbarWidth;
        },
        fixBodyScrollbar: function() {
            if($.zui.checkBodyScrollbar()) {
                var $body = $('body');
                var bodyPad = parseInt(($body.css('padding-right') || 0), 10);
                if($.zui._scrollbarWidth) {
                    $body.css({paddingRight: bodyPad + $.zui._scrollbarWidth, overflowY: 'hidden'});
                }
                return true;
            }
        },
        resetBodyScrollbar: function() {
            $('body').css({paddingRight: '', overflowY: ''});
        },
    });

    $.fn.callEvent = function(name, event, model) {
        var $this = $(this);
        var dotIndex = name.indexOf('.zui.');
        var shortName = dotIndex < 0 ? name : name.substring(0, dotIndex);
        var e = $.Event(shortName, event);

        if((model === undefined) && dotIndex > 0) {
            model = $this.data(name.substring(dotIndex + 1));
        }

        if(model && model.options) {
            var func = model.options[shortName];
            if(typeof func === 'function') {
                e.result = $.zui.callEvent(func, e, model);
            }
        }
        $this.trigger(e);
        return e;
    };

    $.fn.callComEvent = function(component, eventName, params) {
        if (params !== undefined && !Array.isArray(params)) {
            params = [params];
        }
        var $this = this;
        var result;
        $this.trigger(eventName, params);

        var eventCallback = component.options[eventName];
        if (eventCallback) {
            result = eventCallback.apply(component, params);
        }
        return result;
    };
}(jQuery, window, undefined));



$(function()
{
    if(window.innerWidth < 768)
    {
        $('.icon-search').click(function()
        {
            location.href = `/book-search-${$('#bookSearch').val()}.mhtml`;
        });

        var clipboard = new ClipboardJS('.url-copy');
        clipboard.on('success', function(e)
        {
            $(e.trigger).popover('destroy');
            $(e.trigger).popover('show');
            setTimeout(function(){$(e.trigger).popover('hide');}, 2000);
        });

        $('.catalogue.chapter > span').click(function()
        {
            if($(this).parent().hasClass('closed'))
            {
                $(this).parent().removeClass('closed').addClass('opened');
            }
            else
            {
                $(this).parent().removeClass('opened').addClass('closed');
            }
        });
    }
});

$(document).ready(function()
{
    /* Scroll function. */
    function yrScroll()
    {
        var listTitleHeight = $(".book-catalog .panel-heading").height();

        var catalogWidth  = $('.book-catalog').width();
        var catalogHeight = $(window).height() - $('#header').height() - $('#footer').height() - 34;
        $(".book-catalog").css({'max-height': catalogHeight, 'overflow-y': 'auto', 'overflow-x': 'hidden'});

        if($('.books .active').length)
        {
            var listScrollTop =  $(".books .active").position().top;
            var listMoveSize = listScrollTop > ( $(".bookScrollListsBox").height() - listTitleHeight ) / 2 ? listScrollTop : 0;
            var scrollMoveSize = listMoveSize / $(".books").height();
            $(".bookScrollListsBox").scrollTop
            (
                $(".bookScrollListsBox .books").height() * scrollMoveSize -($(".bookScrollListsBox").height() / 2 - $(".bookScrollListsBox .panel-heading").height() - 47)
            );
        }


        /* Bind scroll event */
        $(document).on("scroll", function ()
        {
            if( $("#book").offset()) var headerHeight = $("#book").offset().top;
            if( $('.col-md-9').offset()) { var footerHeight = $('.col-md-9').offset().top + $('.col-md-9').height() - $(window).height();}

            $(".page-wrapper").css({"min-height":$(".book-catalog").height()})
            if($(document).scrollTop() > headerHeight )
            {
                $('.book-catalog').css({'position': 'fixed', 'top':'130px', 'width': $('.col-md-3').width()});
                var catalogLeft = $('.col-md-9').offset().left + $('.col-md-9 header').width() + 50;
                if($('.col-md-9 .icon-double-angle-right').hasClass('expand'))
                    $('.catalog-wrap').css({'position': 'fixed', 'left': catalogLeft, 'top': '130px'});
                if(!$('.col-md-3').hasClass('hide-sidebar'))
                {
                    var left = $('.col-md-3').offset().left + $('.col-md-3 .book-catalog').width();
                    $('.col-md-3 .sidebar-toggle').css({'position': 'fixed', 'left': left + 14, 'top': '130px', 'right': 'unset', 'height': $('.book-catalog').height()});
                    $('.resize-bar').removeClass('hide').css({'position': 'fixed', 'left': left + 5, 'top': '130px', 'right': 'unset', 'height': $('.book-catalog').height()});
                }
                else
                {
                    $('.col-md-3 .sidebar-toggle').css({'position': 'fixed', 'left': $('.col-md-3').offset().left + 14, 'top': '140px', 'right': 'unset', 'height': $('.book-catalog').height()});
                    $('.resize-bar').addClass('hide');
                }
                $('.catalog-wrap .icon-double-angle-right').css({'position': 'fixed','left': $('.col-md-9').offset().left + $('.col-md-9').width(), 'right': 'unset', 'top': '130px'});
                if($(document).scrollTop() > footerHeight)
                {
                    catalogHeight2 = $(window).height() - $('#header').height() - $('.blocks.all-bottom').outerHeight() - $('#footer').outerHeight() - 34;
                    $('.book-catalog').css({'max-height': catalogHeight2, 'overflow-y': 'auto', 'overflow-x': 'hidden'});
                    $('.sidebar-toggle, .resize-bar').css('max-height', catalogHeight2);
                }
                else
                {
                    $('.book-catalog').css({'max-height': catalogHeight, 'overflow-y': 'auto', 'overflow-x': 'hidden'});
                    $('.sidebar-toggle, .resize-bar').css('max-height', catalogHeight);
                }
                $('.book-content h4').each(function(idx, item)
                {
                    if($(item).offset().top - $(document).scrollTop()  < 300)
                    {
                        var currentId = $(item).attr('id');
                        $(`.catalog-wrap a[href='#${currentId}']`).parent('li').addClass('active').siblings().removeClass('active');
                    }
                })
                if($(document).scrollTop() + $('.catalog-wrap').height() + 120 > $('.book-content footer').offset().top)
                    $('.catalog-wrap').hide();
                else
                    $('.catalog-wrap').show();
            }
            else if( $(document).scrollTop() < headerHeight )
            {
                $('.book-catalog').css({'position': 'relative', 'top': '0px'});
                $('.catalog-wrap').css({'position': 'absolute', 'top': '10px', 'left': 'auto'});
                if(!$('.col-md-3').hasClass('hide-sidebar'))
                {
                    $('.col-md-3 .sidebar-toggle').css({'position': 'absolute', 'left': 'unset', 'top': '24px', 'right': '-6px'});
                    $('.resize-bar').removeClass('hide').css({'position': 'absolute', 'left': 'unset', 'top': '24px', 'right': '8px', 'height': '100%'});
                }
                else
                {
                    $('.col-md-3 .sidebar-toggle').css({'position': 'absolute', 'left': '14px', 'top': '24px', 'right': 'unset'});
                    $('.resize-bar').addClass('hide');
                }
                $('.catalog-wrap .icon-double-angle-right').css({'position': 'absolute','left': 'unset', 'right': '-10px', 'top': '10px'});
            }
        });
    };
    yrScroll();

    $(document).on('click', $('.catalog-wrap li a'), function(e)
    {
        $(e.target).parent('li').addClass('active').siblings().removeClass('active');
        var selector = $(e.target).attr('href');
        if(selector)
        {
            setTimeout(function()
            {
                $('html').animate(
                {
                    'scrollTop': $(selector).offset().top - 140
                }, 400);
            }, 0);
        }
    });

    $('dd span').off('click').click(function()
    {
        if($(this).parent().hasClass('opened'))
        {
            $(this).parent().addClass('closed').removeClass('opened');
        }
        else
        {
            $(this).parent().addClass('opened').removeClass('closed');
        }
    });

    $('.return-back').click(function()
    {
        window.history.go(-1);
    });

    $('.col-md-3 .sidebar-toggle').click(function()
    {
        if($(this).hasClass('expand'))
        {
            $(this).addClass('collapse').removeClass('expand');
            $(this).parent('.col-md-3').addClass('hide-sidebar');
            $(this).parent('.col-md-3').find('.book-catalog').addClass('hide');
            $(this).parent().siblings('.col-md-9').css('width', 'calc(100% - 20px)');
            if($(document).scrollTop() > $('#book').offset().top)
                $(this).css({'left': $('.col-md-3').offset().left + 14, 'height': $('.book-catalog').height()});
            else
                $(this).css({'height': $('.book-catalog').height()});
            $('.resize-bar').addClass('hide');
        }
        else
        {
            $(this).addClass('expand').removeClass('collapse');
            $(this).parent('.col-md-3').removeClass('hide-sidebar');
            $(this).parent().siblings('.col-md-9').css('width', $('.col-md-3').parent('.row').width() - parseFloat($('.col-md-3').css('width') || $('.col-md-3').width()));
            $(this).parent('.col-md-3').find('.book-catalog').removeClass('hide');
            $('.resize-bar').removeClass('hide');
            if($(document).scrollTop() > $('#book').offset().top)
            {
                $(this).css('left', $('.col-md-3').offset().left + $('.col-md-3 .panel').width() + 14);
                $('.resize-bar').css({left: $('.col-md-3').offset().left + $('.col-md-3 .panel').width() + 8});
            }
            else
            {
                $(this).css({'left': 'unset', 'right': '-6px'});
                $('.resize-bar').css({'position': 'absolute', 'right': '8px', 'left': 'unset', 'height': '100%', 'top': 0});
                $('.col-md-3 .panel').css('width', $('.col-md-3').width());
            }
        }
    });

    $(document).on('click', '.catalog-wrap .icon-double-angle-right', function()
    {
        if($(this).hasClass('expand'))
        {
            $(this).addClass('collapse').removeClass('expand');
            $(this).parents('.col-md-9').find('header, .article-content').css('width', '100%');
            $('.catalog-wrap h3, .catalog-wrap ul').addClass('hide');
            if($(document).scrollTop() > $('#book').offset().top)
                $('.col-md-9 .icon-double-angle-right.collapse').css({'position': 'fixed','left': $('.col-md-9').offset().left + $('.col-md-9').width()});
        }
        else
        {
            $(this).addClass('expand').removeClass('collapse');
            $(this).parents('.col-md-9').find('header, .article-content').css('width', 'calc(100% - 270px)');
            $('.catalog-wrap h3, .catalog-wrap ul').removeClass('hide');
            if($(document).scrollTop() > $('#book').offset().top)
            {
                $('.col-md-9 .icon-double-angle-right.expand').css({'position': 'fixed','left': $('.col-md-9').offset().left + $('.col-md-9').width()});
                $('.catalog-wrap').css({'position': 'fixed', 'left': $('.col-md-9 header').offset().left + $('.col-md-9 header').width() + 50, 'top': '130px'});
            }
        }
    });

    if($('.catalog-wrap').length === 0)
    {
        $('.book-content header, .book-content .article-content').css('width', '100%');
    }

    $('.col-md-3 dd a').click(function()
    {
        setTimeout(function()
        {
            if($('.catalog-wrap').length === 0)
            {
                $('.book-content header, .book-content .article-content').css('width', '100%');
            }
        }, 200);
    });

    $('#bookSearch').keydown(function(e)
    {
        if(e.keyCode === 13)
        {
            location.href = `/book-search-${e.target.value}.html`;
        }
    });

    var currentPosition = $('.resize-bar').offset().left;
    $('.resize-bar').droppable(
    {
        target: 'droppable-target',
        drag: function(e)
        {
            var offsetX = currentPosition - e.offset.left;
            if(offsetX < 220 && offsetX > -500)
            {
                $('.col-md-3').css({'width': 292 - offsetX, 'transition': 'width 0s'});
                $('.col-md-9').css({'width': 877 + offsetX, 'transition': 'width 0s'});
                $('.book-catalog').css('width', $('.col-md-3').width());
                if($(document).scrollTop() > $('#book').offset().top)
                {
                    var dragLeft = $('.col-md-3').width() + $('.col-md-3').offset().left;
                    $('.sidebar-toggle').css('left', dragLeft + 14);
                    $('.resize-bar').css('left', dragLeft + 8);
                }
            }
        }
    });
});
$('#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 minScrollHeight = windowScrollHeight - $('#header').height() - $('#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).click(function(e) {
    if($(this).children('html').hasClass('m-user-login')) {
        return
    } else {
        $('#loginModal').hide();
        if(window.qrCodeTimer) clearInterval(window.qrCodeTimer);
    }
})
$(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({
            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();
            $.get('/user-getquestionnaire-1.html', function(res)
            {
               if(res.result !== 'fail')
               {
                    shwoDemoQuestion($(item).attr('href'));
               }
               else 
               {
                   window.open($(item).attr('href'));
               }
            });
        });
    }
});$('.fullScreen-book .fullScreen-catalog .panel-heading').insertAfter('.fullScreen-book .fullScreen-header > #siteLogo');
$('.fullScreen-book .fullScreen-header .title').insertBefore('.fullScreen-book .fullScreen-header .dropdown');
$('.fullScreen-book').parent().addClass('wide-screen');
$('.fullScreen-book .fullScreen-header .book-search .form-control').attr('placeholder','搜索');
$('iframe').wrap('<div class="iframe-box"></div>');
$('.bookScrollListsBox .dropdown').click(function(){
    if(!$(this).hasClass('open')) {
        $(this).parent().siblings('.panel-body').css({'minHeight': $(this).find('.dropdown-menu').height() + 20 + 'px'})
    } else {
        $(this).parent().siblings('.panel-body').css({'minHeight': 0})
    }
})
$('.nav-content a').click(function(){
    if($(this).attr('href')) {
        setTimeout(() => {
            window.scrollTo({
                top: $($(this).attr('href'))[0].offsetTop - 120
            })
        }, 100)
    }
})
$(document).ready(function(){
    if(location.href.includes('#')) 
    {
        var element = location.href.split('#')[1];
        setTimeout(() => {
            window.scrollTo({top: $('#' + element)[0].offsetTop - 120})
        }, 100)
    }
})

var windowScrollHeight = window.innerHeight;
var minScrollHeight = windowScrollHeight - $('#header').height() - $('#footer').height() - 54;
if($('.page-wrapper').height() < minScrollHeight) {
    $('.page-wrapper').css('minHeight', minScrollHeight)
}
;
$(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));
;v.messageUrl = "\/message-comment-book-90.html";;
    $('#commentBox').load(v.messageUrl);
