Created
January 27, 2011 10:53
-
-
Save silb/798350 to your computer and use it in GitHub Desktop.
For registering Java runnables as event listeners on GWT DOM elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For registering Java {@link Runnable runnables} as event listeners on GWT DOM elements. | |
* <p> | |
* This class allows for registering listeners for all DOM events including those not supported by GWT. | |
*/ | |
public class NativeDomEvents { | |
public static native void addEventListener(Element element, String event, Runnable listener) /*-{ | |
var eventListener = function() { | |
listener.@java.lang.Runnable::run()(); | |
}; | |
if (element.addEventListener) { | |
element.addEventListener(event, eventListener, false); | |
} else if (element.attachEvent) { | |
element.attachEvent('on' + event, eventListener); | |
} | |
}-*/; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment