Skip to content

Commit 25aea3e

Browse files
committed
Refactor responsive menu
1 parent 5161f99 commit 25aea3e

File tree

5 files changed

+120
-35
lines changed

5 files changed

+120
-35
lines changed

static/css/mpg.css

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
}
77

8+
@media screen and (min-width: 768px) {
9+
10+
.navbar {
11+
12+
flex-flow: row nowrap;
13+
-ms-flex-pack: start;
14+
justify-content: flex-start;
15+
16+
17+
}
18+
19+
}
20+
821
.bg-mongodb {
922

1023
background-color: #13aa52;
@@ -15,9 +28,78 @@
1528

1629
position: relative;
1730
left: 0;
18-
top: 15px;
31+
top: 4px;
32+
33+
padding: 5px;
34+
35+
}
36+
37+
.navbar.menu-expanded .navbar-brand {
38+
39+
display: none;
40+
41+
}
42+
43+
.navbar-nav {
44+
45+
display: none;
46+
47+
}
48+
49+
.navbar.menu-expanded .navbar-nav {
50+
51+
display: -ms-flexbox;
52+
display: flex;
53+
-ms-flex-direction: column;
54+
flex-direction: column;
55+
56+
width: 100%;
57+
margin-top: 35px;
58+
59+
}
1960

20-
padding-bottom: 15px;
61+
@media screen and (min-width: 768px) {
62+
63+
.navbar-brand, .navbar-nav .nav-link {
64+
65+
top: 15px;
66+
padding-top: 10px;
67+
padding-bottom: 15px;
68+
69+
}
70+
71+
.navbar-nav {
72+
73+
display: -ms-flexbox;
74+
display: flex;
75+
-ms-flex-direction: row;
76+
flex-direction: row;
77+
78+
}
79+
80+
}
81+
82+
#menu-toggle-button {
83+
84+
border: none;
85+
background: none;
86+
87+
display: block;
88+
position: absolute;
89+
right: 10px;
90+
top: 10px;
91+
92+
color: white;
93+
94+
}
95+
96+
@media screen and (min-width: 768px) {
97+
98+
#menu-toggle-button {
99+
100+
display: none;
101+
102+
}
21103

22104
}
23105

static/js/mpg.collection.indexes.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ MPG.collectionIndexes = [];
4141
*/
4242
MPG.helpers = {};
4343

44-
/**
45-
* Indicates if device is extra small.
46-
*
47-
* @returns {boolean}
48-
*/
49-
MPG.helpers.isXsDevice = function() {
50-
51-
return window.matchMedia('(max-width: 576px)').matches;
52-
53-
};
54-
5544
/**
5645
* Does an ajax request.
5746
*
@@ -83,21 +72,6 @@ MPG.helpers.doAjaxRequest = function(method, url, successCallback, body) {
8372

8473
};
8574

86-
/**
87-
* Fixes responsive design.
88-
*
89-
* @returns {void}
90-
*/
91-
MPG.fixResponsiveDesign = function() {
92-
93-
if ( MPG.helpers.isXsDevice() ) {
94-
95-
document.querySelector('#mpg-app-name').innerHTML = 'M';
96-
97-
}
98-
99-
};
100-
10175
/**
10276
* Reloads collections of a specific database.
10377
*
@@ -256,6 +230,19 @@ MPG.reloadCollectionIndexes = function() {
256230
*/
257231
MPG.eventListeners = {};
258232

