/* jshint asi:true */

/**
 * [fixSidebar description]
 * 滚轮滚到一定位置时，将 sidebar-wrap 添加 fixed 样式
 * 反之，取消样式
 */
(function() {
    if (window.innerWidth > 770) {

        var sidebarWrap = document.querySelector('.right>.wrap')

        //fix 之后百分比宽度会失效，这里用js赋予宽度
        sidebarWrap.style.width = sidebarWrap.offsetWidth + "px"
        window.onscroll = function() {
            var sidebarWrapTop = sidebarWrap.getBoundingClientRect().top
            if (sidebarWrapTop < 21) {
                sidebarWrap.classList.add('fixed')
            }
            var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
            if (scrollTop < 77) {
                sidebarWrap.classList.remove('fixed')
            }
        }
    }
}());


//-------------mobile--------------
/**
 * 屏幕宽度小于770px时，点击锚点按钮，弹出目录框
 * @param  {[type]} function( [description]
 * @return {[type]}           [description]
 */
(function() {
    if (window.innerWidth <= 770) {
        var anchorBtn = document.querySelector('.anchor')
        var rightDiv = document.querySelector('.right')

        /**
         * 监听锚点按钮
         */
        anchorBtn.onclick = function(e) {
            e.stopPropagation()
            rightDiv.classList.add('right-show')
            anchorBtn.classList.add('anchor-hide')
        }

        //监听body，点击body，隐藏Content
        document.querySelector('body').addEventListener('click', function() {
            rightDiv.classList.remove('right-show')
            anchorBtn.classList.remove('anchor-hide')
        })

        ancherPostion(anchorBtn, rightDiv)
        setContentMaxHeight()
    }
}());

/**
 * 目录锚的位置固定
 */
function ancherPostion(anchorBtn, rightDiv) {
    window.addEventListener('scroll', function() {
        // console.log('scroll');
        var top = anchorBtn.getBoundingClientRect().top
            // console.log(top);
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
        if (scrollTop > 50) {
            anchorBtn.style.top = '20px'
            rightDiv.style.top = '20px'
        } else {
            anchorBtn.style.top = '76px'
            rightDiv.style.top = '76px'
        }
    })
}

/**
 * 设置目录最大高度
 */
function setContentMaxHeight() {
    var windowHeight = window.innerHeight
    var contentUl = document.querySelector('.content-ul')
    var contentMaxHeight = windowHeight-180
    contentUl.style.maxHeight = contentMaxHeight + 'px'
}

@@ -749,23 +749,319 @@
   %7D%0A    
-%7D%0A%7D());
+    setContentMaxHeightInPC()%0A    %7D%0A%7D());%0A%0A/**%0A * %E8%AE%BE%E7%BD%AE%E7%9B%AE%E5%BD%95%E6%9C%80%E5%A4%A7%E9%AB%98%E5%BA%A6%0A */%0Afunction setContentMaxHeightInPC() %7B%0A    var windowHeight = window.innerHeight%0A    var contentUl = document.querySelector('.content-ul')%0A    var contentMaxHeight = windowHeight-77-60%0A    contentUl.style.maxHeight = contentMaxHeight + 'px'%0A%7D
 %0A%0A%0A//---

set max height in pc