/* global twentyseventeenscreenreadertext */ (function( $ ) { var h = $(window).height(); var w=$(window).width(); if ($("#wpadminbar")){ var h1=$("#masthead").height()+$("#wpadminbar").height(); }else { var h1=$("#masthead").height(); } if (h1<400){ $(".floating").css("top",(530)); }else { $(".floating").css("top",(h1+106)); } // variables and dom caching. var $body = $( 'body' ), $customheader = $body.find( '.custom-header' ), $branding = $customheader.find( '.site-branding' ), $navigation = $body.find( '.navigation-top' ), $navwrap = $navigation.find( '.wrap' ), $navmenuitem = $navigation.find( '.menu-item' ), $menutoggle = $navigation.find( '.menu-toggle' ), $menuscrolldown = $body.find( '.menu-scroll-down' ), $sidebar = $body.find( '#secondary' ), $entrycontent = $body.find( '.entry-content' ), $formatquote = $body.find( '.format-quote blockquote' ), isfrontpage = $body.hasclass( 'twentyseventeen-front-page' ) || $body.hasclass( 'home blog' ), navigationfixedclass = 'site-navigation-fixed', navigationheight, navigationouterheight, navpadding, navmenuitemheight, idealnavheight, navisnottootall, headeroffset, menutop = 0, resizetimer; // ensure the sticky navigation doesn't cover current focused links. $( 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex], [contenteditable]', '.site-content-contain' ).filter( ':visible' ).focus( function() { if ( $navigation.hasclass( 'site-navigation-fixed' ) ) { var windowscrolltop = $( window ).scrolltop(), fixednavheight = $navigation.height(), itemscrolltop = $( this ).offset().top, offsetdiff = itemscrolltop - windowscrolltop; // account for admin bar. if ( $( '#wpadminbar' ).length ) { offsetdiff -= $( '#wpadminbar' ).height(); } if ( offsetdiff < fixednavheight ) { $( window ).scrollto( itemscrolltop - ( fixednavheight + 50 ), 0 ); } } }); // set properties of navigation. function setnavprops() { navigationheight = $navigation.height(); navigationouterheight = $navigation.outerheight(); navpadding = parsefloat( $navwrap.css( 'padding-top' ) ) * 2; navmenuitemheight = $navmenuitem.outerheight() * 2; idealnavheight = navpadding + navmenuitemheight; navisnottootall = navigationheight <= idealnavheight; } // make navigation 'stick'. function adjustscrollclass() { // make sure we're not on a mobile screen. if ( 'none' === $menutoggle.css( 'display' ) ) { // make sure the nav isn't taller than two rows. if ( navisnottootall ) { // when there's a custom header image or video, the header offset includes the height of the navigation. if ( isfrontpage && ( $body.hasclass( 'has-header-image' ) || $body.hasclass( 'has-header-video' ) ) ) { headeroffset = $customheader.innerheight() - navigationouterheight; } else { headeroffset = $customheader.innerheight(); } } else { // remove 'fixed' class if nav is taller than two rows. $navigation.removeclass( navigationfixedclass ); } } } // set margins of branding in header. function adjustheaderheight() { if ( 'none' === $menutoggle.css( 'display' ) ) { // the margin should be applied to different elements on front-page or home vs interior pages. if ( isfrontpage ) { $branding.css( 'margin-bottom', navigationouterheight ); } else { $customheader.css( 'margin-bottom', navigationouterheight ); } } else { $customheader.css( 'margin-bottom', '0' ); $branding.css( 'margin-bottom', '0' ); } } // set icon for quotes. function setquotesicon() { $( twentyseventeenscreenreadertext.quote ).prependto( $formatquote ); } // add 'below-entry-meta' class to elements. function belowentrymetaclass( param ) { var sidebarpos, sidebarposbottom; if ( ! $body.hasclass( 'has-sidebar' ) || ( $body.hasclass( 'search' ) || $body.hasclass( 'single-attachment' ) || $body.hasclass( 'error404' ) || $body.hasclass( 'twentyseventeen-front-page' ) ) ) { return; } sidebarpos = $sidebar.offset(); sidebarposbottom = sidebarpos.top + ( $sidebar.height() + 28 ); $entrycontent.find( param ).each( function() { var $element = $( this ), elementpos = $element.offset(), elementpostop = elementpos.top; // add 'below-entry-meta' to elements below the entry meta. if ( elementpostop > sidebarposbottom ) { $element.addclass( 'below-entry-meta' ); } else { $element.removeclass( 'below-entry-meta' ); } }); } /* * test if inline svgs are supported. * @link https://github.com/modernizr/modernizr/ */ function supportsinlinesvg() { var div = document.createelement( 'div' ); div.innerhtml = ''; return 'http://www.w3.org/2000/svg' === ( 'undefined' !== typeof svgrect && div.firstchild && div.firstchild.namespaceuri ); } /** * test if an ios device. */ function checkios() { return /ipad|iphone|ipod/.test(navigator.useragent) && ! window.msstream; } /* * test if background-attachment: fixed is supported. * @link http://stackoverflow.com/questions/14115080/detect-support-for-background-attachment-fixed */ function supportsfixedbackground() { var el = document.createelement('div'), issupported; try { if ( ! ( 'backgroundattachment' in el.style ) || checkios() ) { return false; } el.style.backgroundattachment = 'fixed'; issupported = ( 'fixed' === el.style.backgroundattachment ); return issupported; } catch (e) { return false; } } // fire on document ready. $( document ).ready( function() { // if navigation menu is present on page, setnavprops and adjustscrollclass. if ( $navigation.length ) { setnavprops(); adjustscrollclass(); } // if 'scroll down' arrow in present on page, calculate scroll offset and bind an event handler to the click event. if ( $menuscrolldown.length ) { if ( $( 'body' ).hasclass( 'admin-bar' ) ) { menutop -= 32; } if ( $( 'body' ).hasclass( 'blog' ) ) { menutop -= 30; // the div for latest posts has no space above content, add some to account for this. } if ( ! $navigation.length ) { navigationouterheight = 0; } $menuscrolldown.click( function( e ) { e.preventdefault(); $( window ).scrollto( '#primary', { duration: 600, offset: { top: menutop - navigationouterheight } }); }); } adjustheaderheight(); setquotesicon(); if ( true === supportsinlinesvg() ) { document.documentelement.classname = document.documentelement.classname.replace( /(\s*)no-svg(\s*)/, '$1svg$2' ); } if ( true === supportsfixedbackground() ) { document.documentelement.classname += ' background-fixed'; } }); // if navigation menu is present on page, adjust it on scroll and screen resize. if ( $navigation.length ) { // on scroll, we want to stick/unstick the navigation. $( window ).on( 'scroll', function() { adjustscrollclass(); adjustheaderheight(); }); // also want to make sure the navigation is where it should be on resize. $( window ).resize( function() { setnavprops(); settimeout( adjustscrollclass, 500 ); }); } $( window ).resize( function() { cleartimeout( resizetimer ); resizetimer = settimeout( function() { belowentrymetaclass( 'blockquote.alignleft, blockquote.alignright' ); }, 300 ); settimeout( adjustheaderheight, 1000 ); }); // add header video class after the video is loaded. $( document ).on( 'wp-custom-header-video-loaded', function() { $body.addclass( 'has-header-video' ); }); })( jquery );