| | 1 | /** |
| | 2 | * Enables toggling visibility of all the chapters in the Handbook Chapter widget. |
| | 3 | * |
| | 4 | * @since ??? |
| | 5 | */ |
| | 6 | var toggleChapters = function () { |
| | 7 | /** |
| | 8 | * The Handbook Chapter widget title element. |
| | 9 | * |
| | 10 | * @type {NodeList} |
| | 11 | */ |
| | 12 | var chapterWidgetHeading = document.querySelectorAll( '.widget_wporg_handbook_pages .widgettitle' ); |
| | 13 | |
| | 14 | /* |
| | 15 | * Bind to the touch and click events to make it useful on both mobile and desktop. |
| | 16 | * Since 'click' is the last event in the chain, we use preventDefault() to stop the |
| | 17 | * touch event from continuing and triggering a "ghost click". |
| | 18 | * |
| | 19 | * @link http://www.html5rocks.com/en/mobile/touchandmouse/ |
| | 20 | */ |
| | 21 | jQuery( chapterWidgetHeading ).bind( 'touchstart click', function ( e ) { |
| | 22 | e.preventDefault(); |
| | 23 | jQuery( this ).next( '.menu-table-of-contents-container' ).toggle(); |
| | 24 | } ); |
| | 25 | }; |
| | 26 | |
| | 27 | // Layout changes the widget at 700px, so we don't want to enable toggling above that. |
| | 28 | // @todo Check on window resize, rather than just on page loading |
| | 29 | jQuery( document ).ready( function() { |
| | 30 | if ( 700 >= parseInt( jQuery( window ).width(), 10 ) ) { |
| | 31 | toggleChapters(); |
| | 32 | } |
| | 33 | }); |
| | 34 | |