forked from LaswitchTech/writr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
114 lines (104 loc) · 3.32 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* DOKUWIKI:include js/skip-link-focus-fix.js */
$(document).ready(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 = $('#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>');
}
/*
* Enable add new page dropdown
*/
function enableAddNewPage() {
$('.action.AddNewPage').click(function(event) {
event.preventDefault();
$('.addnewpage').toggle();
});
$(document).click(function(event) {
if (!$(event.target).closest('.action.AddNewPage, .addnewpage').length) {
$('.addnewpage').hide();
}
});
}
/*
* Enable translation dropdown
*/
function enableTranslation() {
$('.action.Translation').click(function(event) {
event.preventDefault();
$('.plugin_translation').toggle();
});
$(document).click(function(event) {
if (!$(event.target).closest('.action.Translation, .plugin_translation').length) {
$('.plugin_translation').hide();
}
});
}
$(function(){
toggleSidebar();
toggleNavigation();
toggleSubmenu();
closeToc();
changeSearchInput();
enableAddNewPage();
enableTranslation();
});
});