1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/* global globalRootUrl, globalTranslate, globalWebAdminLanguage, sessionStorage */ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* sidebarMenuShowActive object for managing the highlighting of the active sidebar menu item. |
23
|
|
|
* @module sidebarMenuShowActive |
24
|
|
|
*/ |
25
|
|
|
const sidebarMenuShowActive = { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* jQuery object for the sidebar menu. |
29
|
|
|
* @type {jQuery} |
30
|
|
|
*/ |
31
|
|
|
$sidebarMenu: $('#sidebar-menu'), |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initializes the sidebar menu and sets the active menu item. |
35
|
|
|
*/ |
36
|
|
|
initialize() { |
37
|
|
|
sidebarMenuShowActive.$sidebarMenu |
38
|
|
|
.sidebar({}) |
39
|
|
|
.sidebar('setting', 'transition', 'push') |
40
|
|
|
.sidebar('setting', 'dimPage', false); |
41
|
|
|
sidebarMenuShowActive.makeMenuActiveElement(); |
42
|
|
|
}, |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Sets the active menu item in the sidebar based on the current URL. |
46
|
|
|
*/ |
47
|
|
|
makeMenuActiveElement() { |
48
|
|
|
const current = window.location.href; |
49
|
|
|
$.each($('#sidebar-menu a'), (index, value) => { |
50
|
|
|
const $this = $(value); |
51
|
|
|
$this.removeClass('active'); |
52
|
|
|
// if the current path is like this link, make it active |
53
|
|
|
const needle = $this.attr('href') |
54
|
|
|
.replace('/index', '') |
55
|
|
|
.replace('/modify', ''); |
56
|
|
|
|
57
|
|
|
if (current.indexOf(needle) !== -1 |
58
|
|
|
&& !$this.hasClass('logo')) { |
59
|
|
|
$this.addClass('active'); |
60
|
|
|
} |
61
|
|
|
}); |
62
|
|
|
}, |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Initialize highlighting the active sidebar menu item. |
68
|
|
|
*/ |
69
|
|
|
$(document).ready(() => { |
70
|
|
|
sidebarMenuShowActive.initialize(); |
71
|
|
|
}); |
72
|
|
|
|