1/** 2 * Functionality specific to Bushwick. 3 * 4 * Provides helper functions to enhance the theme experience. 5 */ 6 7( function( $ ) { 8 9 /** 10 * Masonry. 11 */ 12 $( window ).load( function() { 13 14 var widgets_area = $( '.widget-container' ); 15 16 $( '.widget-handle' ).on( 'click.bushwick', function( event ) { 17 event.preventDefault(); 18 $( this ).toggleClass( 'open' ); 19 20 // Remove mejs players from sidebar 21 $( '#secondary .mejs-container' ).each( function( i, el ) { 22 if ( mejs.players[ el.id ] ) { 23 mejs.players[ el.id ].remove(); 24 } 25 } ); 26 27 if( $( this ).hasClass( 'open' ) ) { 28 $( '#secondary' ).slideDown( 300 ); 29 // Trigger resize to make sure widgets fit prefectly. 30 $( this ).trigger( 'resize' ); 31 // Masonry blocks 32 widgets_area.imagesLoaded( function() { 33 widgets_area.masonry( { 34 itemSelector: '.widget', 35 gutter: 0, 36 transitionDuration: 0, 37 isOriginLeft: ! $( 'body' ).is( '.rtl' ) 38 } ); 39 } ); 40 41 // Re-initialize mediaelement players. 42 setTimeout( function() { 43 if ( window.wp && window.wp.mediaelement ) { 44 window.wp.mediaelement.initialize(); 45 } 46 } ); 47 48 // Trigger resize event to display VideoPress player. 49 setTimeout( function(){ 50 if ( typeof( Event ) === 'function' ) { 51 window.dispatchEvent( new Event( 'resize' ) ); 52 } else { 53 var event = window.document.createEvent( 'UIEvents' ); 54 event.initUIEvent( 'resize', true, false, window, 0 ); 55 window.dispatchEvent( event ); 56 } 57 } ); 58 } else { 59 $( '#secondary' ).slideUp( 300 ); 60 } 61 } ); 62 63 $( '#404-widgets' ).masonry( { 64 itemSelector: '.widget', 65 gutter: 0, 66 transitionDuration: 0, 67 isOriginLeft: ! $( 'body' ).is( '.rtl' ) 68 } ); 69 70 $( window ).resize( function () { 71 72 // Force layout correction after 1500 milliseconds 73 setTimeout( function () { 74 widgets_area.masonry(); 75 }, 1500 ); 76 77 } ); 78 79 } ); 80 81 /** 82 * Wrap entry title if too many characters. 83 */ 84 $( window ).load( function() { 85 var count = $( '.single .entry-title' ).text().length; 86 if ( count > 150 ) { 87 $( '.single .entry-title' ).wrapInner( '<small />' ); 88 } 89 } ); 90 91 /** 92 * Enables menu toggle for small screens. 93 */ 94 ( function() { 95 var container, button, menu; 96 97 container = document.getElementById( 'site-navigation' ); 98 if ( ! container ) 99 return; 100 101 button = container.getElementsByTagName( 'h1' )[0]; 102 if ( 'undefined' === typeof button ) 103 return; 104 105 menu = container.getElementsByTagName( 'ul' )[0]; 106 107 // Hide menu toggle button if menu is empty and return early. 108 if ( 'undefined' === typeof menu ) { 109 button.style.display = 'none'; 110 return; 111 } 112 113 if ( -1 === menu.className.indexOf( 'nav-menu' ) ) 114 menu.className += ' nav-menu'; 115 116 button.onclick = function() { 117 if ( -1 !== container.className.indexOf( 'toggled' ) ) 118 container.className = container.className.replace( ' toggled', '' ); 119 else 120 container.className += ' toggled'; 121 }; 122 123 // Fix child menus for touch devices. 124 function fixMenuTouchTaps( container ) { 125 var touchStartFn, 126 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 127 128 if ( 'ontouchstart' in window ) { 129 touchStartFn = function( e ) { 130 var menuItem = this.parentNode; 131 132 if ( ! menuItem.classList.contains( 'focus' ) ) { 133 e.preventDefault(); 134 for( var i = 0; i < menuItem.parentNode.children.length; ++i ) { 135 if ( menuItem === menuItem.parentNode.children[i] ) { 136 continue; 137 } 138 menuItem.parentNode.children[i].classList.remove( 'focus' ); 139 } 140 menuItem.classList.add( 'focus' ); 141 } else { 142 menuItem.classList.remove( 'focus' ); 143 } 144 }; 145 146 for ( var i = 0; i < parentLink.length; ++i ) { 147 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ); 148 } 149 } 150 } 151 152 fixMenuTouchTaps( container ); 153 } )(); 154 155 $( '.navigation-main' ).find( 'a' ).on( 'focus blur', function() { 156 $( this ).parents().toggleClass( 'focus' ); 157 } ); 158 159 /** 160 * Makes "skip to content" link work correctly in IE9 and Chrome for better 161 * accessibility. 162 * 163 * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ 164 */
165 $( window ).on( 'hashchange.bushwick', function() { 166 var element = document.getElementById( location.hash.substring( 1 ) ); 167 168 if ( element ) { 169 if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) 170 element.tabIndex = -1; 171 172 element.focus(); 173 } 174 } ); 175 176 /** 177 * Adds a class .home-link class to the navigation list item containing the home link. 178 */ 179 $( '.navigation-main a[href="' + bushwick_functions_vars.home_url + '"]' ).closest( 'li').addClass( 'home-link' ); 180 181} )( 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.