(function($) { "use strict"; //fix back forward cache issue: http://stackoverflow.com/questions/11979156/mobile-safari-back-button $(window).bind("pageshow", function(event) { if (event.originalEvent.persisted) { avia_site_preloader(); } }); $(document).ready(function() { //alert('ok'); //check if user uses IE7 - if yes don't execute the function or the menu will break awork_responsive_menu(); awork_adjust_menu_position(); $(window).resize(function() { awork_adjust_menu_position(); var browser_width = document.body.clientWidth; //在mobile状态下点击菜单后,放大,还出现菜单及图标 //if( $(".awork-menu .menu-icon").css("display") == "none" ){ if( browser_width>1024 ){ $("#awork-menu ul.menu-mobile").css("display","none");//--隐藏移动菜单--- $(".awork-menu .menu-icon .icon-close").css("display","none");//--隐藏移动菜单后隐藏图标,以防再次缩小时出现关闭按钮-- $(".awork-menu .menu-icon .icon-menu").css("display","block"); $(".menu-icon").css('display', 'none'); }else{ if( $("#awork-top-search").css("display") == "none" ){ $(".menu-icon").css('display', 'block'); } } //if( $("header .header-wrap .awork-menu ul.menu span") == "none" ){}else{$(".awork-menu .menu-icon .icon-menu").css("display"," none");} //注: 当在移动状态下点击search时,然后拉大,在正常状态下关闭,移动状态下的菜单不会隐藏 //先点搜索,再点菜单,拉大之后菜单不会消失 }); }); // ------------------------------------------------------------------------------------------- // responsive menu function // ------------------------------------------------------------------------------------------- function awork_responsive_menu() { $('#awork-menu ul.menu span').clone().attr('id','awork-mobile-menu').removeClass().attr('class','awork-mobile-menu').appendTo( $("#awork-menu ul.menu-mobile") ); $(".menu-icon").click(function(){ $(".awork-menu .menu-icon .icon-close").toggle(); $(".awork-menu .menu-icon .icon-menu").toggle(); $("#awork-menu ul.menu-mobile").toggle(500); }); $(".icon-search").click(function(){ $(".menu-icon").css('display', 'none'); $("#awork-menu ul.menu").css('display', 'none'); $("#awork-top-search").slideDown("slow"); //$("#awork-top-search").slideDown( 500 ); var browser_width = document.body.clientWidth; if( browser_width>1024 ){ $(".menu-icon").css('display', 'none'); } }); $(".awork-close-search-field").click(function(){ $(".menu-icon").css('display', 'block');//显示菜单图标 //$(".menu-icon").slideDown("slow"); $("#awork-menu ul.menu").css('display', 'block');//显示菜单 //$("#awork-menu ul.menu").slideDown("slow"); $("#awork-top-search").css('display', 'none');//隐藏搜索 var browser_width = document.body.clientWidth; if( browser_width>1024 ){ $(".menu-icon").css('display', 'none'); } //if(!$("header .header-wrap .awork-menu ul.menu span") == "none" )$(".awork-menu .menu-icon .icon-menu").css("display"," none"); }); } function awork_adjust_menu_position() { var width = $('.header-wrap').width(), logo_width = $('.awork-logo').width(), header_height = $('.header').height(), browser_width = document.body.clientWidth //css = "", //css_box = $("").appendTo('head:first') ; $("#awork-top-search").css('width', width-logo_width-20); $("#awork-top-search").css('paddingTop', (header_height-25)/2 ); $("#awork-top-search .awork-search-form input").css('max-width', width-logo_width-60 ); $(".awork-menu ul.menu li.menu-item-has-children ul.sub-menu").has(".menu-item-has-children").css('width', width); $(".awork-menu ul.menu li.menu-item-has-children ul.sub-menu").has(".menu-item-has-children").css('right', (( browser_width - width) /2) ); $(".awork-menu ul.menu li.menu-item-has-children ul.sub-menu").has(".menu-item-has-children").css('top', ( header_height-30)); $(".awork-menu ul.menu li.menu-item-has-children ul.sub-menu").has(".menu-item-has-children").addClass("sub-menu-width"); var num = $('.awork-menu ul.menu li.menu-item-has-children ul.sub-menu-width').children('li').length; if(num == 3 ){ $("header .header-wrap .awork-menu ul.menu li ul.sub-menu-width li").css('width', '33%'); } if(num == 2 ){ $("header .header-wrap .awork-menu ul.menu li ul.sub-menu-width li").css('width', '50%'); } $("header .header-wrap .awork-menu ul.menu li ul.sub-menu li ul.sub-menu li").css('width', '100%'); //alert(num); $("header .header-wrap .awork-menu ul.menu li ul li").parent(".sub-menu-width").find("li").css("background-color", "transparent"); // $("header .header-wrap .awork-menu ul.menu li").css('height', header_height); $("header .header-wrap .awork-menu ul.menu li ul li").css('height','auto'); //css += ".awork-menu ul.menu li.menu-item-has-children ul.sub-menu{right:" + (( browser_width - width) /2)+ "px;top:" + ( header_height-30)+ "px; }"; //css += "header .header-wrap .awork-menu ul.menu li{height:" + header_height+ "px; }"; /* try{ css_box.text(''); css_box.text(css); } catch(err){ css_box.remove(); css_box = $("").appendTo('head:first'); } */ } // ------------------------------------------------------------------------------------------- // Smooth scrooling when clicking on anchor links // todo: maybe use https://github.com/ryanburnette/scrollToBySpeed/blob/master/src/scrolltobyspeed.jquery.js in the future // ------------------------------------------------------------------------------------------- (function($) { $.fn.avia_smoothscroll = function(apply_to_container) { if(!this.length) return; var the_win = $(window), $header = $('#header'), $main = $('.html_header_top.html_header_sticky #main').not('.page-template-template-blank-php #main'), $meta = $('.html_header_top.html_header_unstick_top_disabled #header_meta'), $alt = $('.html_header_top:not(.html_top_nav_header) #header_main_alternate'), shrink = $('.html_header_top.html_header_shrinking').length, frame = $('.av-frame-top'), fixedMainPadding = 0, isMobile = $.avia_utilities.isMobile, sticky_sub = $('.sticky_placeholder:first'), calc_main_padding= function() { if($header.css('position') == "fixed") { var tempPadding = parseInt($main.data('scroll-offset'),10) || 0, non_shrinking = parseInt($meta.outerHeight(),10) || 0, non_shrinking2 = parseInt($alt.outerHeight(),10) || 0; if(tempPadding > 0 && shrink) { tempPadding = (tempPadding / 2 ) + non_shrinking + non_shrinking2; } else { tempPadding = tempPadding + non_shrinking + non_shrinking2; } tempPadding += parseInt($('html').css('margin-top'),10); fixedMainPadding = tempPadding; } else { fixedMainPadding = parseInt($('html').css('margin-top'),10); } if(frame.length){ fixedMainPadding += frame.height(); } }; if(isMobile) shrink = false; calc_main_padding(); the_win.on("debouncedresize av-height-change", calc_main_padding); var hash = window.location.hash.replace(/\//g, ""); //if a scroll event occurs at pageload and an anchor is set and a coresponding element exists apply the offset to the event if (fixedMainPadding > 0 && hash && apply_to_container == 'body' && hash.charAt(1) != "!" && hash.indexOf("=") === -1) { var scroll_to_el = $(hash), modifier = 0; if(scroll_to_el.length) { the_win.on('scroll.avia_first_scroll', function() { setTimeout(function(){ //small delay so other scripts can perform necessary resizing if(sticky_sub.length && scroll_to_el.offset().top > sticky_sub.offset().top) { modifier = sticky_sub.outerHeight() - 3; } the_win.off('scroll.avia_first_scroll').scrollTop( scroll_to_el.offset().top - fixedMainPadding - modifier); },10); }); } } return this.each(function() { $(this).click(function(e) { var newHash = this.hash.replace(/\//g, ""), clicked = $(this), data = clicked.data(); if(newHash != '' && newHash != '#' && newHash != '#prev' && newHash != '#next' && !clicked.is('.comment-reply-link, #cancel-comment-reply-link, .no-scroll')) { var container = "", originHash = ""; if("#next-section" == newHash) { originHash = newHash; container = clicked.parents('.container_wrap:eq(0)').nextAll('.container_wrap:eq(0)'); newHash = '#' + container.attr('id') ; } else { container = $(this.hash.replace(/\//g, "")); } if(container.length) { var cur_offset = the_win.scrollTop(), container_offset = container.offset().top, target = container_offset - fixedMainPadding, hash = window.location.hash, hash = hash.replace(/\//g, ""), oldLocation=window.location.href.replace(hash, ''), newLocation=this, duration= data.duration || 1200, easing= data.easing || 'easeInOutQuint'; if(sticky_sub.length && container_offset > sticky_sub.offset().top) { target -= sticky_sub.outerHeight() - 3;} // make sure it's the same location if(oldLocation+newHash==newLocation || originHash) { if(cur_offset != target) // if current pos and target are the same dont scroll { if(!(cur_offset == 0 && target <= 0 )) // if we are at the top dont try to scroll to top or above { // animate to target and set the hash to the window.location after the animation $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() { // add new hash to the browser location //window.location.href=newLocation; if(window.history.replaceState) window.history.replaceState("", "", newHash); }); } } // cancel default click action e.preventDefault(); } } } }); }); }; })(jQuery); // ------------------------------------------------------------------------------------------- // Avia Menu // ------------------------------------------------------------------------------------------- /* (function($) { //alert('ok'); $.fn.aviaMegamenu = function(variables) { var defaults = { modify_position:true, delay:300 }; var options = $.extend(defaults, variables), win = $(window), width_select= $('html').is('.html_header_sidebar') ? "#main" : "#header", the_main = $(width_select + ' .container:first'), css_block = $("").appendTo('head:first'), calc_dimensions = function() { var css = "", w_12 = Math.round( the_main.width() ); css += " #header .three.units{width:" + ( w_12 * 0.25)+ "px;}"; css += " #header .six.units{width:" + ( w_12 * 0.50)+ "px;}"; css += " #header .nine.units{width:" + ( w_12 * 0.75)+ "px;}"; css += " #header .twelve.units{width:" +( w_12 ) + "px;}"; //ie8 needs different insert method try{ css_block.text(css); } catch(err){ css_block.remove(); css_block = $("").appendTo('head:first'); } }; if($('.avia_mega_div').length > 0) { win.on( 'debouncedresize', calc_dimensions); calc_dimensions(); } return this.each(function() { var the_html = $('html:first'), main = $('#main .container:first'), left_menu = the_html.filter('.html_menu_left, .html_logo_center').length, isMobile = $.avia_utilities.isMobile, menu = $(this), menuItems = menu.find(">li:not(.ignore_menu)"), megaItems = menuItems.find(">div").parent().css({overflow:'hidden'}), menuActive = menu.find('>.current-menu-item>a, >.current_page_item>a'), dropdownItems = menuItems.find(">ul").parent(), parentContainer = menu.parent(), mainMenuParent = menu.parents('.main_menu').eq(0), parentContainerWidth = parentContainer.width(), delayCheck = {}, mega_open = []; if(!menuActive.length){ menu.find('.current-menu-ancestor:eq(0) a:eq(0), .current_page_ancestor:eq(0) a:eq(0)').parent().addClass('active-parent-item')} if(!the_html.is('.html_header_top')) { options.modify_position = false; } menuItems.on('click' ,'a', function() { if(this.href == window.location.href + "#" || this.href == window.location.href + "/#") return false; }); menuItems.each(function() { var item = $(this), pos = item.position(), megaDiv = item.find("div:first").css({opacity:0, display:"none"}), normalDropdown = ""; //check if we got a mega menu if(!megaDiv.length) { normalDropdown = item.find(">ul").css({display:"none"}); } //if we got a mega menu or dropdown menu add the arrow beside the menu item if(megaDiv.length || normalDropdown.length) { var link = item.addClass('dropdown_ul_available').find('>a'); link.append(''); //is a mega menu main item doesnt have a link to click use the default cursor if(typeof link.attr('href') != 'string' || link.attr('href') == "#"){ link.css('cursor','default').click(function(){return false;}); } } //correct position of mega menus if(options.modify_position && megaDiv.length) { item.on('mouseenter', function(){ calc_offset(item, pos, megaDiv, parentContainerWidth) }); } }); function calc_offset(item, pos, megaDiv, parentContainerWidth) { pos = item.position(); if(!left_menu) { if(pos.left + megaDiv.width() < parentContainerWidth) { megaDiv.css({right: -megaDiv.outerWidth() + item.outerWidth() }); //item.css({position:'static'}); } else if(pos.left + megaDiv.width() > parentContainerWidth) { megaDiv.css({right: -mainMenuParent.outerWidth() + (pos.left + item.outerWidth() ) }); } } else { if(megaDiv.width() > pos.left + item.outerWidth()) { megaDiv.css({left: (pos.left* -1)}); } else if(pos.left + megaDiv.width() > parentContainerWidth) { megaDiv.css({left: (megaDiv.width() - pos.left) * -1 }); } } } function megaDivShow(i) { if(delayCheck[i] == true) { var item = megaItems.filter(':eq('+i+')').css({overflow:'visible'}).find("div:first"), link = megaItems.filter(':eq('+i+')').find("a:first"); mega_open["check"+i] = true; item.stop().css('display','block').animate({opacity:1},300); if(item.length) { link.addClass('open-mega-a'); } } } function megaDivHide (i) { if(delayCheck[i] == false) { megaItems.filter(':eq('+i+')').find(">a").removeClass('open-mega-a'); var listItem = megaItems.filter(':eq('+i+')'), item = listItem.find("div:first"); item.stop().css('display','block').animate({opacity:0},300, function() { $(this).css('display','none'); listItem.css({overflow:'hidden'}); mega_open["check"+i] = false; }); } } if(isMobile) { megaItems.each(function(i){ $(this).bind('click', function() { if(mega_open["check"+i] != true) return false; }); }); } //bind event for mega menu megaItems.each(function(i){ $(this).hover( function() { delayCheck[i] = true; setTimeout(function(){megaDivShow(i); },options.delay); }, function() { delayCheck[i] = false; setTimeout(function(){megaDivHide(i); },options.delay); } ); }); // bind events for dropdown menu dropdownItems.find('li').addBack().each(function() { var currentItem = $(this), sublist = currentItem.find('ul:first'), showList = false; if(sublist.length) { sublist.css({display:'block', opacity:0, visibility:'hidden'}); var currentLink = currentItem.find('>a'); currentLink.bind('mouseenter', function() { sublist.stop().css({visibility:'visible'}).animate({opacity:1}); }); currentItem.bind('mouseleave', function() { sublist.stop().animate({opacity:0}, function() { sublist.css({visibility:'hidden'}); }); }); } }); }); }; })(jQuery); */ })( jQuery );