Skip to content

Commit 40cc82e

Browse files
author
Pascal MARTINEZ
committed
First published version
0 parents  commit 40cc82e

File tree

6 files changed

+892
-0
lines changed

6 files changed

+892
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CHANGE LOG: Toggle menu (z4m_togglemenu)
2+
3+
## Version 1.0, 2025-07-27
4+
First version.

LICENSE.TXT

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ZnetDK 4 Module Toggle menu (z4m_togglemenu)
2+
Adds to the the ZnetDK 4 Mobile application a menu button to hide or show the side navigation menu on large screen.
3+
4+
![Screenshot of the menu button provided by the ZnetDK 4 Mobile 'z4m_togglemenu' module](https://mobile.znetdk.fr/applications/default/public/images/modules/z4m_togglemenu/screenshot.png?v1)
5+
6+
## REQUIREMENTS
7+
- [ZnetDK 4 Mobile](/../../../znetdk4mobile) version 3.0 or higher,
8+
9+
10+
## INSTALLATION
11+
1. Copy module's code in the `./engine/modules/z4m_togglemenu/` subdirectory,
12+
2. Reload the application in your web browser to see the toggle menu button.
13+
14+
## CHANGE LOG
15+
See [CHANGELOG.md](CHANGELOG.md) file.
16+
17+
## CONTRIBUTING
18+
Your contribution to the **ZnetDK 4 Mobile** project is welcome. Please refer to the [CONTRIBUTING.md](https://github.com/pascal-martinez/znetdk4mobile/blob/master/CONTRIBUTING.md) file.

mod/config.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* ZnetDK, Starter Web Application for rapid & easy development
4+
* See official website https://mobile.znetdk.fr
5+
* Copyright (C) 2025 Pascal MARTINEZ (contact@znetdk.fr)
6+
* License GNU GPL https://www.gnu.org/licenses/gpl-3.0.html GNU GPL
7+
* --------------------------------------------------------------------
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
* --------------------------------------------------------------------
19+
* Parameters of the Toggle menu module
20+
*
21+
* File version: 1.0
22+
* Last update: 07/27/2025
23+
*/
24+
25+
26+
// VERSIONS
27+
define('MOD_Z4M_TOGGLEMENU_VERSION_NUMBER','1.0');
28+
define('MOD_Z4M_TOGGLEMENU_VERSION_DATE','2025-07-27');

public/js/minified/z4m_togglemenu-min.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/z4m_togglemenu.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* ZnetDK, Starter Web Application for rapid & easy development
3+
* See official website https://mobile.znetdk.fr
4+
* Copyright (C) 2025 Pascal MARTINEZ (contact@znetdk.fr)
5+
* License GNU GPL https://www.gnu.org/licenses/gpl-3.0.html GNU GPL
6+
* --------------------------------------------------------------------
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
* --------------------------------------------------------------------
18+
* Toggle menu module JS library
19+
*
20+
* File version: 1.0
21+
* Last update: 07/27/2025
22+
*/
23+
24+
// Once the document is fully loaded
25+
window.addEventListener("load", function() {
26+
if (!z4m.authentication.isRequired()) {
27+
new Z4M_ToggleMenu();
28+
}
29+
});
30+
31+
/* global z4m */
32+
class Z4M_ToggleMenu {
33+
#logoutLink
34+
#logoutButton
35+
#menuButton
36+
#sideMenuEl
37+
#sideMenuElWidth
38+
#adjustCenteringEls
39+
#workingAreaEl
40+
#footerContentNotLarge
41+
#workingAreaMarginLeft
42+
#mediaQueryObj
43+
#largeViewPortWidth = '993px'
44+
#localStorageisVisibleKey = 'Z4M_ToggleMenu_isVisible'
45+
constructor() {
46+
this.#logoutLink = document.getElementById('zdk-logout');
47+
this.#logoutButton = document.querySelector('#zdk-userpanel-modal button.logout');
48+
this.#menuButton = document.getElementById('zdk-side-nav-button');
49+
this.#sideMenuEl = document.getElementById('zdk-side-nav-menu');
50+
this.#workingAreaEl = document.querySelector('.w3-main');
51+
this.#adjustCenteringEls = document.querySelectorAll('.adjust-centering');
52+
this.#footerContentNotLarge = document.querySelector('#zdk-footer > div:first-of-type');
53+
54+
this.#sideMenuElWidth = this.#sideMenuEl.style.width;
55+
this.#workingAreaMarginLeft = this.#workingAreaEl.style.marginLeft;
56+
57+
this.#mediaQueryObj = window.matchMedia('(min-width: ' + this.#largeViewPortWidth + ')');
58+
this.#adjustMenuButtonPosition();
59+
60+
this.#setMenuButtonAlwaysVisible();
61+
this.#handleMenuButtonClickEvents();
62+
this.#handleLogoutEvents();
63+
this.#handleViewPortWidthChange();
64+
this.#applyMemorizedState();
65+
}
66+
#isLargeViewPort() {
67+
return this.#mediaQueryObj ? this.#mediaQueryObj.matches : false;
68+
}
69+
#setMenuButtonAlwaysVisible() {
70+
const largeTitleEl = document.querySelector('#zdk-header .banner-title-large');
71+
largeTitleEl.style.width = 'calc(100% - 50px)';
72+
this.#menuButton.classList.remove('w3-hide-large');
73+
this.#menuButton.style.position = 'relative';
74+
}
75+
#adjustMenuButtonPosition() {
76+
this.#menuButton.style.top = this.#isLargeViewPort() ? '4px' : '0';
77+
}
78+
#handleMenuButtonClickEvents() {
79+
const $this = this;
80+
this.#menuButton.addEventListener('click', function(){
81+
$this.#toggle();
82+
});
83+
}
84+
#handleViewPortWidthChange() {
85+
const $this = this;
86+
this.#mediaQueryObj.addEventListener('change', function() {
87+
$this.#adjustMenuButtonPosition();
88+
});
89+
}
90+
#handleLogoutEvents() {
91+
const $this = this;
92+
this.#logoutLink.addEventListener('click', hideMenuButton);
93+
this.#logoutButton.addEventListener('click', hideMenuButton);
94+
function hideMenuButton() {
95+
$this.#menuButton.classList.add('w3-hide-large');
96+
}
97+
}
98+
#memorizeState(isVisible) {
99+
z4m.browser.storeLocalData(this.#localStorageisVisibleKey, isVisible ? '1' : '0');
100+
}
101+
#applyMemorizedState() {
102+
const isVisible = z4m.browser.readLocalData(this.#localStorageisVisibleKey);
103+
if (isVisible === '0') {
104+
this.#toggle();
105+
}
106+
}
107+
#toggle() {
108+
if (this.#isLargeViewPort()
109+
&& this.#workingAreaEl.style.marginLeft === this.#workingAreaMarginLeft) {
110+
// Is visible so is set hidden
111+
this.#sideMenuEl.style.width = '0';
112+
this.#workingAreaEl.style.marginLeft = '0';
113+
this.#adjustCenteringEls.forEach((el) => {
114+
el.classList.add('w3-hide-large');
115+
});
116+
this.#footerContentNotLarge.classList.remove('w3-hide-large');
117+
this.#triggerCustomEvent(false);
118+
this.#memorizeState(false);
119+
} else {
120+
// Is hidden so is set visible
121+
this.#sideMenuEl.style.width = this.#sideMenuElWidth;
122+
this.#workingAreaEl.style.marginLeft = this.#workingAreaMarginLeft;
123+
this.#adjustCenteringEls.forEach((el) => {
124+
el.classList.remove('w3-hide-large');
125+
});
126+
this.#footerContentNotLarge.classList.add('w3-hide-large');
127+
if (this.#isLargeViewPort()) {
128+
this.#triggerCustomEvent(true);
129+
}
130+
this.#memorizeState(true);
131+
}
132+
}
133+
#triggerCustomEvent(isMenuVisible) {
134+
const customEvent = new CustomEvent("z4mtogglemenu", {
135+
detail: {
136+
bubbles: true,
137+
isMenuVisible: isMenuVisible
138+
}
139+
});
140+
return this.#sideMenuEl.dispatchEvent(customEvent);
141+
}
142+
143+
}
144+

0 commit comments

Comments
 (0)