1/* global screenReaderText */ 2/** 3 * Theme functions file. 4 * 5 * Contains handlers for navigation and widget area. 6 * 7 * @version 1.0 8 */ 9 10( function( $ ) { 11 var $body, $window, $sidebar, adminbarOffset, top = false, 12 bottom = false, windowWidth, windowHeight, lastWindowPos = 0, 13 topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, 14 secondary, button; 15 16 // Mobile Main Menu. 17 $('#menu-main-wrap').hide(); 18 $('#menu-main-close').hide(); 19 $('#menu-main-toggle').on( 'click', function () { 20 $('#menu-main-wrap').slideToggle('fast'); 21 $('#menu-main-toggle').addClass('hide'); 22 $('#menu-main-close').addClass('show'); 23 }); 24 25 $('#menu-main-close').on( 'click', function () { 26 $('#menu-main-wrap').slideToggle('fast'); 27 $('#menu-main-toggle').removeClass('hide'); 28 $('#menu-main-close').removeClass('show'); 29 }); 30 31 $('#menu-main-close-bottom').on( 'click', function () { 32 $('#menu-main-wrap').slideToggle('fast'); 33 $('#menu-main-toggle').removeClass('hide'); 34 $('#menu-main-close').removeClass('show'); 35 }); 36 37 // Subscribe Widget Area 38 $('.lightbox-btn').on( 'click', function () { 39 $('.lightbox').fadeIn('slow'); 40 }); 41 $('.lightbox-close').on( 'click', function () { 42 $('.lightbox').fadeOut('slow'); 43 }); 44 45 // Responsive Videos. 46 $('#primary').fitVids(); 47 48 49 // Initialize Featured Content slider for the slider widget. 50 $(window).load(function() { 51 jQuery('.flexslider').flexslider({ 52 animation: "fade", //String: Select your animation type, "fade" or "slide" 53 slideshow: true, //Boolean: Animate slider automatically 54 animationLoop: true, 55 prevText: "<span>Previous</span>", //String: Set the text for the "previous" directionNav item 56 nextText: "<span>Next</span>", 57 touch: true //{NEW} Boolean: Allow touch swipe navigation of the slider on touch-enabled devices 58 }); 59 }); 60 61 //Smooth Scroll to top Button 62 // browser window scroll (in pixels) after which the "back to top" link is shown 63 var offset = 500, 64 //browser window scroll (in pixels) after which the "back to top" link opacity is reduced 65 offset_opacity = 1200, 66 //duration of the top scrolling animation (in ms) 67 scroll_top_duration = 700, 68 //grab the "back to top" link 69 $back_to_top = $('.top'); 70 71 //hide or show the "back to top" link 72 $(window).scroll(function(){ 73 ( $(this).scrollTop() > offset ) ? $back_to_top.addClass('is-visible') : $back_to_top.removeClass('is-visible'); 74 }); 75 76 //smooth scroll to top 77 $back_to_top.on('click', function(event){ 78 event.preventDefault(); 79 $('body,html').animate({ 80 scrollTop: 0 , 81 }, scroll_top_duration 82 ); 83 }); 84 85 // Add dropdown toggle that display child menu items. 86 $( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); 87 88 // Toggle buttons and submenu items with active children menu items. 89 $( '.current-menu-ancestor > button' ).addClass( 'toggle-on' ); 90 $( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 91 92 $( '.dropdown-toggle' ).click( function( e ) { 93 var _this = $( this ); 94 e.preventDefault(); 95 _this.toggleClass( 'toggle-on' ); 96 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 97 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 98 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); 99 } ); 100 101 secondary = $( '#secondary' ); 102 button = $( '.site-branding' ).find( '.secondary-toggle' ); 103 104 // Enable menu toggle for small screens. 105 ( function() { 106 var menu, widgets, social; 107 if ( ! secondary || ! button ) { 108 return; 109 } 110 111 // Hide button if there are no widgets and the menus are missing or empty. 112 menu = secondary.find( '.nav-menu' ); 113 widgets = secondary.find( '#widget-area' ); 114 social = secondary.find( '#social-navigation' ); 115 if ( ! widgets.length && ! social.length && ( ! menu || ! menu.children().length ) ) { 116 button.hide(); 117 return; 118 } 119 120 button.on( 'click.weta', function() { 121 secondary.toggleClass( 'toggled-on' ); 122 secondary.trigger( 'resize' ); 123 $( this ).toggleClass( 'toggled-on' ); 124 if ( $( this, secondary ).hasClass( 'toggled-on' ) ) { 125 $( this ).attr( 'aria-expanded', 'true' ); 126 secondary.attr( 'aria-expanded', 'true' ); 127 } else { 128 $( this ).attr( 'aria-expanded', 'false' ); 129 secondary.attr( 'aria-expanded', 'false' ); 130 } 131 } ); 132 } )(); 133 134 /** 135 * @summary Add or remove ARIA attributes. 136 * Uses jQuery's width() function to determine the size of the window and add 137 * the default ARIA attributes for the menu toggle if it's visible. 138 * @since Twenty Fifteen 1.1 139 */ 140 function onResizeARIA() { 141 if ( 1022 > $window.width() ) { 142 button.attr( 'aria-expanded', 'false' ); 143 secondary.attr( 'aria-expanded', 'false' ); 144 button.attr( 'aria-controls', 'secondary' ); 145 } else { 146 button.removeAttr( 'aria-expanded' ); 147 secondary.removeAttr( 'aria-expanded' ); 148 button.removeAttr( 'aria-controls' ); 149 } 150 } 151 152 153 // Scroll Top + Fix-position Main Menu. 154 var StickyElement = function(node){ 155 var doc = $(document), 156 fixed = false, 157 anchor = node.find('.sticky-anchor'), 158 content = node.find('.sticky-content'); 159 160 var onScroll = function(e){
161 var docTop = doc.scrollTop(), 162 anchorTop = anchor.offset().top; 163 164 if(docTop > anchorTop){ 165 if(!fixed){ 166 anchor.height(content.outerHeight()); 167 content.addClass('fixed'); 168 $('body').addClass('nav-is-fixed'); 169 fixed = true; 170 } 171 } else { 172 if(fixed){ 173 anchor.height(0); 174 content.removeClass('fixed'); 175 $('body').removeClass('nav-is-fixed'); 176 fixed = false; 177 } 178 } 179 }; 180 $(window).on('scroll', onScroll); 181 }; 182 183 var demo = new StickyElement($('#menu-main-wrap')); 184 185} )( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.