de.swm.gwt.client.responsive.MatchMediaFacade Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swm-gwt-client Show documentation
Show all versions of swm-gwt-client Show documentation
Plain GWT Swm erweiterungen, auch zur benutzung in mobilen Geraeten
package de.swm.gwt.client.responsive;
import com.google.gwt.core.shared.GWT;
/**
* Wrapper for the javascript matchMedia function.
* Based on patch/contribution at GWT bug tracker
* Use a polyfill in case the browser doesn't support this function (see links below).
*
* Typical application example:
*
* MatchMediaFacade facade = MatchMediaFacade.getInstance();
*
* IMatchMedia minWidth = facade.match("(min-width: 720px)");
* minWidth.addMatchMediaChangeHandler(new IMatchMediaChangeHandler() {
*
* @Override
* public void onMatchMediaChange(IMatchMedia matchMedia) {
* if (matchMedia.hasMatch() {
*
* }
* }
* });
*
*
* @see Js MatchMedia
* @see Polyfill
* @see Example usages
* @see Browser support
* @see Match Media alternative JS lib.
*
* @author Ed Bras
*/
public final class MatchMediaFacade {
private MatchMediaFacade() {
}
public static MatchMediaFacade getInstance() {
return InstanceHolder.INSTANCE;
}
public native boolean isSupported() /*-{ return $wnd.matchMedia != null || $wnd.msMatchMedia != null; }-*/;
public IMatchMedia match(final String mediaQuery) {
return (mediaQuery == null) ? null : matchIntern(mediaQuery);
}
private native JsMatchMedia matchIntern(String mediaQuery) /*-{ return $wnd.matchMedia(mediaQuery); }-*/;
private interface InstanceHolder {
MatchMediaFacade INSTANCE = GWT.create(MatchMediaFacade.class);
}
}