Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Context 'this' points to window object #251

Closed
djds4rce opened this issue Aug 23, 2014 · 4 comments · Fixed by #323
Closed

Context 'this' points to window object #251

djds4rce opened this issue Aug 23, 2014 · 4 comments · Fixed by #323

Comments

@djds4rce
Copy link

Here is the demo http://codepen.io/anon/pen/AbouB?editors=001

Shouldn't it actually point to ui.item.parent()[0]?

@thgreasi
Copy link
Contributor

Since one of the points of directives is to abstract away DOM and discourage manipulations, I never though of providing this feature to the wrapped callbacks of ui-sortable.
Since, as you pointed, someone could reach the sortable element through the ui callback parameter, do you still find this feature required?
Such a PR should not be to large but would require some extra tests.

@djds4rce
Copy link
Author

I wanted 'this' parameter to figure out the connected lists i.e find out whether the update call is from the item being moved in its own list or to another list. Here is how I fixed it.

if(ui.sender !==null){
 console.log('item dropped from another list');
}
else if(ui.item.sortable.droptarget[0] === ui.item.parent()[0]){
console.log('item dropped from same list');
}

So the 'this' values is redundant.

Thanks and cheers

@thgreasi
Copy link
Contributor

You can also check ui.item.sortable.received. It will be true inside (and after) the update() callback of the connected sortable that received the item.

Glad i could help.

@thgreasi
Copy link
Contributor

#323 tries to fix this.
Feedback is welcome.

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

Successfully merging a pull request may close this issue.

2 participants