Obtaining the original context "this".
First of all I gotta thank you for the great plugin you've made. It's really good and flexible, and I'm using it in a variety of areas in our system.
I do have one issue which is bugging me a little bit, and I'm unsure if this is an expected behavior or it is a bug.
Basically, I have a few elements on the page with ".tags" class.
I'm just using the function like how everyone does, and apply all these classes in one call, which is great!
I'm just using the function like how everyone does:
$(".tags").sortable({
vertical: false,
delay: 200
onDrop: function ($item, container, _super, event) {
var results = $(this).someComplicatedCalculations();
console.log(results);
_super($item, container);
}
});
The problem I'm facing though, is onDrop(). I'm supposed to do some complicated calculates based on "that specific .tags element". Every ".tags" element has its own custom values stored as "data-*" inside the DOM. To achieve this, I want to get the "this" context inside onDrop().
I tried a $(this), and noticed that it wasn't returning what I was expected. Then I jumped over to line 303, and noticed that the callback to onDrop() was not called via a context proxy:
this.options.onDrop(this.item, this.getContainer(this.item), groupDefaults.onDrop, e)
I've done some jQuery plugins in the past (though I'm definitely not an expert), I do recall that when doing callbacks, I was having a custom method to do a context proxy. I had this helper method like this:
function callFunc(functionName, context/*, args*/) {
var args = Array.prototype.slice.call(arguments).splice(2,10);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(this, args);
}
Would there be planned support for my case above? Or is there an alternative way to obtain that element?
Or, if I completely misunderstood the concept, do let me know as well.
Thank you very much!
Cheers, Thomas