Skip to content

Commit

Permalink
Fix #1471: Make the handle stay in bounds when resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed May 14, 2021
1 parent d36b7d6 commit ebd4ae3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 13 additions & 10 deletions debug_toolbar/static/debug_toolbar/js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const djdt = {
requestAnimationFrame(function () {
djdt.handleDragged = false;
});
djdt.ensure_handle_visibility();
}
});
const show =
Expand All @@ -210,23 +211,24 @@ const djdt = {
e.classList.remove("djdt-active");
});
},
ensure_handle_visibility() {
const handle = document.getElementById("djDebugToolbarHandle");
// set handle position
const handleTop = Math.min(
localStorage.getItem("djdt.top") || 0,
window.innerHeight - handle.offsetWidth
);
handle.style.top = handleTop + "px";
},
hide_toolbar() {
djdt.hide_panels();

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

const handle = document.getElementById("djDebugToolbarHandle");
$$.show(handle);
// set handle position
let handleTop = localStorage.getItem("djdt.top");
if (handleTop) {
handleTop = Math.min(
handleTop,
window.innerHeight - handle.offsetWidth
);
handle.style.top = handleTop + "px";
}

djdt.ensure_handle_visibility();
window.addEventListener("resize", djdt.ensure_handle_visibility);
document.removeEventListener("keydown", onKeyDown);

localStorage.setItem("djdt.show", "false");
Expand All @@ -249,6 +251,7 @@ const djdt = {
$$.hide(document.getElementById("djDebugToolbarHandle"));
$$.show(document.getElementById("djDebugToolbar"));
localStorage.setItem("djdt.show", "true");
window.removeEventListener("resize", djdt.ensure_handle_visibility);
},
cookie: {
get(key) {
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Change log
Next version
------------

* Ensured that the handle stays within bounds when resizing the window.


3.2.1 (2021-04-14)
------------------
Expand Down

0 comments on commit ebd4ae3

Please sign in to comment.