java - GWT Node or Element listen to onAttach event -
is there way handle sort of onattach event in gwt node? suppose this:
node mydiv = dom.creatediv(); magic.setonattacheventlistener(mydiv, new eventlistener() { @override public void onevent(event event) { // ... } } the handler should invoked when this,
parent.appendchild(mydiv); given parent attached itself, i.e., displayed in current window.
i post second answer know can't change way how divs added parent.
after searching found mutation events. allow listen domnodeinserted event:
js:
mydiv.addeventlistener("domnodeinserted", function (ev) { alert('added'); }, false); in gwt need use jsni method:
private native void addlistener(element elem) /*-{ elem.addeventlistener("domnodeinserted", function (ev) { $wnd.alert('added'); }, false); }-*/; it works, but... it's deprecated. should use mutationobserver instead.
unfortunately mutationobserver don't have nodeinserted event observed. thought subtree mutation observation job didn't work me. solution observe childlist mutation on parent:
js:
// create observer instance var observer = new mutationobserver(function(mutations) { mutations.foreach(function(mutation) { alert(mutation.type); }); }); // configuration of observer: var config = { childlist: true }; // pass in target node, observer options observer.observe(elem, config); and, again, gwt need wrap in jsni method (you know how).
the mutation parameter in observer callback mutationrecord object.
so, if can parent, use mutationobserver on , observe childlist mutation. if not, try use deprecated mutation events.
i know not pure gwt solution, can use gwt methods handle event or mutation. need call gwt method form jsni this:
[instance-expr.]@class-name::method-name(param-signature)(arguments) you'll find jsni info in gwt documentation.
Comments
Post a Comment