/** * * This file contains all theme JS functions */ // make it globally accessible ;( function( $, BUNTINGTON2 ) { 'use strict'; BUNTINGTON2.headroom = ''; BUNTINGTON2.masthead_height = 0; BUNTINGTON2.menu_tagline_triggered = 0; /* ---------- handle logo */ BUNTINGTON2.site_branding_width = function() { if( $( '#navhead .site-header--branding' ).length ) { // is it logo or text? var cell_width = 0; var site_title = 0; var site_descr = 0; var site_brand_padding_left = parseInt( $( '#navhead .site-header--branding .site-header--branding-a' ).css( 'padding-left' ) ); var site_brand_padding_right = parseInt( $( '#navhead .site-header--branding .site-header--branding-a' ).css( 'padding-right' ) ); if( ! $( '#navhead .site-header--branding .site-header--branding-a' ).length ) { if( $( '#navhead .site-header--branding .site-title' ).length ) site_title = $( '#navhead .site-header--branding .site-title a' ).textWidth(); if( $( '#navhead .site-header--branding .site-description' ).length ) site_descr = $( '#navhead .site-header--branding .site-description span' ).textWidth(); // add more space to override font width issue site_title += 10; site_descr += 10; cell_width = ( site_title >= site_descr ) ? site_title : site_descr; } else { var logo_width = $( '#navhead .site-header--branding .site-header--branding-a' ).data( 'img-width' ); cell_width = logo_width + site_brand_padding_left + site_brand_padding_right; } // set the cell width $( '#navhead .site-header--branding' ).css( 'width', cell_width ); } $( '#navhead' ).css( { visibility: 'visible' } ).animate( { opacity: 1.0 } ); }; /* ---------- end handle logo */ /* ---------- menu */ BUNTINGTON2.slicknav_init = function() { $( '#primary-menu' ).slicknav( { 'label': '', 'prependTo': '#mobile-nav-container', 'closedSymbol': '☰', 'openedSymbol': '▣', 'allowParentLinks': false, 'nestedParentLinks': false } ); $( '.menu-toggler' ).click( function() { var mobile_nav_container_pos_y = $( '#mobile-nav-container' ).offset().top; if( $( '#nav-icon' ).hasClass( 'open' ) ) mobile_nav_container_pos_y = 0; $( 'html, body' ).animate( { scrollTop : mobile_nav_container_pos_y }, 300 ); $( '#primary-menu' ).slicknav( 'toggle' ); $( '#nav-icon').toggleClass( 'open' ); } ); }; /* ---------- end menu */ /* ---------- menu */ BUNTINGTON2.headroom_init = function() { if( $( 'header.headroom' ).length ) { var headroom_el = document.querySelector( 'header.headroom' ); var headroom_height = $( 'header.headroom' ).outerHeight(); BUNTINGTON2.headroom = new Headroom( headroom_el, { 'offset': headroom_height, 'tolerance' : { up : 0, down : 0 }, 'classes': { 'pinned': 'headroom--pinned', 'unpinned': 'headroom--unpinned' } } ); BUNTINGTON2.headroom.init(); } }; /* ---------- end menu */ /* ---------- handle featured image */ BUNTINGTON2.handle_post_featured_image = function() { if( $( '.buntington2-cinema' ).length ) { // include the case when Site Header is set to overlay Cinema Header.Simply append the styleable class to #masthead $( '#masthead' ).removeClass( 'deny-overlay-style' ); $( '#masthead' ).addClass( 'apply-overlay-style' ); $( '.buntington2-cinema' ).headerFeaturedImage(); } }; /* ---------- end handle featured image */ /* ---------- element margins */ BUNTINGTON2.marginator = function() { var win = $( window ); var win_width = win.width(); // handle main menu items tagline if( ! BUNTINGTON2.menu_tagline_triggered ) { if( $( '#primary-menu' ).length ) { $( '#primary-menu > li > a' ).each( function() { if( $( this ).parent().is( '#search-menu-item' ) ) return; var title_tag = $( this ).attr( 'title' ); if( title_tag != '' && title_tag != undefined ) { var label = $( this ).text(); if( $( this ).attr( 'data-remodal-target' ) == 'buntington2-cart-modal' ) return; var tag = '' + title_tag + ''; $( this ).html( label + tag ); } } ); BUNTINGTON2.menu_tagline_triggered = 1; } } if( ! $( '#primary-menu' ).is( ':visible' ) ) { $( '.buntington2-primary-menu-title' ).css( 'display', 'none' ); } else { $( '.buntington2-primary-menu-title' ).css( 'display', 'block' ); } if( $( '.headroom' ).length ) { var header_height_total = 0; var site_logo_height = 0; var site_navig_height = 0; // masthead height // 1. logo if( $( '.site-header--branding-a' ).length && typeof $( '.site-header--branding-a' ).attr( 'data-img-height' ) !== typeof undefined && $( '.site-header--branding-a' ).attr( 'data-img-height' ) !== false ) { var logo_height = parseInt( $( '.site-header--branding-a' ).attr( 'data-img-height' ) ); var padding_top = parseInt( $( '.site-header--branding-a' ).css( 'paddingTop' ) ); var padding_bot = parseInt( $( '.site-header--branding-a' ).css( 'paddingBottom' ) ); // add it up site_logo_height = logo_height + padding_top + padding_bot; } else { site_logo_height = parseInt( $( '#navhead' ).outerHeight( true ) ); } // 2. navig if( $( '#site-navigation' ).length && $( '#primary-menu' ).is( ':visible' ) ) { site_navig_height = parseInt( $( '#site-navigation' ).outerHeight( true ) ); } // compare these two if( $( '#navhead' ).hasClass( 'site-header--logo-center' ) ) { header_height_total = site_logo_height + site_navig_height; } else { if( site_logo_height >= site_navig_height ) header_height_total = site_logo_height; else header_height_total = site_navig_height; } // setup height $( '#navhead' ).height( header_height_total ); // cinema height var headbar_height = 0; if( $( '.header-bar' ).length && ! $( '.header-bar' ).hasClass( 'header-bar-absolute' ) ) { headbar_height = parseInt( $( '.header-bar' ).outerHeight( true ) ); } // margin top for the content underneath fixed header $( '#cinemahead' ).css( 'marginTop', header_height_total + headbar_height ); } // admin bar height if( $( '#wpadminbar' ).length ) { if( win_width < 768 ) { $( '.header--fixed' ).css( 'top', 46 ); $( '.site-header--overlayed' ).css( 'top', 46 ); } else { $( '.header--fixed' ).css( 'top', 32 ); $( '.site-header--overlayed' ).css( 'top', 32 ); } } }; /* ---------- end element margins */ /* ---------- fitVids */ BUNTINGTON2.fitVideos = function() { $( '#page' ).fitVids(); }; /* ---------- end fitVids */ /* ---------- back-to-top */ BUNTINGTON2.back_to_top_page = function() { if( $( '#site-to-top' ).length ) { $( '#site-to-top' ).click( function() { $( 'html, body' ).animate( { scrollTop : 0 }, 300 ); return false; } ); } }; BUNTINGTON2.back_to_top_button = function() { if( $( '#site-to-top' ).length ) { if( $( window ).scrollTop() > 500 ) $( '#site-to-top' ).fadeIn(); else $( '#site-to-top' ).fadeOut(); } }; /* ---------- end back-to-top */ // events $( document ).ready( function() { BUNTINGTON2.marginator(); // margins for off grid elements BUNTINGTON2.slicknav_init(); // regular and mobile nav BUNTINGTON2.headroom_init(); // headroom BUNTINGTON2.handle_post_featured_image(); // post featured image BUNTINGTON2.fitVideos(); // fitvids plugin BUNTINGTON2.back_to_top_page(); // back to top page BUNTINGTON2.site_branding_width(); // logo and text width /* NOTE: This doesn't work on document ready */ $( 'html' ).css( 'visibility', 'visible' ); // on scroll $( window ).scroll( function() { BUNTINGTON2.back_to_top_button(); // back to top button } ); // on resize $( window ).resize( function() { BUNTINGTON2.marginator(); } ); } ); $( window ).load( function() { //BUNTINGTON2.site_branding_width(); // logo and text width } ); // calc text width $.fn.textWidth = function(){ var contents = this.contents(), wrapper = '', width = ''; contents.wrapAll(wrapper); width = contents.parent().width(); // parent is now the wrapper contents.unwrap(); return width; }; // header featured image $.fn.headerFeaturedImage = function() { var myself = $( this ); var data_url = myself.data( 'url' ); if( undefined !== data_url ) { myself.hide(); // add background image... myself.css( 'backgroundImage', 'url(' + data_url + ')' ); myself.fadeIn( 500 ); } }; } )( jQuery, window.BUNTINGTON2 = window.BUNTINGTON2 || {} );