Skip to content

Commit 497b4b0

Browse files
committed
the overlay should disappear when the user resizes the screen
Closes #744 Closes #742 LGTM given by: @sethladd Squashed commit of the following: commit f829c5c Author: Seth Ladd <[email protected]> Date: Wed Jul 29 15:22:21 2015 -0700 from review commit 499c84f Author: Seth Ladd <[email protected]> Date: Wed Jul 29 14:57:42 2015 -0700
1 parent e1c89a6 commit 497b4b0

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

lib/resources/script.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,27 @@ function initScroller() {
2828
function initSideNav() {
2929
var leftNavToggle = document.getElementById('sidenav-left-toggle');
3030
var leftDrawer = document.querySelector('.sidebar-offcanvas-left');
31+
var overlay = document.getElementById('overlay-under-drawer');
3132

32-
var overlay = document.createElement('div');
33-
overlay.id = 'overlay-under-drawer';
34-
overlay.addEventListener('click', function(e) {
35-
if (leftDrawer) leftDrawer.classList.remove('active');
36-
document.body.removeChild(overlay);
37-
});
33+
function toggleBoth() {
34+
if (leftDrawer) {
35+
leftDrawer.classList.toggle('active');
36+
}
37+
38+
if (overlay) {
39+
overlay.classList.toggle('active');
40+
}
41+
}
42+
43+
if (overlay) {
44+
overlay.addEventListener('click', function(e) {
45+
toggleBoth();
46+
});
47+
}
3848

3949
if (leftNavToggle) {
4050
leftNavToggle.addEventListener('click', function(e) {
41-
if (leftDrawer) {
42-
leftDrawer.classList.toggle('active');
43-
document.body.appendChild(overlay);
44-
}
51+
toggleBoth();
4552
});
4653
}
4754
}

lib/resources/styles.css

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,19 @@ button {
562562
margin-right: 24px;
563563
}
564564

565+
#overlay-under-drawer.active {
566+
opacity: 0.7;
567+
height: 100%;
568+
z-index: 1999;
569+
position: fixed;
570+
top: 0px;
571+
left: 0px;
572+
right: 0px;
573+
bottom: 0px;
574+
background-color: black;
575+
display: block;
576+
}
577+
565578
.sidebar-offcanvas-left {
566579
left:-100%;
567580
position:fixed;
@@ -610,12 +623,5 @@ button {
610623
}
611624

612625
#overlay-under-drawer {
613-
opacity: 0.7;
614-
width: 100%;
615-
height: 100%;
616-
z-index: 1999;
617-
position: fixed;
618-
top: 0px;
619-
left: 0px;
620-
background-color: black;
626+
display: none;
621627
}

lib/templates/_head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
<body>
2424

25+
<div id="overlay-under-drawer"></div>
26+
2527
<header class="container-fluid" id="title">
2628
<nav class="navbar navbar-fixed-top">
2729
<div class="container">

0 commit comments

Comments
 (0)