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