Fossil SCM

Recalculate the dimensions of the hamburger menu if the browser window is resized.

florian 2018-10-11 16:36 UTC js-hamburger-menu
Commit 7c724cf7b2fd6325ce67191141ccc15e870583fc
1 file changed +16 -1
--- skins/default/js.txt
+++ skins/default/js.txt
@@ -21,11 +21,11 @@
2121
if (!document.getElementById("hbbtn")) return; // no hamburger button
2222
var panel = document.getElementById("hbdrop");
2323
if (!panel) return; // site admin might've nuked it
2424
if (!panel.style) return; // shouldn't happen, but be sure
2525
var panelBorder = panel.style.border;
26
- var panelInitialized = false; // track first panel display
26
+ var panelInitialized = false; // reset if browser window is resized
2727
2828
// Disable animation if this browser doesn't support CSS transitions.
2929
//
3030
// We need this ugly calling form for old browsers that don't allow
3131
// panel.style.hasOwnProperty('transition'); catering to old browsers
@@ -44,10 +44,15 @@
4444
4545
// Calculate panel height despite its being hidden at call time.
4646
// Based on https://stackoverflow.com/a/29047447/142454
4747
var panelHeight; // computed on first panel display
4848
function calculatePanelHeight() {
49
+
50
+ // Clear the max-height CSS property in case the panel size is recalculated
51
+ // after the browser window was resized.
52
+ panel.style.maxHeight = '';
53
+
4954
// Get initial panel styles so we can restore them below.
5055
var es = window.getComputedStyle(panel),
5156
edis = es.display,
5257
epos = es.position,
5358
evis = es.visibility;
@@ -130,10 +135,20 @@
130135
return true;
131136
childElement = childElement.nextSibling;
132137
}
133138
return false;
134139
}
140
+
141
+ // Reset the state of the panel to uninitialized if the browser window is
142
+ // resized, so the dimensions are recalculated the next time it's opened.
143
+ originalEventHandlers.onresize = window.onresize;
144
+ window.onresize = function(event) {
145
+ panelInitialized = false;
146
+ if (originalEventHandlers.onresize) {
147
+ originalEventHandlers.onresize.call(window,event);
148
+ }
149
+ };
135150
136151
// Click handler for the hamburger button.
137152
document.getElementById("hbbtn").onclick = function(event) {
138153
// Break the event handler chain, or the handler for document.onclick
139154
// (about to be installed) may already be triggered by the current event.
140155
--- skins/default/js.txt
+++ skins/default/js.txt
@@ -21,11 +21,11 @@
21 if (!document.getElementById("hbbtn")) return; // no hamburger button
22 var panel = document.getElementById("hbdrop");
23 if (!panel) return; // site admin might've nuked it
24 if (!panel.style) return; // shouldn't happen, but be sure
25 var panelBorder = panel.style.border;
26 var panelInitialized = false; // track first panel display
27
28 // Disable animation if this browser doesn't support CSS transitions.
29 //
30 // We need this ugly calling form for old browsers that don't allow
31 // panel.style.hasOwnProperty('transition'); catering to old browsers
@@ -44,10 +44,15 @@
44
45 // Calculate panel height despite its being hidden at call time.
46 // Based on https://stackoverflow.com/a/29047447/142454
47 var panelHeight; // computed on first panel display
48 function calculatePanelHeight() {
 
 
 
 
 
49 // Get initial panel styles so we can restore them below.
50 var es = window.getComputedStyle(panel),
51 edis = es.display,
52 epos = es.position,
53 evis = es.visibility;
@@ -130,10 +135,20 @@
130 return true;
131 childElement = childElement.nextSibling;
132 }
133 return false;
134 }
 
 
 
 
 
 
 
 
 
 
135
136 // Click handler for the hamburger button.
137 document.getElementById("hbbtn").onclick = function(event) {
138 // Break the event handler chain, or the handler for document.onclick
139 // (about to be installed) may already be triggered by the current event.
140
--- skins/default/js.txt
+++ skins/default/js.txt
@@ -21,11 +21,11 @@
21 if (!document.getElementById("hbbtn")) return; // no hamburger button
22 var panel = document.getElementById("hbdrop");
23 if (!panel) return; // site admin might've nuked it
24 if (!panel.style) return; // shouldn't happen, but be sure
25 var panelBorder = panel.style.border;
26 var panelInitialized = false; // reset if browser window is resized
27
28 // Disable animation if this browser doesn't support CSS transitions.
29 //
30 // We need this ugly calling form for old browsers that don't allow
31 // panel.style.hasOwnProperty('transition'); catering to old browsers
@@ -44,10 +44,15 @@
44
45 // Calculate panel height despite its being hidden at call time.
46 // Based on https://stackoverflow.com/a/29047447/142454
47 var panelHeight; // computed on first panel display
48 function calculatePanelHeight() {
49
50 // Clear the max-height CSS property in case the panel size is recalculated
51 // after the browser window was resized.
52 panel.style.maxHeight = '';
53
54 // Get initial panel styles so we can restore them below.
55 var es = window.getComputedStyle(panel),
56 edis = es.display,
57 epos = es.position,
58 evis = es.visibility;
@@ -130,10 +135,20 @@
135 return true;
136 childElement = childElement.nextSibling;
137 }
138 return false;
139 }
140
141 // Reset the state of the panel to uninitialized if the browser window is
142 // resized, so the dimensions are recalculated the next time it's opened.
143 originalEventHandlers.onresize = window.onresize;
144 window.onresize = function(event) {
145 panelInitialized = false;
146 if (originalEventHandlers.onresize) {
147 originalEventHandlers.onresize.call(window,event);
148 }
149 };
150
151 // Click handler for the hamburger button.
152 document.getElementById("hbbtn").onclick = function(event) {
153 // Break the event handler chain, or the handler for document.onclick
154 // (about to be installed) may already be triggered by the current event.
155

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button