I have a page with a list of objects, clicking one of them opens a popup-menu.
I want to align the popup-menu with the object that was clicked. So I created a custom-binding that waits for the object JQuery element and then aligns the popup according to the object's offset and scrollTop.
It all works fine, but I have a small issue. Before that list of objects I have a container that displays some extra details, and it fades out after a specific time.
So if I try to open the popup menu before the container fades out, it will remain in that position even after the container fades out, while the object list moves.
So I thought I'll just add 'update' to the custom binding, but it doesn't work.
In my custom binding:
ko.bindingHandlers.alignPopup = {
init: function (element, valueAccessor) {
var value = valueAccessor();
var element = value(); // jQuery.fn.init[1] , this is the object clicked
... some aligning computations ...
}
},
update: function(element, valueAccessor) {
... same thing ...
}
};
In my ViewModel, I've tried:
var elementObs = ko.observable(objectElement) // objectElement is the object clicked jQuery element
In html I've just added the custom binding with the above elementObs
Update is never called, so my guess is that the observable does not know that the 'offset()' and the 'scrollTop' have modified, because they are not observables as well.
How can I make the jQuery observable notice that those 2 attributes have changed?
EDIT: I said that 'update' is never called, it is called only in the beginning when the binding is applied (as it always should)