Generally ok, given it is a global listener and you probably just install
it once on app initialization. However you should use *$doc* instead of
*document* to make sure you listen on the global document. Depending on
your browser support you might want a utility method to check if visibility
change events are actually supported by the browser.
static native boolean isSupported() /*-{
return $doc.hidden !== 'undefined' && $doc.visibilityState !==
'undefined';
}-*/;
In our app we created a PageVisibilityChangedEvent which extends GwtEvent
and then fire it on the app wide EventBus so everyone can easily listen for
it. To register the DOM handler we used
Element doc = Document.get().cast();
DOM.sinkBitlessEvent(doc, VISIBILITY_CHANGE_EVENT);
DOM.setEventListener(doc, new EventListener() {
@Override
public void onBrowserEvent(final Event event) {
if (VISIBILITY_CHANGE_EVENT.equals(event.getType())) {
firePageVisibilityChangedEvent();
}
}
});
You could of course also use elemental2 (requires newest GWT) or JsInterop
to reduce the amount of JSNI if that is important for you.
-- J.
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.