Skip to content
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

Custom offset handler #285

Open
rohmann opened this issue Dec 29, 2015 · 9 comments
Open

Custom offset handler #285

rohmann opened this issue Dec 29, 2015 · 9 comments

Comments

@rohmann
Copy link

rohmann commented Dec 29, 2015

There are a few cases where I would like _offsetX and offsetY to be 0 rather than the calculated value. This way my element is guaranteed to be placed at the mouse coordinates.

Example 1: I have a larger element, and I'm styling gu-mirror to make it appear as just an icon as it's being dragged.

Example 2: I'm manually starting a drag event, and following up by dispatching a mousedown event to force the drag to begin (The mouse is already clicked down from a previous event). Having no offset will allow that element to jump to the mouse position.

@rohmann rohmann changed the title Feature Request: Ability to disable offsets Feature Request: Custom offset handler Dec 31, 2015
@rohmann
Copy link
Author

rohmann commented Dec 31, 2015

Renamed the issue. How about the ability to pass in a handler that can be used to calculate the offset?

@bevacqua bevacqua changed the title Feature Request: Custom offset handler Custom offset handler Jan 5, 2016
@GermainBergeron
Copy link

I would need this too. I use Dragula inside of a modal and the offset doesn't account for this modal positioning

@rohmann
Copy link
Author

rohmann commented Jun 14, 2016

@GermainBergeron I added a PR, but it's not passing :( I haven't had a chance to look into why, but I'm using the changes in a project currently

#328

@GermainBergeron
Copy link

I forked the repo and applied your changes. The test are green, I don't know what went wrong with travis. @rohmann I can do a new PR if you want, it literally a copy paste of your code

@rohmann
Copy link
Author

rohmann commented Jun 14, 2016

Go for it!

@yellow1912
Copy link

I ran into the same issue. One way to get around it, is to simply turn off the css "transform" property of the modal so that the fixed position is not affected by the transformed context. Another way is to compensating for it via custom offset like you do, though I feel it a bit hacky for some reason.

@yellow1912
Copy link

yellow1912 commented Apr 13, 2017

After applying the patch by rohmann in his pull request, below is the code i used to adjust the offset of boostrap modal. This works for single level modal, i haven't tried with nested modal.

offset: function(offset, e, item) {
                    var modal = item.closest(".modal-dialog");

                    if (modal) {
                        var box = modal.getBoundingClientRect();

                        return {
                            x: offset.x + box.left, y: offset.y + box.top
                        };
                    }

                    return offset;
                }

The issue with bootstrap is that, as I explained earlier, it uses transform

In the HTML namespace, any value other than none for the transform results in the creation of both a stacking context and a containing block. The object acts as a containing block for fixed positioned descendants.

Hope this helps someone. I wasted several hours with this.

Note: closest method is not supported in some browsers such as IE, you may write your own js to traverse the tree or use jQuery or anything. The purpose of that line of code is to get the modal the element stays in to get its offset to adjust.

@ghost
Copy link

ghost commented Apr 30, 2018

@bevacqua @rohmann any progress on this?

@diego-mathis
Copy link

This works fine: cf10a03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants