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

onDragMove don't give access to the dragged element #1565

Closed
alaa-eddine opened this issue Jun 15, 2020 · 2 comments
Closed

onDragMove don't give access to the dragged element #1565

alaa-eddine opened this issue Jun 15, 2020 · 2 comments

Comments

@alaa-eddine
Copy link

alaa-eddine commented Jun 15, 2020

Hi,

Thank you for your great job on MetroUI, it's really helping a lot in getting beautiful interface done fast.

I'm using window component a lot, and I noticed that onDragMove event callback only have a "pos" argument, and the only way to access the dragged element is to use "this"inside the function.
the problem is that sometimes, we need to use fat arrow functions where this is bound to the parent context.

for now, I'm getting around it by overriding the event at runtime, but it's a dirty hack :)

is it possible to add a second argument to the actually dragged element ?
it also makes sense since other events like onMinClick, onCanClose already provide it.

Many thanks

@alaa-eddine
Copy link
Author

This is the hack I'm using btw

const settings = {
//contains my window settings
}

settings.onDragStop = (pos, el) => {
  // normally, el argument is not provided, and this is not accessible inside fat arrow function
  // see below for override to get it working
}

const window = Metro.window.create(settings).data('window');

//. . .

//overriding draggable events in order to pass the context as last argument
const draggable = window.win.data('draggable');
['onDragStart', 'onDragStop', 'onDragMove'].forEach(evt => {
	const orig = draggable.options[evt];
	draggable.options[evt] = function (...args) {
		args.push(this);
		return orig.apply(this, args)
	}
});

olton added a commit that referenced this issue Jun 15, 2020
…any object with drag events, Window: add second argument `context` for events `onDragStart`, `onDragStop`, `onDragMove`, issue #1565
@olton
Copy link
Owner

olton commented Jun 15, 2020

Added in 4.3.8. You can use second argument for events, named context

<div data-role="window" class="p-2" data-on-drag-start="dragStart">
    This is a simple window
</div>
function dragStart(pos, context) {
    console.log(pos, context);
}

@olton olton added this to the 4.3.8 milestone Jun 15, 2020
@olton olton closed this as completed Jun 21, 2020
olton added a commit that referenced this issue Oct 28, 2023
…any object with drag events, Window: add second argument `context` for events `onDragStart`, `onDragStop`, `onDragMove`, issue #1565
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

2 participants