|
1 | | -var Ggrach = { |
2 | | - DebugBar: { |
3 | | - init: function () { |
4 | | - document.addEventListener('DOMContentLoaded', function () { |
5 | | - if (Ggrach.Utils.User.isAdmin()) |
| 1 | +var Ggrach = {}; |
| 2 | + |
| 3 | +Ggrach.Utils = {}; |
| 4 | + |
| 5 | + |
| 6 | +Ggrach.DebugBar = { |
| 7 | + |
| 8 | + initHotKeys: function () { |
| 9 | + // Закрываем панель при нажатии на esc |
| 10 | + window.addEventListener('keydown', Ggrach.Handlers.onKeyEsc, true); |
| 11 | + }, |
| 12 | + |
| 13 | + init: function () { |
| 14 | + |
| 15 | + document.addEventListener('DOMContentLoaded', function () { |
| 16 | + if (Ggrach.Utils.User.isAdmin()) |
| 17 | + { |
| 18 | + if (Ggrach.Utils.Screen.isMobile()) |
6 | 19 | { |
7 | | - if (Ggrach.Utils.Screen.isMobile()) |
8 | | - { |
9 | | - document.querySelector('.ggrach__debug_bar').remove(); |
10 | | - } else |
| 20 | + Ggrach.DebugBar.removeBar(); |
| 21 | + } else |
| 22 | + { |
| 23 | + Ggrach.DebugBar.initHotKeys(); |
| 24 | + |
| 25 | + // Закрываем панель при нажатии на область затемнения |
| 26 | + Ggrach.Utils.DOM.getOverlay().addEventListener('click', function () { |
| 27 | + document.querySelector('[data-type-notice].active').click(); |
| 28 | + }); |
| 29 | + |
| 30 | + if (Ggrach.Utils.DOM.getButtonsNotice()) |
11 | 31 | { |
12 | | - var $logsItems = document.querySelectorAll('[data-click="show_notice_panel"]'); |
13 | | - |
14 | | - if ($logsItems) |
15 | | - { |
16 | | - $logsItems.forEach(function (element) { |
17 | | - element.addEventListener('click', function (e) { |
18 | | - var type = e.target.dataset.typeNotice; |
19 | | - |
20 | | - document.querySelectorAll('.ggrach__debug_bar__log').forEach(function (element) { |
21 | | - |
22 | | - element.scrollTop = 0; |
23 | | - |
24 | | - if (element.dataset.typeNotice !== type) |
25 | | - { |
26 | | - element.style.display = 'none'; |
27 | | - } |
28 | | - |
29 | | - }); |
30 | | - |
31 | | - var $targetLogPanel = document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]'); |
32 | | - |
33 | | - $logsItems.forEach(function (el) { |
34 | | - el.classList.remove('active'); |
35 | | - }); |
36 | | - |
37 | | - if ($targetLogPanel.style.display === 'block') |
38 | | - { |
39 | | - e.target.classList.remove('active'); |
40 | | - document.querySelector('body').style.overflow = null; |
41 | | - $targetLogPanel.style.display = 'none'; |
42 | | - document.querySelector('.ggrach__overlay').style.display = 'none'; |
43 | | - } else |
44 | | - { |
45 | | - e.target.classList.add('active'); |
46 | | - document.querySelector('body').style.overflow = 'hidden'; |
47 | | - $targetLogPanel.style.display = 'block'; |
48 | | - document.querySelector('.ggrach__overlay').style.display = 'block'; |
49 | | - } |
50 | | - }); |
51 | | - }); |
52 | | - } |
| 32 | + Ggrach.Utils.DOM.getButtonsNotice().forEach(function (element) { |
| 33 | + element.addEventListener('click', Ggrach.Handlers.onClickItemNotice); |
| 34 | + }); |
53 | 35 | } |
54 | 36 | } |
55 | | - }); |
56 | | - } |
| 37 | + } |
| 38 | + }); |
| 39 | + }, |
| 40 | + |
| 41 | + removeBar: function () { |
| 42 | + document.querySelector('.ggrach__debug_bar').remove(); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +Ggrach.Utils.Screen = { |
| 47 | + isMobile: function () { |
| 48 | + return window.matchMedia("(max-width: 1100px)").matches; |
| 49 | + } |
| 50 | +}; |
| 51 | + |
| 52 | +Ggrach.Utils.User = { |
| 53 | + isAdmin: function () { |
| 54 | + return document.getElementById('panel') && |
| 55 | + document.getElementById('bx-panel-admin-tab'); |
57 | 56 | } |
58 | 57 | }; |
59 | 58 |
|
60 | | -Ggrach.Utils = { |
61 | | - User: { |
62 | | - isAdmin: function () { |
63 | | - return document.getElementById('panel') && |
64 | | - document.getElementById('bx-panel-admin-tab'); |
| 59 | +Ggrach.Utils.DOM = { |
| 60 | + |
| 61 | + getDebugBarLogsType: function (type) { |
| 62 | + return document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]') |
| 63 | + }, |
| 64 | + |
| 65 | + getDebugBarLogs: function () { |
| 66 | + return document.querySelectorAll('.ggrach__debug_bar__log'); |
| 67 | + }, |
| 68 | + |
| 69 | + getButtonsNotice: function () { |
| 70 | + return document.querySelectorAll('[data-click="show_notice_panel"]'); |
| 71 | + }, |
| 72 | + |
| 73 | + getOverlay: function () { |
| 74 | + return document.querySelector('.ggrach__overlay'); |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +Ggrach.Handlers = { |
| 79 | + |
| 80 | + // Нажатие клавиши esc |
| 81 | + onKeyEsc: function (e) { |
| 82 | + if ((e.key == 'Escape' || e.key == 'Esc' || e.keyCode == 27) && (e.target.nodeName == 'BODY')) { |
| 83 | + |
| 84 | + if (document.querySelector('[data-type-notice].active')) |
| 85 | + { |
| 86 | + document.querySelector('[data-type-notice].active').click(); |
| 87 | + } |
65 | 88 | } |
66 | 89 | }, |
67 | 90 |
|
68 | | - Screen: { |
69 | | - isMobile: function () { |
70 | | - return window.matchMedia("(max-width: 1100px)").matches; |
| 91 | + onClickItemNotice: function (e) { |
| 92 | + var type = e.target.dataset.typeNotice; |
| 93 | + |
| 94 | + Ggrach.Utils.DOM.getDebugBarLogs().forEach(function (element) { |
| 95 | + |
| 96 | + element.scrollTop = 0; |
| 97 | + |
| 98 | + if (element.dataset.typeNotice !== type) |
| 99 | + { |
| 100 | + element.style.display = 'none'; |
| 101 | + } |
| 102 | + |
| 103 | + }); |
| 104 | + |
| 105 | + var $targetLogPanel = Ggrach.Utils.DOM.getDebugBarLogsType(type); |
| 106 | + |
| 107 | + Ggrach.Utils.DOM.getButtonsNotice().forEach(function (el) { |
| 108 | + el.classList.remove('active'); |
| 109 | + }); |
| 110 | + |
| 111 | + if ($targetLogPanel.style.display === 'block') |
| 112 | + { |
| 113 | + e.target.classList.remove('active'); |
| 114 | + document.querySelector('body').style.overflow = null; |
| 115 | + $targetLogPanel.style.display = 'none'; |
| 116 | + Ggrach.Utils.DOM.getOverlay().style.display = 'none'; |
| 117 | + } else |
| 118 | + { |
| 119 | + e.target.classList.add('active'); |
| 120 | + document.querySelector('body').style.overflow = 'hidden'; |
| 121 | + $targetLogPanel.style.display = 'block'; |
| 122 | + Ggrach.Utils.DOM.getOverlay().style.display = 'block'; |
71 | 123 | } |
72 | 124 | } |
73 | 125 | }; |
|
0 commit comments