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