Reality123b commited on
Commit
6f9ece3
·
verified ·
1 Parent(s): 064fb37

Update application/static/js/components/navbar.js

Browse files
application/static/js/components/navbar.js CHANGED
@@ -1,36 +1,73 @@
1
- // application/static/js/components/navbar.js
2
  class Navbar {
3
  constructor(UIManager) {
4
- console.log("Navbar constructor called"); // Keep this
5
- // this.uiManager = UIManager;
6
- // this.menu = this.uiManager.menu;
7
- // this.hamburger = this.uiManager.hamburger;
8
- // this.container = this.uiManager.container;
9
- // this.state = true; // true = open, false = closed
10
- // this.menuWidth = 0;
11
- // this.containerWidth = this.container.clientWidth;
12
- // this.NAV_AREA_LARGE = 20; // % of window width
13
- // this.NAV_AREA_MEDIUM = 25; // % of window width
14
- // this.NAV_AREA_SMALL = 60; // % of window width
15
- // this.ANIMATION_STEP = 5; // pixels per frame
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
  run() {
19
- console.log("Navbar run called"); //Keep this
20
- // this.navArea = this.calculateNavArea();
21
- // this.nav = {
22
- // open: () => this.animateNav('open'),
23
- // close: () => this.animateNav('close'),
24
- // };
25
-
26
- // if (window.innerWidth <= 785) {
27
- // this.state = false;
28
- // } else {
29
- // this.nav.open();
30
- // }
31
-
32
- // this.hamburger.addEventListener('click', () => this.toggleState());
 
 
 
 
 
 
 
 
 
33
  }
34
  }
35
 
36
- export default Navbar
 
1
+ // navbar.js
2
  class Navbar {
3
  constructor(UIManager) {
4
+ this.uiManager = UIManager;
5
+ this.menu = this.uiManager.menu;
6
+ this.hamburger = this.uiManager.hamburger;
7
+ this.container = this.uiManager.container;
8
+ this.state = true; // true = open, false = closed
9
+ this.menuWidth = 0;
10
+ this.containerWidth = this.container.clientWidth;
11
+ this.NAV_AREA_LARGE = 20; // % of window width
12
+ this.NAV_AREA_MEDIUM = 25; // % of window width
13
+ this.NAV_AREA_SMALL = 60; // % of window width
14
+ this.ANIMATION_STEP = 5; // pixels per frame
15
+
16
+ console.log("Navbar constructor: uiManager =", this.uiManager);
17
+ console.log("Navbar constructor: menu =", this.menu);
18
+ }
19
+
20
+ calculateNavArea() {
21
+ if (window.innerWidth > 785) {
22
+ return window.innerWidth < 1100
23
+ ? window.innerWidth * (this.NAV_AREA_MEDIUM / 100)
24
+ : window.innerWidth * (this.NAV_AREA_LARGE / 100);
25
+ }
26
+ return window.innerWidth * (this.NAV_AREA_SMALL / 100);
27
+ }
28
+
29
+ animateNav(action) {
30
+ if (action === 'open' && this.menuWidth < this.navArea) {
31
+ this.menuWidth += this.ANIMATION_STEP;
32
+ } else if (action === 'close' && this.menuWidth > 0) {
33
+ this.menuWidth -= this.ANIMATION_STEP;
34
+ } else {
35
+ return; // Stop animation
36
+ }
37
+
38
+ this.menu.style.width = `${this.menuWidth}px`;
39
+ if(window.innerWidth>775){
40
+ this.container.style.width = `${this.containerWidth - this.menuWidth}px`;
41
+ this.container.style.left = `${this.menuWidth}px`;
42
+ }
43
+ requestAnimationFrame(() => this.animateNav(action));
44
  }
45
 
46
  run() {
47
+ console.log("Navbar run called");
48
+ this.navArea = this.calculateNavArea();
49
+ this.nav = {
50
+ open: () => this.animateNav('open'),
51
+ close: () => this.animateNav('close'),
52
+ };
53
+
54
+ if (window.innerWidth <= 785) {
55
+ this.state = false;
56
+ } else {
57
+ this.nav.open();
58
+ }
59
+
60
+ this.hamburger.addEventListener('click', () => this.toggleState());
61
+ }
62
+
63
+ toggleState() {
64
+ if (this.state) {
65
+ this.nav.close();
66
+ } else {
67
+ this.nav.open();
68
+ }
69
+ this.state = !this.state;
70
  }
71
  }
72
 
73
+ export default Navbar;