/** * Created by troy on 5/17/2015. */ $(function () { // Adds browser version on html class. $.browserSelector(); var $html = $('html'), $isMobile = $html.hasClass('mobile'), $width = $(window).width(); /********** lte IE 8 *************/ /* if ($html.hasClass('ie')) { if ($html.hasClass('ie6') || $html.hasClass('ie7')) { location.href = "/ie_upgrade.html"; } } */ /********** for smooth scroll *************/ // Adds window smooth scroll on chrome. if ($html.hasClass("chrome") || $html.hasClass('ie11')) { $.smoothScroll(); } /********** iPad orientation refresh *************/ // to prevent the menu&mobile-menu switch error if ($isMobile && (($width - 800) * ($(window).height() - 800)) < 0) { // to ensure the 'landscape' is wide and 'portrait' is confined. window.addEventListener('orientationchange', function () { location.reload(); }); } /********** for top line wechat QR code *************/ if (!$isMobile) { // desktop mouse $("#wechat").hover( function () { $("#wechat-QR").show(); }, function () { $("#wechat-QR").hide(); } ); } else { // mobile touch screen $("#wechat").click( function () { var wechat = $("#wechat-QR"); if (wechat.css('display') == 'block') wechat.hide(); else wechat.show(); } ); } /***************** for navigation ***************/ if ($isMobile && $width >= 960) { // prevent touch event to jump to another page. $('nav dt a').removeAttr('href'); } var wgt = $('.wgt-navbar'); if (!$isMobile) { // desktop !function () { var timer = ''; wgt.on('mouseenter', 'dl', function () { clearTimeout(timer); // hover delay timer = setTimeout(function () { wgt.addClass('wgt-navbar-hover'); }, 300); }).on('mouseleave', function () { clearTimeout(timer); wgt.removeClass('wgt-navbar-hover'); }).on('click', 'a', function () { clearTimeout(timer); wgt.removeClass('wgt-navbar-hover'); }); }(); } else if ($width >= 960) { // wide touch screen $('.wgt-navbar dt a').click(function () { if (wgt.hasClass('wgt-navbar-hover')) { wgt.removeClass('wgt-navbar-hover'); } else { wgt.addClass('wgt-navbar-hover'); } }) } else if ($width <= 480) { // confined touch screen,mobile nav $('#mobile-nav-icon').click(function () { var topLine = $('.top-line'); var mobileNav = $('#mobile-nav'); if (topLine.hasClass('show-nav')) { topLine.removeClass('show-nav'); mobileNav.slideUp(200); } else { topLine.addClass('show-nav'); mobileNav.slideDown(200); } }); } /******************** for index slider ********************/ try { if ($html.hasClass('ie8')||$html.hasClass('ie9')){ var swiper=new Swiper('#main-swiper', { mode:'horizontal', loop: true, autoplay: 5000, pagination: '.swiper-pagination', paginationClickable: true }); $('.swiper-button-prev').on('click', function(e){ e.preventDefault(); swiper.swipePrev(); }) $('.swiper-button-next').on('click', function(e){ e.preventDefault(); swiper.swipeNext(); }) }else if ($isMobile) { // mobile new Swiper('#main-swiper', { pagination: '.swiper-pagination', paginationClickable: false, speed: 1000, autoplay: 5000, autoplayDisableOnInteraction: true, loop: true, parallax: true }); $('.swiper-button-prev').removeClass('swiper-button-prev'); $('.swiper-button-next').removeClass('swiper-button-next'); } else { // desktop new Swiper('#main-swiper', { pagination: '.swiper-pagination', paginationClickable: false, nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', speed: 1000, autoplay: 5000, autoplayDisableOnInteraction: true, loop: true, parallax: true }); } } catch (e) { //console.log("no swiper"); } /***************** for key access list ***************/ if ($width > 800) { $("#list-pic-tab").find("li").mouseenter( function () { if (!$(this).hasClass("current")) { $("#list-pic-tab").find("li").removeClass("current"); $(this).addClass("current"); $(".list-image").find("div").hide(); $(".list-image a:nth-child(" + $(this).data("order") + ") div").show(); } } ); } else { $('#list-pic-tab').find('li').first().removeClass('current'); } /***************** for quick link ***************/ if ($width > 800 && !$isMobile) { $("#quick-link").find('li').hover( function () { $(this).addClass('current'); $(this).parent().addClass('hover'); }, function () { $(this).parent().removeClass('hover'); $(this).removeClass('current'); } ); } /***************** for sub-page menu ***************/ var $menu = $('#menu'); if ($menu.length > 0) { if ($width > 768) { // desktop menu /***************** for sub-page menu current confirm ***************/ $menu.find('a').each(function () { if ($(this).attr('href') === 'index.htm') { $(this).parent().addClass('current'); return false; } }); /***************** calc sub-page menu background height ***************/ var count = $menu.find("li").length; $menu.find('.background').css("height", count * 50); /***************** for sub-page menu hover ***************/ if (!$isMobile) { $menu.lavaLamp({ fx: "backout", speed: 500, click: function (event, menuItem) { } }); } else { $menu.find('.current').addClass('hover'); } /***************** keep sub-page menu remain in sight ***************/ var menu = $(".menu"), content = $(".main-content"); var menuTop = menu.offset().top - 40; var menuWidth = menu.width(); var contentLeft = content.offset().left - menu.offset().left; $(window).scroll(function () { var lowest = Math.max(content.height() - menu.height(), 0); if (lowest != 0) lowest += content.offset().top; if (lowest == 0) return;// content.height < menu.height, no need to move var curTop = $(window).scrollTop(); if (curTop < menuTop) { // init menu.removeAttr('style'); content.removeAttr('style'); } else if (curTop > lowest - 40) { // reach bottom menu.css({"position": "relative", "marginTop": lowest - menuTop}); content.removeAttr('style'); } else { // fixed menu.css({"position": "fixed", "marginTop": 40, "width": menuWidth}); content.css("marginLeft", contentLeft); } }) } else { // mobile menu $('.menu #svg-icons').click(function () { var menuWrapper = $('.menu'); if (menuWrapper.hasClass('show-nav')) { menuWrapper.removeClass('show-nav'); $menu.slideUp(200); } else { menuWrapper.addClass('show-nav'); $menu.slideDown(200); } }); } } /***************** top line search submit simulate ***************/ $('.top-search').click( function () { $('form.search').submit(); } ); /***************** articles like

clear text-indent ***************/ $('.content p').find('img').parent().css('textIndent', '0'); /***************** index bgpt & xnmh LAN/WAN switch ***************/ if ($('.bgpt').length) { // check if a small image in 'bgpt' can be accessed $.can_access('/Uploads/201701/5875e0f8508dd.gif', function (e) { $('.bgpt').each(function(){ $(this)[0].href = '#'; }) }, null); } if ($('.xnmh').length) { // check if a small image in 'xnmh' can be accessed $.can_access('/Uploads/201701/5875e0f8508dd.gif', function (e) { $('.xnmh').each(function(){ $(this)[0].href = '#'; }) }, null); } });