blob: 8b5c029d2b9d6a614f939f5a71bdbb167f61ba5d (
plain)
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
|
$(document).ready(function () {
removeOverlayAndCloseSidebar()
documentLoaded()
$(window).on("resize", function () {
const screenWidth = window.innerWidth
if (screenWidth <= 991) return userIsInTabletScreenWidth(screenWidth)
return removeOverlayAndButtons(screenWidth)
})
})
function removeButtons() {
const alreadyCreatedOpenButtonCheck = $('.openLeftSidebarMenuButton')
const alreadyCreatedCloseButtonCheck = $('.closeButtonDivLine')
if(alreadyCreatedOpenButtonCheck[0]) alreadyCreatedOpenButtonCheck[0].remove()
if(alreadyCreatedCloseButtonCheck[0]) alreadyCreatedCloseButtonCheck[0].remove()
}
function documentLoaded() {
const screenWidth = window.innerWidth
if (screenWidth <= 991) return userIsInTabletScreenWidth(screenWidth)
return
}
function userIsInTabletScreenWidth(screenWidth) {
const alreadyCreatedButtonCheck = $('.openLeftSidebarMenuButton')
if (alreadyCreatedButtonCheck[0]) return
createOpenSidebarButton(screenWidth)
createCloseSidebarButton(screenWidth)
removeOverlayAndCloseSidebar()
}
function createOverlay(screenWidth) {
const contentContainer = $('.wy-nav-content')
contentContainer.addClass('overlay')
const overlayDiv = `
<div class='overlayDiv' />
`
contentContainer.append(overlayDiv)
$('.wy-nav-content.overlay').on('click', onOverlayClickHandler)
}
function onOverlayClickHandler() {
removeOverlayAndCloseSidebar()
}
function removeOverlayAndCloseSidebar() {
const screenWidth = window.innerWidth
const contentContainer = $('.wy-nav-content')
contentContainer.removeClass('overlay')
const overlayDiv = $('.overlayDiv')
overlayDiv.remove()
const leftSidebarOpened = $('nav.wy-nav-side.shift')
leftSidebarOpened.removeClass('shift')
const leftSidebar = $('nav.wy-nav-side')
// that's working don't touch
if(screenWidth > 991) {
// when user is not in tablet -> we add classes on opened sidebar and remove classes on closed sidebar
const contentSection = $('section.wy-nav-content-wrap')
const contentDiv = $('div.wy-nav-content')
contentSection.addClass('wy-nav-content-wrap-opened-sidebar')
contentDiv.addClass('wy-nav-content-opened-sidebar')
contentSection.removeClass('wy-nav-content-wrap-closed-sidebar')
contentDiv.removeClass('wy-nav-content-closed-sidebar')
leftSidebar.removeClass('display_none')
return
}
if(screenWidth <= 991) {
// I add closed classes to make contentContainer 100% width
const contentSection = $('section.wy-nav-content-wrap')
const contentDiv = $('div.wy-nav-content')
contentSection.removeClass('wy-nav-content-wrap-opened-sidebar')
contentDiv.removeClass('wy-nav-content-opened-sidebar')
contentSection.addClass('wy-nav-content-wrap-closed-sidebar')
contentDiv.addClass('wy-nav-content-closed-sidebar')
leftSidebar.addClass('display_none')
}
}
function createOpenSidebarButton() {
const divToInsert = $('div[role=navigation][aria-label="Page navigation"]')
divToInsert[0].insertAdjacentHTML('afterbegin', formOpenSidebarButton())
const newlyCreatedButton = $('.openLeftSidebarMenuButton')
newlyCreatedButton.on('click', onOpenLeftSidebarMenuButtonClickHandler)
}
function onOpenLeftSidebarMenuButtonClickHandler(e) {
e.stopPropagation()
const leftSidebar = $('nav.wy-nav-side')
const leftSidebarOpened = $('nav.wy-nav-side.shift')
if(leftSidebarOpened[0]) {
// leftSidebarOpened.removeClass('shift')
removeOverlayAndCloseSidebar()
}
createOverlay()
if(leftSidebar.hasClass('display_none')) leftSidebar.removeClass('display_none')
if(leftSidebar.hasClass('.additionalStylesForShift')) leftSidebar.removeClass('.additionalStylesForShift')
// here I add classes to contentSection and contentDiv to make them margined left and remove closed classes if any
const contentSection = $('section.wy-nav-content-wrap')
const contentDiv = $('div.wy-nav-content')
// contentSection.removeClass('wy-nav-content-wrap-closed-sidebar')
// contentDiv.removeClass('wy-nav-content-closed-sidebar')
// contentSection.addClass('wy-nav-content-wrap-opened-sidebar')
// contentDiv.addClass('wy-nav-content-opened-sidebar')
return leftSidebar.addClass('shift')
}
function createCloseSidebarButton(screenWidth) {
const updatedLeftSidebarScrollDiv = $('nav.wy-nav-side')
const alreadyCreatedButtonCheck = $('div.closeLeftSidebarMenuButton')
if(alreadyCreatedButtonCheck[0]) return
updatedLeftSidebarScrollDiv[0].insertAdjacentHTML('beforeend', formCloseLeftSidebarButton())
updatedLeftSidebarScrollDiv.addClass('additionalStylesForShift')
const createdCloseSidebarButton = $('.closeButtonDivLine')
createdCloseSidebarButton.on('click', function () {
removeOverlayAndCloseSidebar()
})
}
function formOpenSidebarButton() {
return `
<div class='openLeftSidebarMenuButton'>
${hamburgerIcon}
</div>
`
}
function formCloseLeftSidebarButton() {
return `
<div class='closeButtonDivLine'>
<div class='closeLeftSidebarMenuButton'>
Close
</div>
</div>
`
}
function removeOverlayAndButtons(screenWidth) {
removeOverlayAndCloseSidebar()
removeButtons()
}
|