xref: /template/writr/script.js (revision 787ebf2b34f565800837cfcd285970a421c8195f)
1/* DOKUWIKI:include js/skip-link-focus-fix.js */
2
3( function( $ ) {
4    /*
5     * Click to toggle sidebar.
6     */
7    function toggleSidebar() {
8        $( '#writr__sidebar' ).on( 'click', '#writr__sidebar-toggle', function( e ) {
9            e.preventDefault();
10            $( 'html, body' ).scrollTop( 0 );
11            $( this ).toggleClass( 'open' );
12            $( 'body' ).toggleClass( 'sidebar-closed' );
13            $( '#writr__secondary' ).resize();
14        } );
15    }
16
17    /**
18     * Handles toggling the navigation menu for small screens.
19     */
20    function toggleNavigation() {
21        var $container = $('#writr__site-navigation');
22        if (!$container.length) return;
23        var $button = $('.menu-toggle', $container);
24        if (!$button.length) return;
25        var $menu = $('ul', $container);
26        if (!$menu.length) {
27            $menu.hide();
28            return;
29        }
30        $button.click(function(){
31            $container.toggleClass('toggled');
32        });
33    }
34
35    /*
36     * A function to enable/disable a dropdown submenu.
37     */
38    function toggleSubmenu() {
39        $( '.main-navigation .node > div > a' ).append( '<span class="dropdown-icon" />' );
40        $( '#writr__site-navigation' ).on( 'click', '.dropdown-icon', function( e ) {
41            e.preventDefault();
42            $( this ).toggleClass( 'open' );
43            if ( $( this ).hasClass( 'open' ) ) {
44                $( this ).parent().parent().next( 'ul' ).show();
45            } else {
46                $( this ).parent().parent().next( 'ul' ).hide();
47            }
48        } );
49    }
50
51    /*
52     * Close TOC by default
53     */
54    function closeToc() {
55        var $toc = jQuery('#dw__toc .toggle');
56        if($toc.length) {
57            $toc[0].setState(-1);
58        }
59    }
60
61    /*
62     * Change search submit input to submit button to make it easier to style
63     */
64    function changeSearchInput() {
65        var $searchForm = $('.search-form > form > div');
66        var $searchButton = $('input[type="submit"]', $searchForm).detach();
67        var title = $searchButton.attr('title');
68        var value = $searchButton.val();
69        $searchForm.append('<button type="submit" title="'+title+'">'+value+'</button>');
70    }
71
72    $(function(){
73        toggleSidebar();
74        toggleNavigation();
75        toggleSubmenu();
76        closeToc();
77        changeSearchInput();
78    });
79} )( jQuery );
80