Nucha commited on
Commit
f227001
·
verified ·
1 Parent(s): 82a8012

Create scripts.js

Browse files
Files changed (1) hide show
  1. scripts.js +162 -0
scripts.js ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Scripts for css grid dashboard */
2
+
3
+ $(document).ready(() => {
4
+ addResizeListeners();
5
+ setSidenavListeners();
6
+ setUserDropdownListener();
7
+ renderChart();
8
+ setMenuClickListener();
9
+ setSidenavCloseListener();
10
+ });
11
+
12
+ // Set constants and grab needed elements
13
+ const sidenavEl = $('.sidenav');
14
+ const gridEl = $('.grid');
15
+ const SIDENAV_ACTIVE_CLASS = 'sidenav--active';
16
+ const GRID_NO_SCROLL_CLASS = 'grid--noscroll';
17
+
18
+ function toggleClass(el, className) {
19
+ if (el.hasClass(className)) {
20
+ el.removeClass(className);
21
+ } else {
22
+ el.addClass(className);
23
+ }
24
+ }
25
+
26
+ // User avatar dropdown functionality
27
+ function setUserDropdownListener() {
28
+ const userAvatar = $('.header__avatar');
29
+
30
+ userAvatar.on('click', function(e) {
31
+ const dropdown = $(this).children('.dropdown');
32
+ toggleClass(dropdown, 'dropdown--active');
33
+ });
34
+ }
35
+
36
+ // Sidenav list sliding functionality
37
+ function setSidenavListeners() {
38
+ const subHeadings = $('.navList__subheading'); console.log('subHeadings: ', subHeadings);
39
+ const SUBHEADING_OPEN_CLASS = 'navList__subheading--open';
40
+ const SUBLIST_HIDDEN_CLASS = 'subList--hidden';
41
+
42
+ subHeadings.each((i, subHeadingEl) => {
43
+ $(subHeadingEl).on('click', (e) => {
44
+ const subListEl = $(subHeadingEl).siblings();
45
+
46
+ // Add/remove selected styles to list category heading
47
+ if (subHeadingEl) {
48
+ toggleClass($(subHeadingEl), SUBHEADING_OPEN_CLASS);
49
+ }
50
+
51
+ // Reveal/hide the sublist
52
+ if (subListEl && subListEl.length === 1) {
53
+ toggleClass($(subListEl), SUBLIST_HIDDEN_CLASS);
54
+ }
55
+ });
56
+ });
57
+ }
58
+
59
+ // Draw the chart
60
+ function renderChart() {
61
+ const chart = AmCharts.makeChart( "chartdiv", {
62
+ "type": "serial",
63
+ "theme": "light",
64
+ "dataProvider": [ {
65
+ "month": "Jan",
66
+ "visits": 2025
67
+ }, {
68
+ "month": "Feb",
69
+ "visits": 1882
70
+ }, {
71
+ "month": "Mar",
72
+ "visits": 1809
73
+ }, {
74
+ "month": "Apr",
75
+ "visits": 1322
76
+ }, {
77
+ "month": "May",
78
+ "visits": 1122
79
+ }, {
80
+ "month": "Jun",
81
+ "visits": 1114
82
+ }, {
83
+ "month": "Jul",
84
+ "visits": 984
85
+ }, {
86
+ "month": "Aug",
87
+ "visits": 711
88
+ }, {
89
+ "month": "Sept",
90
+ "visits": 665
91
+ }, {
92
+ "month": "Oct",
93
+ "visits": 580
94
+ } ],
95
+ "valueAxes": [ {
96
+ "gridColor": "#FFFFFF",
97
+ "gridAlpha": 0.2,
98
+ "dashLength": 0
99
+ } ],
100
+ "gridAboveGraphs": true,
101
+ "startDuration": 1,
102
+ "graphs": [ {
103
+ "balloonText": "[[category]]: <b>[[value]]</b>",
104
+ "fillAlphas": 0.8,
105
+ "lineAlpha": 0.2,
106
+ "type": "column",
107
+ "valueField": "visits"
108
+ } ],
109
+ "chartCursor": {
110
+ "categoryBalloonEnabled": false,
111
+ "cursorAlpha": 0,
112
+ "zoomable": false
113
+ },
114
+ "categoryField": "month",
115
+ "categoryAxis": {
116
+ "gridPosition": "start",
117
+ "gridAlpha": 0,
118
+ "tickPosition": "start",
119
+ "tickLength": 20
120
+ },
121
+ "export": {
122
+ "enabled": false
123
+ }
124
+ });
125
+ }
126
+
127
+ function toggleClass(el, className) {
128
+ if (el.hasClass(className)) {
129
+ el.removeClass(className);
130
+ } else {
131
+ el.addClass(className);
132
+ }
133
+ }
134
+
135
+ // If user opens the menu and then expands the viewport from mobile size without closing the menu,
136
+ // make sure scrolling is enabled again and that sidenav active class is removed
137
+ function addResizeListeners() {
138
+ $(window).resize(function(e) {
139
+ const width = window.innerWidth; console.log('width: ', width);
140
+
141
+ if (width > 750) {
142
+ sidenavEl.removeClass(SIDENAV_ACTIVE_CLASS);
143
+ gridEl.removeClass(GRID_NO_SCROLL_CLASS);
144
+ }
145
+ });
146
+ }
147
+
148
+ // Menu open sidenav icon, shown only on mobile
149
+ function setMenuClickListener() {
150
+ $('.header__menu').on('click', function(e) { console.log('clicked menu icon');
151
+ toggleClass(sidenavEl, SIDENAV_ACTIVE_CLASS);
152
+ toggleClass(gridEl, GRID_NO_SCROLL_CLASS);
153
+ });
154
+ }
155
+
156
+ // Sidenav close icon
157
+ function setSidenavCloseListener() {
158
+ $('.sidenav__brand-close').on('click', function(e) {
159
+ toggleClass(sidenavEl, SIDENAV_ACTIVE_CLASS);
160
+ toggleClass(gridEl, GRID_NO_SCROLL_CLASS);
161
+ });
162
+ }