233+
/**
234+
* Adds an event listener on "Menu toggle" button.
235+
*
236+
* @returns {void}
237+
*/
238+
MPG.eventListeners.addMenuToggle = function() {
239+
240+
document.querySelector('#menu-toggle-button').addEventListener('click', function() {
241+
document.querySelector('.navbar').classList.toggle('menu-expanded');
242+
});
243+
244+
};
245+
259246
/**
260247
* Adds an event listener on each database.
261248
*
@@ -411,8 +398,7 @@ MPG.eventListeners.addDropIndex = function() {
411398
// When document is ready:
412399
window.addEventListener('DOMContentLoaded', function(_event) {
413400

414-
MPG.fixResponsiveDesign();
415-
401+
MPG.eventListeners.addMenuToggle();
416402
MPG.eventListeners.addDatabases();
417403
MPG.eventListeners.addCreateIndex();
418404

static/js/mpg.database.query.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ MPG.fixResponsiveDesign = function() {
295295

296296
if ( MPG.helpers.isXsDevice() ) {
297297

298-
document.querySelector('#mpg-app-name').innerHTML = 'M';
299298
document.querySelector('#mpg-insert-one-button').innerHTML = 'Insert';
300299
document.querySelector('#mpg-delete-one-button').innerHTML = 'Delete';
301300

@@ -351,6 +350,19 @@ MPG.reloadCollections = function(databaseName) {
351350
*/
352351
MPG.eventListeners = {};
353352

353+
/**
354+
* Adds an event listener on "Menu toggle" button.
355+
*
356+
* @returns {void}
357+
*/
358+
MPG.eventListeners.addMenuToggle = function() {
359+
360+
document.querySelector('#menu-toggle-button').addEventListener('click', function() {
361+
document.querySelector('.navbar').classList.toggle('menu-expanded');
362+
});
363+
364+
};
365+
354366
/**
355367
* Adds an event listener on each database.
356368
*
@@ -827,6 +839,7 @@ window.addEventListener('DOMContentLoaded', function(_event) {
827839
MPG.initializeCodeMirror();
828840
MPG.fixResponsiveDesign();
829841

842+
MPG.eventListeners.addMenuToggle();
830843
MPG.eventListeners.addDatabases();
831844
MPG.eventListeners.addInsertOne();
832845
MPG.eventListeners.addCount();

views/collection.indexes.tpl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
<body>
2323

24-
<nav class="navbar navbar-expand sticky-top navbar-dark bg-mongodb">
24+
<nav class="navbar sticky-top navbar-dark bg-mongodb">
2525

26-
<a id="mpg-app-name" class="navbar-brand" href="<?php echo MPG_BASE_URL; ?>/index"><?php echo MPG_APP_NAME; ?></a>
26+
<a class="navbar-brand" href="<?php echo MPG_BASE_URL; ?>/index"><?php echo MPG_APP_NAME; ?></a>
2727

2828
<div class="navbar-nav">
2929
<a class="nav-item nav-link" href="<?php echo MPG_BASE_URL; ?>/createDatabase">Create database</a>
@@ -32,6 +32,8 @@
3232
<a class="nav-item nav-link" href="<?php echo MPG_BASE_URL; ?>/logout">Logout</a>
3333
</div>
3434

35+
<button id="menu-toggle-button"><i class="fa fa-bars" aria-hidden="true"></i></button>
36+
3537
</nav>
3638

3739
<div class="container-fluid">

views/database.query.tpl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
<body>
3333

34-
<nav class="navbar navbar-expand sticky-top navbar-dark bg-mongodb">
34+
<nav class="navbar sticky-top navbar-dark bg-mongodb">
3535

36-
<a id="mpg-app-name" class="navbar-brand" href="<?php echo MPG_BASE_URL; ?>/index"><?php echo MPG_APP_NAME; ?></a>
36+
<a class="navbar-brand" href="<?php echo MPG_BASE_URL; ?>/index"><?php echo MPG_APP_NAME; ?></a>
3737

3838
<div class="navbar-nav">
3939
<a class="nav-item nav-link" href="<?php echo MPG_BASE_URL; ?>/createDatabase">Create database</a>
@@ -42,6 +42,8 @@
4242
<a class="nav-item nav-link" href="<?php echo MPG_BASE_URL; ?>/logout">Logout</a>
4343
</div>
4444

45+
<button id="menu-toggle-button"><i class="fa fa-bars" aria-hidden="true"></i></button>
46+
4547
</nav>
4648

4749
<div class="container-fluid">

0 commit comments

Comments
 (0)