1 2/* global screenReaderText */ 3/** 4 * Theme functions file. 5 * 6 * Contains handlers for navigation and widget area. 7 */ 8 9( function( $ ) { 10 var body, masthead, menuToggle, siteNavigation, socialNavigation, siteHeaderMenu, resizeTimer; 11 12 function initMainNavigation( container ) { 13 14 // Add dropdown toggle that displays child menu items. 15 var dropdownToggle = $( '<button />', { 16 'class': 'dropdown-toggle', 17 'aria-expanded': false 18 } ).append( $( '<span />', { 19 'class': 'screen-reader-text', 20 text: screenReaderText.expand 21 } ) ); 22 23 container.find( '.menu-item-has-children > a' ).after( dropdownToggle ); 24 25 // Toggle buttons and submenu items with active children menu items. 26 container.find( '.current-menu-ancestor > button' ).addClass( 'toggled-on' ); 27 container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 28 29 // Add menu items with submenus to aria-haspopup="true". 30 container.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' ); 31 32 container.find( '.menu-item-has-children > a' ).click( function( e ) { 33 var _this = $( this ).next('.dropdown-toggle'), 34 screenReaderSpan = _this.find( '.screen-reader-text' ); 35 36 $( this ).parent().siblings('li').find('.toggled-on').toggleClass( 'toggled-on' ); 37 38 e.preventDefault(); 39 _this.toggleClass( 'toggled-on' ); 40 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 41 42 // jscs:disable 43 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 44 // jscs:enable 45 screenReaderSpan.text( screenReaderSpan.text() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); 46 return false; 47 } ); 48 } 49 initMainNavigation( $( '.main-navigation' ) ); 50 51 masthead = $( '#masthead' ); 52 menuToggle = masthead.find( '.menu-toggle' ); 53 siteHeaderMenu = masthead.find( '#site-header-menu' ); 54 siteNavigation = masthead.find( '#site-navigation' ); 55 socialNavigation = masthead.find( '#social-navigation' ); 56 57 // Enable menuToggle. 58 ( function() { 59 60 // Return early if menuToggle is missing. 61 if ( ! menuToggle.length ) { 62 return; 63 } 64 65 // Add an initial values for the attribute. 66 menuToggle.add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded', 'true' ); 67 68 menuToggle.on( 'click.twentysixteen', function() { 69 console.log('clicked'); 70 $( '.menu-toggle' ).add( siteHeaderMenu ).toggleClass( 'toggled-on' ); 71 72 // jscs:disable 73 $( '.menu-toggle' ).add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded', $( this ).add( siteNavigation ).add( socialNavigation ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 74 // jscs:enable 75 } ); 76 } )(); 77 78 // Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility. 79 ( function() { 80 if ( ! siteNavigation.length || ! siteNavigation.children().length ) { 81 return; 82 } 83 84 // Toggle `focus` class to allow submenu access on tablets. 85 function toggleFocusClassTouchScreen() { 86 if ( window.innerWidth >= 910 ) { 87 $( document.body ).on( 'touchstart.twentysixteen', function( e ) { 88 if ( ! $( e.target ).closest( '.main-navigation li' ).length ) { 89 $( '.main-navigation li' ).removeClass( 'focus' ); 90 } 91 } ); 92 siteNavigation.find( '.menu-item-has-children > a' ).on( 'touchstart.twentysixteen', function( e ) { 93 var el = $( this ).parent( 'li' ); 94 95 if ( ! el.hasClass( 'focus' ) ) { 96 e.preventDefault(); 97 el.toggleClass( 'focus' ); 98 el.siblings( '.focus' ).removeClass( 'focus' ); 99 } 100 } ); 101 } else { 102 siteNavigation.find( '.menu-item-has-children > a' ).unbind( 'touchstart.twentysixteen' ); 103 } 104 } 105 106 if ( 'ontouchstart' in window ) { 107 $( window ).on( 'resize.twentysixteen', toggleFocusClassTouchScreen ); 108 toggleFocusClassTouchScreen(); 109 } 110 111 siteNavigation.find( 'a' ).on( 'focus.twentysixteen blur.twentysixteen', function() { 112 $( this ).parents( '.menu-item' ).toggleClass( 'focus' ); 113 } ); 114 } )(); 115 116 // Add the default ARIA attributes for the menu toggle and the navigations. 117 function onResizeARIA() { 118 if ( window.innerWidth < 910 ) { 119 if ( menuToggle.hasClass( 'toggled-on' ) ) { 120 menuToggle.attr( 'aria-expanded', 'true' ); 121 } else { 122 menuToggle.attr( 'aria-expanded', 'false' ); 123 } 124 125 if ( siteHeaderMenu.hasClass( 'toggled-on' ) ) { 126 siteNavigation.attr( 'aria-expanded', 'true' ); 127 socialNavigation.attr( 'aria-expanded', 'true' ); 128 } else { 129 siteNavigation.attr( 'aria-expanded', 'false' ); 130 socialNavigation.attr( 'aria-expanded', 'false' ); 131 } 132 133 menuToggle.attr( 'aria-controls', 'site-navigation social-navigation' ); 134 } else { 135 menuToggle.removeAttr( 'aria-expanded' ); 136 siteNavigation.removeAttr( 'aria-expanded' ); 137 socialNavigation.removeAttr( 'aria-expanded' ); 138 menuToggle.removeAttr( 'aria-controls' ); 139 } 140 } 141 142 // jQuery to collapse the navbar on scroll 143 function minimize() { 144 if ($("#masthead").offset().top > 50) { 145 $("#masthead").addClass("minimize"); 146 $('body').trigger('minimized'); 147 } else { 148 $("#masthead").removeClass("minimize"); 149 } 150 } 151 152 $(window).scroll(minimize); 153 minimize(); 154 155 // Add 'below-entry-meta' class to elements. 156 function belowEntryMetaClass( param ) { 157 if ( body.hasClass( 'page' ) || body.hasClass( 'search' ) || body.hasClass( 'single-attachment' ) || body.hasClass( 'error404' ) ) { 158 return; 159 } 160 161 $( '.entry-content' ).find( param ).each( function() { 162 var element = $( this ), 163 elementPos = element.offset(), 164 elementPosTop = elementPos.top, 165 entryFooter = element.closest( 'article' ).find( '.entry-footer' ), 166 entryFooterPos = entryFooter.offset(), 167 entryFooterPosBottom = entryFooterPos.top + ( entryFooter.height() + 28 ),
168 caption = element.closest( 'figure' ), 169 newImg; 170 171 // Add 'below-entry-meta' to elements below the entry meta. 172 if ( elementPosTop > entryFooterPosBottom ) { 173 174 // Check if full-size images and captions are larger than or equal to 840px. 175 if ( 'img.size-full' === param ) { 176 177 // Create an image to find native image width of resized images (i.e. max-width: 100%). 178 newImg = new Image(); 179 newImg.src = element.attr( 'src' ); 180 181 $( newImg ).on( 'load.twentysixteen', function() { 182 if ( newImg.width >= 840 ) { 183 element.addClass( 'below-entry-meta' ); 184 185 if ( caption.hasClass( 'wp-caption' ) ) { 186 caption.addClass( 'below-entry-meta' ); 187 caption.removeAttr( 'style' ); 188 } 189 } 190 } ); 191 } else { 192 element.addClass( 'below-entry-meta' ); 193 } 194 } else { 195 element.removeClass( 'below-entry-meta' ); 196 caption.removeClass( 'below-entry-meta' ); 197 } 198 } ); 199 } 200 201 $( document ).ready( function() { 202 body = $( document.body ); 203 204 $( window ) 205 .on( 'load.twentysixteen', onResizeARIA ) 206 .on( 'resize.twentysixteen', function() { 207 clearTimeout( resizeTimer ); 208 resizeTimer = setTimeout( function() { 209 belowEntryMetaClass( 'img.size-full' ); 210 belowEntryMetaClass( 'blockquote.alignleft, blockquote.alignright' ); 211 }, 300 ); 212 onResizeARIA(); 213 } ); 214 215 belowEntryMetaClass( 'img.size-full' ); 216 belowEntryMetaClass( 'blockquote.alignleft, blockquote.alignright' ); 217 } ); 218} )( 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.