window.onload = function() { $(".main-content .header .practice-area .area-list .dropdown span,.main-content .header .practice-area .area-list img").click(function(){ $(".main-content .header .practice-area .area-list .dropdown ul").toggleClass('hidden'); }); $(".main-content .header .practice-area .area-list .dropdown ul").mouseleave(function(){ $(".main-content .header .practice-area .area-list .dropdown ul").addClass('hidden'); }); $(".main-content .content .overview .list .item").off('click hover').on('click',function(){ $(this).addClass('active'); $(this).siblings().removeClass('active'); var index = $(".main-content .content .overview .list .item").index(this); var $item = $(".main-content .content .overview .short-description .item").eq(index); $item.siblings().removeClass('active'); $item.addClass('active'); }); $(".main-content .margin-dynamic").css("margin-top",$("body > div.container-fluid.topics > div > div").height()-50 +"px"); $(".main-content .content .overview .list .item").hover(function(){ $(this).addClass('active'); $(this).siblings().removeClass('active'); var index = $(".main-content .content .overview .list .item").index(this); var $item = $(".main-content .content .overview .short-description .item").eq(index); $item.siblings().removeClass('active'); $item.addClass('active'); }); $(".main-content .content .show-more-guidance").click(function(){ $(this).toggleClass('expanded'); if($(this).hasClass('expanded')){ $(".main-content .content .guidance.overflow").removeClass('hidden'); $("#guidance-expand-text").html("Collapse Guidance"); } else{ $(".main-content .content .guidance.overflow").addClass('hidden'); $("#guidance-expand-text").html("Show All Guidance"); } }); $(".main-content .content .legislation .legislation-list li").click(function(){ $(this).addClass('active'); $(this).siblings().removeClass('active'); var index = $(".main-content .content .legislation .legislation-list li").index(this); var $item = $(".main-content .content .legislation .citation-list .citation-item").eq(index); $item.siblings().removeClass('active'); $item.addClass('active'); }); $("a[data-func]").click(function (e) { var $target = $(e.currentTarget), topicId=$("#topicId").val(), subTopicId=$("#subTopicId").val(), docfullpath = $target.data("docfullpath"); if(!subTopicId){ subTopicId = $target.closest("div.body").data("subtopicid"); } if(docfullpath){ var docId = docfullpath.split(':').pop(); $target.attr("href",topicId + "_"+subTopicId+"_"+docId+".html"); } }); $(window).scroll(function (event) { scrollCallback(); }); var resizeHandler = null; $(window).resize(function(){ clearTimeout(resizeHandler); resizeHandler = setTimeout(function(){ topicNavPages = calcTopicNavigationPageNumbers(); initTopicNav(); },300); }); var padding = { left: 40, right: 40 }; var topicNavPages = calcTopicNavigationPageNumbers(); var currentPageNo = 1; $(".topics .prev-btn").click(function(){ if(currentPageNo==1){ return; } else{ currentPageNo--; updateTopicsNavState(currentPageNo, true); } }); $(".topics .next-btn").click(function(){ if(currentPageNo== topicNavPages.length){ return; } else{ currentPageNo++; updateTopicsNavState(currentPageNo, true); } }); // 初始化 initTopicNav(); scrollCallback(); function updateTopicsNavState(pageNo, hasAnimation){ $(".topics .prev-btn").toggleClass('hidden',pageNo ==1); $(".topics .next-btn").toggleClass('hidden',pageNo ==topicNavPages.length); var newOffset = topicNavPages[pageNo-1].offset; if(pageNo >1){ //fix the padding-left space newOffset = newOffset + parseInt( $('.topics .item:nth-child(2)').css('padding-left'),10) } if(hasAnimation){ $('.topics .list').animate({ left: (newOffset * -1) + "px" }, { queue: false, speed: 400 }); } else{ $('.topics .list').css( "left", (newOffset * -1) + "px" ); } var $viewportContainer = $('.topics .list').parent(); var viewportWidth = $viewportContainer.width(); var topicFullWidth =$('.topics .list').width(); $viewportContainer.toggleClass('ellipsis', topicFullWidth > viewportWidth && pageNo < topicNavPages.length); } function initTopicNav(){ if(topicNavPages.length == 1 || $('.topics .list .item .active').length == 0){ currentPageNo =1; updateTopicsNavState(currentPageNo, false); return; } var activeOffset = $('.topics .list .item .active').offset().left - $('.topics .list').offset().left; for (let index = 1; index < topicNavPages.length; index++) { var topicNav = topicNavPages[index]; if (topicNav.offset + padding.left > activeOffset) { currentPageNo = topicNav.num -1; updateTopicsNavState(currentPageNo, false); break; } if(index == topicNavPages.length - 1){ currentPageNo = topicNav.num ; updateTopicsNavState(currentPageNo, false); break; } } } function calcTopicNavigationPageNumbers(){ var pages = []; var topicItems = $('.topics .list .item'); var viewportWidth = $(".topics .container").width(); pages.push({ num: 1, offset: 0}); var currentPageWidth =0; var currentPageStartTopicIndex = 0; var hasRightPadding = false; var hasLeftPadding = false; var reCalculate = false; for (let index = 0; index < topicItems.length; index++) { var ele = topicItems.get(index); var actualViewportWidth = hasLeftPadding ? viewportWidth - padding.left : viewportWidth; actualViewportWidth = hasRightPadding ? viewportWidth -padding.right : actualViewportWidth; if(currentPageWidth + $(ele).outerWidth() < actualViewportWidth){ currentPageWidth += $(ele).outerWidth(); continue; } else{ // 正在计算第二页的起始位置 if(pages.length == 1){ if(!reCalculate){ // 重新开始计算第一页的宽度,也就是第二页的起始位置 reCalculate = true; hasLeftPadding = true; currentPageWidth = 0; index = currentPageStartTopicIndex; index--; } else{ var lastPage = pages[pages.length -1]; pages.push({num: lastPage.num + 1, offset: lastPage.offset + currentPageWidth - padding.left}); currentPageWidth = $(ele).outerWidth();// 超出的宽度计入下一页宽度 currentPageStartTopicIndex = index; reCalculate = false; } continue; } else{ // 正在计算第三,四....页的起始位置 if(!hasRightPadding){ hasRightPadding = true; currentPageWidth = 0; index = currentPageStartTopicIndex; index--; } else{ var lastPage = pages[pages.length -1]; pages.push({num: lastPage.num + 1, offset: lastPage.offset + currentPageWidth}); currentPageWidth = $(ele).outerWidth();// 超出的宽度计入下一页宽度 currentPageStartTopicIndex = index; hasRightPadding = false;//假设下一页不需要后一页按钮 } continue; } } } return pages; } var rightTrialHeight = $('.rigt-free-trial-link').height(); function scrollCallback(){ var top = document.body.scrollTop == 0 ? document.documentElement.scrollTop : document.body.scrollTop; if(top> $('.top-banner').height()){ $('body > .container-fluid.topics').addClass('always-top'); } else{ $('body > .container-fluid.topics').removeClass('always-top'); } if(top> $('.top-banner').height() + rightTrialHeight){ var bottomHeight = $('.bottom-footer').height() + $('.footer-links').height(); var leftBottomSpace = $(document).height() - top - rightTrialHeight; console.log($(document).height(), top,rightTrialHeight, leftBottomSpace, bottomHeight); if(leftBottomSpace >bottomHeight){ $('.rigt-free-trial-link').addClass('always-right').css("top", "0px"); } else{ $('.rigt-free-trial-link').addClass('always-right').css("top", leftBottomSpace -bottomHeight -11 + "px"); } } else{ $('.rigt-free-trial-link').removeClass('always-right'); } } }