--- /dev/null
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client;
+
+import com.google.gwt.query.rebind.BrowserGenerator;
+
+/**
+ * This class is the equivalent to the jQuery.browser object in gQuery.
+ *
+ * The implementation is performend by the {@link BrowserGenerator}
+ *
+ * It can be used as a way of deferred-binding without modifying .gwt.xml files,
+ * taking advantage of compiler optimizations which will or will not include the
+ * code in a 'if' statement checking these conditions.
+ *
+ * Example:
+ * <pre>
+ if (GQuery.browser.ie6) {
+ // this code will be removed on non-ie6 permutations
+ Window.alert("IE6");
+ } else if (!browser.webkit) {
+ // this code will be only in the webkit permutation
+ Window.alert("NOT WEBKIT");
+ }
+ * </pre>
+ *
+ */
+public abstract class Browser {
+
+ /**
+ * Not in jquery, but useful in GWT for deferred bindings.
+ * @return true if ie6
+ */
+ public final boolean ie6 = isIe6();
+ /**
+ * Not in jquery, but useful in GWT for deferred bindings.
+ * @return true if ie8
+ */
+ public final boolean ie8 = isIe8();
+ /**
+ * Not in jquery, but useful in GWT for deferred bindings.
+ * @return true if ie9
+ */
+ public final boolean ie9 = isIe9();
+ /**
+ * @return true if Firefox
+ */
+ public final boolean mozilla = isMozilla();
+ /**
+ * @return true if any IE
+ */
+ public final boolean msie = isMsie();
+ /**
+ * @return true if opera
+ */
+ public final boolean opera = isOpera();
+ /**
+ * Maintained for jQuery compatibility
+ * @return true if webkit
+ * @deprecated use webkit() instead
+ */
+ @Deprecated
+ public final boolean safari = isWebkit();
+ /**
+ * @return true if webkit
+ */
+ public final boolean webkit = isWebkit();
+
+ protected abstract boolean isIe6();
+ protected abstract boolean isIe8();
+ protected abstract boolean isIe9();
+ protected abstract boolean isMozilla();
+ protected abstract boolean isMsie();
+ protected abstract boolean isOpera();
+ protected abstract boolean isWebkit();
+}
*/
package com.google.gwt.query.client;
-import static com.google.gwt.query.client.plugins.QueuePlugin.Queue;
+import static com.google.gwt.query.client.plugins.QueuePlugin.*;
import java.util.ArrayList;
import java.util.Arrays;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.core.client.JsArrayString;
-import com.google.gwt.dom.client.BodyElement;
-import com.google.gwt.dom.client.ButtonElement;
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.InputElement;
-import com.google.gwt.dom.client.Node;
-import com.google.gwt.dom.client.NodeList;
-import com.google.gwt.dom.client.OptionElement;
-import com.google.gwt.dom.client.SelectElement;
+import com.google.gwt.dom.client.*;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.HasCssName;
-import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.HasCssValue;
import com.google.gwt.query.client.css.TakesCssValue;
* The body element in the current page.
*/
public static final BodyElement body = GWT.isClient() ? Document.get().getBody() : null;
+
+ /**
+ * A Browser object with a set of browser-specific flags.
+ */
+ public static final Browser browser = GWT.isClient() ? GWT.<Browser>create(Browser.class) : null;
/**
* Object to store element data (public so as we can access to it from tests).
* The document element in the current page.
*/
public static final Document document = GWT.isClient() ? Document.get() : null;
-
+
/**
* Static reference Effects plugin
*/
import java.util.Comparator;
import java.util.List;
+import javax.validation.constraints.AssertFalse;
+
import static com.google.gwt.query.client.GQuery.$;
import static com.google.gwt.query.client.GQuery.$$;
import static com.google.gwt.query.client.GQuery.document;
e.setInnerHTML("");
}
}
+
+ @DoNotRunWith({Platform.Prod})
+ public void testBrowser() {
+ assertTrue(GQuery.browser.webkit);
+ assertFalse(GQuery.browser.webkit);
+ assertFalse(GQuery.browser.opera);
+ assertFalse(GQuery.browser.msie);
+ assertFalse(GQuery.browser.ie6);
+ assertFalse(GQuery.browser.ie8);
+ assertFalse(GQuery.browser.ie9);
+ }
public void testAttributeMethods() {