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