Skip to content

toolbar.js: Ensure toolbar handle cannot be dragged outside window #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

teddywing
Copy link
Contributor

Previously the toolbar handle could be dragged beyond the top and bottom
of the window where it could get lost.

If the handle position outside the window border was saved, the only way
to get the handle back that I found would be to open the inspector and
manually change the handle's offset to make it visible once again.

This change restricts the handle so that it cannot be dragged above the
top or below the bottom of the window area.

Closes #634.

django-debug-toolbar--handle-can-be-dragged-outside-window--fixed

@tim-schilling
Copy link
Member

I tested this out and it works for the functionality you described, but breaks when I scroll down a page or two and then try to move the toolbar.

@teddywing
Copy link
Contributor Author

Sorry about that. Thanks for taking a look. Admittedly I only tested this on the sparse index page. I'll work out the scrolling issue you described.

Previously the toolbar handle could be dragged beyond the top and bottom
of the window where it could get lost.

If the handle position outside the window border was saved, the only way
to get the handle back that I found would be to open the inspector and
manually change the handle's offset to make it visible once again.

This change restricts the handle so that it cannot be dragged above the
top or below the bottom of the window area.

Using `event.clientY` in order to get the cursor position relative to
the viewport instead of the document (as is the case with
`event.pageY`). This allows the handle to be dragged when the page is
scrolled.

Closes django-commons#634.
@teddywing teddywing force-pushed the restrict-toolbar-handle-to-window branch from 7f660d9 to b2957c1 Compare September 14, 2014 17:10
@teddywing
Copy link
Contributor Author

Made the following update to handle scrolling:

diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index c42e885..7bd1045 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -140,7 +140,7 @@
                     // cursor really moved.  Otherwise, it will be impossible to expand the toolbar
                     // due to djdt.handleDragged being set to true.
                     if (djdt.handleDragged || event.pageY != startPageY) {
-                        var top = baseY + event.pageY;
+                        var top = baseY + event.clientY;

                         if (top < 0) {
                             top = 0;
@@ -148,7 +148,7 @@
                             top = windowHeight - handle.height();
                         }

-                        handle.offset({top: top});
+                        handle.css({top: top});
                         djdt.handleDragged = true;
                     }
                 });

django-debug-toolbar--handle-can-be-dragged-outside-window--fix-scroll

@tim-schilling
Copy link
Member

Thanks! I'll try to take a look at it and get it merged in this week.

@teddywing
Copy link
Contributor Author

Thanks

tim-schilling added a commit that referenced this pull request Sep 17, 2014
Ensure toolbar handle cannot be dragged outside window. Closes #634
@tim-schilling tim-schilling merged commit 7a82ac3 into django-commons:master Sep 17, 2014
@tim-schilling
Copy link
Member

Thanks for the PR!

@teddywing
Copy link
Contributor Author

Thank you!

ryneeverett pushed a commit to ryneeverett/django-debug-toolbar that referenced this pull request Oct 2, 2016
…-handle-to-window

Ensure toolbar handle cannot be dragged outside window. Closes django-commons#634
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle can be dragged outside of window bounds
2 participants