1/* global screenReaderText */ 2/* global toggleButtonText */ 3/** 4 * Theme functions file. 5 * 6 * Contains handlers for navigation and widget area. 7 */ 8 9( function( $ ) { 10 var $body = $( document.body ), 11 $window = $( window ), 12 sidebar = $( '#sidebar' ), 13 widgets = sidebar.find( '#secondary' ), 14 social = sidebar.find( '#social-navigation' ), 15 sidebarMenu = sidebar.find( '.main-navigation' ), 16 masthead = $( '#masthead' ), 17 sidebarToggle = masthead.find( '#sidebar-toggle' ), 18 menu = masthead.find( '.nav-menu' ), 19 mastheadHeight = masthead.outerHeight(), 20 headerImageHeight = $( '.header-image' ).height(), 21 windowWidth = window.innerWidth, 22 toolbarHeight, 23 resizeTimer; 24 25 // Add dropdown toggle that display child menu items. 26 $( '#sidebar .main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); 27 28 // Toggle buttons and submenu items with active children menu items. 29 $( '#sidebar .main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' ); 30 $( '#sidebar .main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 31 32 $( '.dropdown-toggle' ).click( function( e ) { 33 var _this = $( this ); 34 e.preventDefault(); 35 _this.toggleClass( 'toggle-on' ); 36 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 37 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 38 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); 39 } ); 40 41 // Move the Page Links before Sharedaddy. 42 $( '.single .hentry' ).each( function() { 43 $( this ).find( '.page-links' ).insertBefore( $( this ).find( '.sharedaddy' ).first() ); 44 } ); 45 46 // Enable sidebar toggle. 47 ( function() { 48 if ( ! sidebar || ! sidebarToggle ) { 49 return; 50 } 51 52 // Hide button if there are no widgets and the menus are missing or empty. 53 if ( ! widgets.length && ! social.length && ( ! sidebarMenu || ! sidebarMenu.children().length ) ) { 54 sidebarToggle.hide(); 55 return; 56 } 57 58 // Add a toggle button text. 59 sidebarToggle.append( toggleButtonText.widgets ); 60 61 // Add an initial value for the attribute. 62 $( sidebarToggle ).add( sidebar ).attr( 'aria-expanded', 'false' ); 63 64 sidebarToggle.on( 'click.resonar', function() { 65 $body.toggleClass( 'sidebar-open' ).trigger( 'resize' ); 66 $( this ).toggleClass( 'toggled-on' ); 67 $( this ).add( sidebar ).attr( 'aria-expanded', $( this ).add( sidebar ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false'); 68 69 // Remove mejs players from sidebar 70 $( '#secondary .mejs-container' ).each( function( i, el ) { 71 if ( mejs.players[ el.id ] ) { 72 mejs.players[ el.id ].remove(); 73 } 74 } ); 75 76 // Re-initialize mediaelement players. 77 setTimeout( function() { 78 if ( window.wp && window.wp.mediaelement ) { 79 window.wp.mediaelement.initialize(); 80 } 81 } ); 82 83 // Trigger resize event to display VideoPress player. 84 setTimeout( function(){ 85 if ( typeof( Event ) === 'function' ) { 86 window.dispatchEvent( new Event( 'resize' ) ); 87 } else { 88 var event = window.document.createEvent( 'UIEvents' ); 89 event.initUIEvent( 'resize', true, false, window, 0 ); 90 window.dispatchEvent( event ); 91 } 92 } ); 93 } ); 94 } )(); 95 96 // Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility. 97 ( function() { 98 if ( ! menu || ! menu.children().length ) { 99 return; 100 } 101 102 if ( 'ontouchstart' in window ) { 103 menu.find( '.menu-item-has-children > a' ).on( 'touchstart.resonar', function( e ) { 104 var el = $( this ).parent( 'li' ); 105 106 if ( ! el.hasClass( 'focus' ) ) { 107 e.preventDefault(); 108 el.toggleClass( 'focus' ); 109 el.siblings( '.focus' ).removeClass( 'focus' ); 110 } 111 } ); 112 } 113 114 menu.find( 'a' ).on( 'focus.resonar blur.resonar', function() { 115 $( this ).parents( '.menu-item' ).toggleClass( 'focus' ); 116 } ); 117 } )(); 118 119 // Make Featured image full-screen. 120 function fullscreenFeaturedImage() {
121 var entryHeaderBackground = $( '.entry-header-background' ), 122 entryHeaderOffset = 0; 123 124 if ( ! entryHeaderBackground ) { 125 return; 126 } 127 128 // 1088 is site-main width. 129 if ( 1088 < $window.width() ) { 130 entryHeaderOffset = ( $window.width() - 1088 ) / 2; 131 } 132 133 toolbarHeight = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; 134 135 entryHeaderBackground.css( { 136 'height': $window.height() - ( toolbarHeight + mastheadHeight + headerImageHeight ) + 'px', 137 'margin-left': '-' + entryHeaderOffset + 'px', 138 'margin-right': '-' + entryHeaderOffset + 'px' 139 } ); 140 } 141 142 // Minimum height for sidebar. 143 function sidebarSize() { 144 if ( ! sidebar ) { 145 return; 146 } 147 148 toolbarHeight = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; 149 150 var sidebarMinHeight = $window.height() - ( toolbarHeight + mastheadHeight + headerImageHeight ); 151 152 sidebar.css( { 153 'min-height': sidebarMinHeight + 'px' 154 } ); 155 } 156 157 // Scroll up when the arrow is clicked. 158 function scroll() { 159 if ( ! $( '#scroll-indicator' ) ) { 160 return; 161 } 162 163 $( '#scroll-indicator' ).on( 'click.resonar', function() { 164 $( 'html, body' ).animate( { 165 scrollTop: $( '#entry-header' ).offset().top + 24 166 }, 300 ); 167 return false; 168 } ); 169 } 170 171 // Add a class to change opacity of the arrow and to move the entry header. 172 $( function() { 173 if ( ! $( '#scroll-indicator' ) ) { 174 return; 175 } 176 177 $window.on( 'scroll.resonar', function() { 178 if ( 0 < $window.scrollTop() ) { 179 $( '#scroll-indicator, #entry-header' ).addClass ( 'scrolled' ); 180 } else { 181 $( '#scroll-indicator, #entry-header' ).removeClass ( 'scrolled' ); 182 } 183 } ); 184 } ); 185 186 // Add body classes to modify layout. 187 function bodyClasses() { 188 if ( 925 <= windowWidth ) { 189 var siteBrandingWidth = masthead.find( '.site-branding' ).width() + 32, 190 mainNavigationWidth = masthead.find( '.main-navigation' ).width() - 16, 191 mastheadWidth = masthead.width(); 192 193 if ( ! widgets.length && ! social.length ) { 194 $body.addClass( 'no-sidebar' ); 195 } else { 196 $body.removeClass( 'no-sidebar' ); 197 } 198 199 if ( mastheadWidth < ( siteBrandingWidth + mainNavigationWidth + sidebarToggle.width() ) ) { 200 $body.addClass( 'menu-left' ); 201 } else { 202 $body.removeClass( 'menu-left' ); 203 } 204 } else { 205 $body.removeClass( 'no-sidebar, menu-left' ); 206 } 207 } 208 209 // Add a class to big image and caption >= 1088px. 210 function bigImageClass() { 211 $( '.entry-content img.size-full' ).each( function() { 212 var img = $( this ), 213 caption = $( this ).closest( 'figure' ), 214 newImg = new Image(); 215 216 newImg.src = img.attr( 'src' ); 217 218 $( newImg ).load( function() { 219 var imgWidth = newImg.width; 220 221 if ( 1088 <= imgWidth ) { 222 $( img ).addClass( 'size-big' ); 223 } 224 225 if ( caption.hasClass( 'wp-caption' ) && 1088 <= imgWidth ) { 226 caption.addClass( 'caption-big' ); 227 caption.removeAttr( 'style' ); 228 } 229 } ); 230 } ); 231 } 232 233 // Change the toggle button text. 234 function toggleButtonTxt() { 235 if ( 925 >= windowWidth ) { 236 if ( ( sidebarMenu.length || social.length ) && widgets.length ) { 237 sidebarToggle.html( toggleButtonText.both ); 238 } else if ( ( sidebarMenu.length || social.length ) && ! widgets.length ) { 239 sidebarToggle.html( toggleButtonText.menu ); 240 } else { 241 sidebarToggle.html( toggleButtonText.widgets ); 242 } 243 } else { 244 sidebarToggle.html( toggleButtonText.widgets ); 245 } 246 } 247 248 // Close Sidebar with an escape key. 249 $( document ).keyup( function( e ) { 250 if ( 27 === e.keyCode && sidebarToggle.hasClass( 'toggled-on' ) ) { 251 $body.removeClass( 'sidebar-open' ); 252 sidebarToggle.removeClass( 'toggled-on' ).attr( 'aria-expanded', 'false' ); 253 sidebar.attr( 'aria-hidden', 'true' ); 254 } 255 } ); 256 257 $( document ).ready( function() { 258 $window.on( 'resize.resonar', function() { 259 windowWidth = window.innerWidth; 260 clearTimeout( resizeTimer ); 261 resizeTimer = setTimeout( function() { 262 sidebarSize(); 263 fullscreenFeaturedImage(); 264 bodyClasses(); 265 toggleButtonTxt(); 266 }, 300 ); 267 } ); 268 269 sidebarSize(); 270 fullscreenFeaturedImage(); 271 bodyClasses(); 272 bigImageClass(); 273 toggleButtonTxt(); 274 scroll(); 275 } ); 276} )( 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.