Skip to content

Commit ebd4ae3

Browse files
committed
Fix #1471: Make the handle stay in bounds when resizing
1 parent d36b7d6 commit ebd4ae3

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ const djdt = {
190190
requestAnimationFrame(function () {
191191
djdt.handleDragged = false;
192192
});
193+
djdt.ensure_handle_visibility();
193194
}
194195
});
195196
const show =
@@ -210,23 +211,24 @@ const djdt = {
210211
e.classList.remove("djdt-active");
211212
});
212213
},
214+
ensure_handle_visibility() {
215+
const handle = document.getElementById("djDebugToolbarHandle");
216+
// set handle position
217+
const handleTop = Math.min(
218+
localStorage.getItem("djdt.top") || 0,
219+
window.innerHeight - handle.offsetWidth
220+
);
221+
handle.style.top = handleTop + "px";
222+
},
213223
hide_toolbar() {
214224
djdt.hide_panels();
215225

216226
$$.hide(document.getElementById("djDebugToolbar"));
217227

218228
const handle = document.getElementById("djDebugToolbarHandle");
219229
$$.show(handle);
220-
// set handle position
221-
let handleTop = localStorage.getItem("djdt.top");
222-
if (handleTop) {
223-
handleTop = Math.min(
224-
handleTop,
225-
window.innerHeight - handle.offsetWidth
226-
);
227-
handle.style.top = handleTop + "px";
228-
}
229-
230+
djdt.ensure_handle_visibility();
231+
window.addEventListener("resize", djdt.ensure_handle_visibility);
230232
document.removeEventListener("keydown", onKeyDown);
231233

232234
localStorage.setItem("djdt.show", "false");
@@ -249,6 +251,7 @@ const djdt = {
249251
$$.hide(document.getElementById("djDebugToolbarHandle"));
250252
$$.show(document.getElementById("djDebugToolbar"));
251253
localStorage.setItem("djdt.show", "true");
254+
window.removeEventListener("resize", djdt.ensure_handle_visibility);
252255
},
253256
cookie: {
254257
get(key) {

docs/changes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Change log
44
Next version
55
------------
66

7+
* Ensured that the handle stays within bounds when resizing the window.
8+
79

810
3.2.1 (2021-04-14)
911
------------------

0 commit comments

Comments
 (0)