Skip to content

Commit 5b14560

Browse files
committed
Move inline nav JavaScript to nav.js file
1 parent 56ee132 commit 5b14560

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

docs/source/_assets/js/nav.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $.when($.ready).then(function() {
33

44
// Allow opening links in new tabs
55
if (event.metaKey) {
6-
return
6+
return
77
}
88

99
// Prevent following link
@@ -25,8 +25,8 @@ $.when($.ready).then(function() {
2525
var nav = $(html).find('#nav').html()
2626
var content = $(html).find('#content').html()
2727

28-
$('#sidebar').addClass("hidden");
29-
$('.js-close-sidebar').addClass("hidden");
28+
$('#sidebar').addClass('hidden')
29+
$('#sidebar-close').addClass('hidden')
3030

3131
// Update the page
3232
$('title').text(title)
@@ -38,21 +38,33 @@ $.when($.ready).then(function() {
3838

3939
// Add page load to brower history
4040
window.history.pushState({
41-
"title": title,
42-
"nav": $(html).find('#nav').html(),
43-
"content": $(html).find('#content').html()
41+
'title': title,
42+
'nav': $(html).find('#nav').html(),
43+
'content': $(html).find('#content').html()
4444
}, '', href)
4545
})
4646
})
4747

4848
// Load page history (for back/forward nav)
4949
window.onpopstate = function(e) {
50-
if(e.state){
50+
if(e.state){
5151

52-
// Update the page
53-
$('title').text(e.state.title)
54-
$('#nav').html(e.state.nav)
55-
$('#content').html(e.state.content)
56-
}
52+
// Update the page
53+
$('title').text(e.state.title)
54+
$('#nav').html(e.state.nav)
55+
$('#content').html(e.state.content)
56+
}
5757
}
58+
59+
// Close sidebar (mobile)
60+
$('#sidebar-close').on('click', function () {
61+
$('#sidebar').addClass('hidden')
62+
$('#sidebar-close').addClass('hidden')
63+
})
64+
65+
// Show sidebar (mobile)
66+
$('#sidebar-open').on('click', function () {
67+
$('#sidebar').removeClass('hidden')
68+
$('#sidebar-close').removeClass('hidden')
69+
})
5870
})

docs/source/_layouts/documentation.blade.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@
159159
<div class="md:ml-80">
160160
<div class="fixed w-full z-20">
161161
<div class="pin-t bg-white md:hidden relative border-b border-grey-light h-12 flex items-center">
162-
<div class="js-open-sidebar absolute pin-l pin-y px-4 flex items-center">
162+
<div id="sidebar-open" class="absolute pin-l pin-y px-4 flex items-center">
163163
<svg class="h-4 cursor-pointer text-grey" role="button" fill="#777" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
164164
</div>
165-
<div class="mx-auto inline-flex items-center">
165+
<a href="/" class="mx-auto inline-flex items-center">
166166
<svg class="h-4" viewBox="0 0 60 36" xmlns="http://www.w3.org/2000/svg">
167167
<path d="M15 12c2-8 7-12 15-12 12 0 13.5 9 19.5 10.5 4 1 7.5-.5 10.5-4.5-2 8-7 12-15 12-12 0-13.5-9-19.5-10.5-4-1-7.5.5-10.5 4.5zM0 30c2-8 7-12 15-12 12 0 13.5 9 19.5 10.5 4 1 7.5-.5 10.5-4.5-2 8-7 12-15 12-12 0-13.5-9-19.5-10.5-4-1-7.5.5-10.5 4.5z" fill="url(#logoGradient)" fill-rule="evenodd"></path>
168168
</svg>
169-
</div>
170-
<div class="hidden js-close-sidebar">
169+
</a>
170+
<div id="sidebar-close" class="hidden">
171171
<div class="flex items-center absolute pin-r pin-y px-4">
172172
<svg class="h-4 cursor-pointer text-grey" role="button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M10 8.586L2.929 1.515 1.515 2.929 8.586 10l-7.071 7.071 1.414 1.414L10 11.414l7.071 7.071 1.414-1.414L11.414 10l7.071-7.071-1.414-1.414L10 8.586z"/></svg>
173173
</div>
@@ -184,21 +184,6 @@
184184
</div>
185185
</div>
186186
<script src="/js/app.js"></script>
187-
<script>
188-
var closeSidebar = function () {
189-
$('#sidebar').addClass("hidden");
190-
$('.js-close-sidebar').addClass("hidden");
191-
}
192-
193-
$('.js-close-sidebar').on('click', function () {
194-
closeSidebar();
195-
});
196-
197-
$('.js-open-sidebar').on('click', function () {
198-
$('#sidebar').removeClass("hidden");
199-
$('.js-close-sidebar').removeClass("hidden");
200-
});
201-
</script>
202187
</div>
203188
</div>
204189
</div>

0 commit comments

Comments
 (0)