public class GQUtils {
/**
- * Returns the numeric value of a css property.
- *
- * The parameter force has a special meaning:
- * - When force is false, returns the value of the css property defined
- * in the set of style attributes.
- * - Otherwise it returns the real computed value.
+ * Use the method in the gquery class $(elem).cur(prop, force);
*/
+ @Deprecated
public static double cur(Element elem, String prop, boolean force) {
- if (elem.getPropertyString(prop) != null
- && (elem.getStyle() == null || elem.getStyle().getProperty(prop) == null)) {
- return elem.getPropertyDouble(prop);
- }
- GQuery g = GQuery.$(elem);
- String val = g.css(prop, force);
- if ("thick".equalsIgnoreCase(val)) {
- return (5);
- } else if ("medium".equalsIgnoreCase(val)) {
- return (3);
- } else if ("thin".equalsIgnoreCase(val)) {
- return (1);
- }
- if (!val.matches("^[\\d\\.]+.*$")) {
- val = g.css(prop, false);
- }
- val = val.trim().replaceAll("[^\\d\\.\\-]+.*$", "");
- return val.length() == 0 ? 0 : Double.parseDouble(val);
+ return GQuery.$(elem).cur(prop, force);
}
/**
/**\r
* We will use the fact as GWT use the widget itself as EventListener !\r
* If no Widget associated with the element, this method returns null.\r
- * @param e\r
- * @return\r
*/\r
protected static Widget getAssociatedWidget(Element e){\r
EventListener listener = DOM.getEventListener((com.google.gwt.user.client.Element) e);\r
}\r
return this;\r
}\r
+ \r
+ /**\r
+ * Returns the numeric value of a css property.\r
+ */\r
+ public double cur(String prop) {\r
+ return cur(prop, false);\r
+ }\r
+ \r
+ /**\r
+ * Returns the numeric value of a css property.\r
+ * \r
+ * The parameter force has a special meaning:\r
+ * - When force is false, returns the value of the css property defined\r
+ * in the set of style attributes. \r
+ * - When true returns the real computed value. \r
+ */\r
+ public double cur(String prop, boolean force) {\r
+ return styleImpl.cur(get(0), prop, force);\r
+ }\r
\r
/**\r
* Returns value at named data store for the element, as set by data(name,\r
* Returns the computed left position of the first element matched.\r
*/\r
public int left() {\r
- return (int) GQUtils.cur(get(0), "left", true);\r
+ return (int)cur("left", true);\r
}\r
\r
/**\r
public int outerHeight(boolean includeMargin){\r
int outerHeight = get(0).getOffsetHeight(); //height including padding and border\r
if (includeMargin){\r
- outerHeight+=GQUtils.cur( get(0), "marginTop", true)+GQUtils.cur( get(0), "marginBottom", true);\r
+ outerHeight += cur("marginTop", true) + cur("marginBottom", true);\r
}\r
return outerHeight;\r
}\r
public int outerWidth(boolean includeMargin){\r
int outerWidth = get(0).getOffsetWidth(); //width including padding and border\r
if (includeMargin){\r
- outerWidth+=GQUtils.cur( get(0), "marginRight", true)+GQUtils.cur( get(0), "marginLeft", true);\r
+ outerWidth += cur("marginRight", true) + cur("marginLeft", true);\r
}\r
return outerWidth;\r
}\r
// Get correct offsets\r
Offset offset = offset();\r
Offset parentOffset = null;\r
- if ("body".equalsIgnoreCase(offsetParent.getNodeName())\r
- || "html".equalsIgnoreCase(offsetParent.getNodeName())) {\r
+ if (offsetParent == body || offsetParent == (Node)document) {\r
parentOffset = new Offset(0, 0);\r
} else {\r
parentOffset = $(offsetParent).offset();\r
}\r
\r
// Subtract element margins\r
- int topMargin = (int) GQUtils.cur(element, "marginTop", true);\r
+ int topMargin = (int)styleImpl.cur(element, "marginTop", true);\r
+ // TODO: move this check to styleImpl\r
// When margin-left = auto, Safari and chrome return a value while IE and\r
// Firefox return 0\r
// force the margin-left to 0 if margin-left = auto.\r
int leftMargin = 0;\r
if (!"auto".equals(element.getStyle().getMarginLeft())) {\r
- leftMargin = (int) GQUtils.cur(element, "marginLeft", true);\r
+ leftMargin = (int)styleImpl.cur(element, "marginLeft", true);\r
}\r
\r
offset = offset.add(-leftMargin, -topMargin);\r
\r
// Add offsetParent borders\r
- int parentOffsetBorderTop = (int) GQUtils.cur(offsetParent,\r
+ int parentOffsetBorderTop = (int)styleImpl.cur(offsetParent,\r
"borderTopWidth", true);\r
- int parentOffsetBorderLeft = (int) GQUtils.cur(offsetParent,\r
+ int parentOffsetBorderLeft = (int)styleImpl.cur(offsetParent,\r
"borderLeftWidth", true);\r
parentOffset = parentOffset.add(parentOffsetBorderLeft,\r
parentOffsetBorderTop);\r
* Returns the computed left position of the first element matched.\r
*/\r
public int top() {\r
- return (int) GQUtils.cur(get(0), "top", true);\r
+ return (int)cur("top", true);\r
}\r
\r
/**\r
*/
LazyGQuery<T> css(TakesPercentage cssProperty, Percentage value);
+ /**
+ * Returns the numeric value of a css property.
+ */
+ double cur(String prop);
+
+ /**
+ * Returns the numeric value of a css property.
+ *
+ * The parameter force has a special meaning:
+ * - When force is false, returns the value of the css property defined
+ * in the set of style attributes.
+ * - When true returns the real computed value.
+ */
+ double cur(String prop, boolean force);
+
/**
* Returns value at named data store for the element, as set by data(name,
* value).
public static native String hyphenize(String name) /*-{
return name.replace(/([A-Z])/g, "-$1" ).toLowerCase();
}-*/;
-
+
+ /**
+ * Returns the numeric value of a css property.
+ *
+ * The parameter force has a special meaning:
+ * - When force is false, returns the value of the css property defined
+ * in the set of style attributes.
+ * - Otherwise it returns the real computed value.
+ */
+ public double cur(Element elem, String prop, boolean force) {
+ if (elem.getPropertyString(prop) != null
+ && (elem.getStyle() == null || elem.getStyle().getProperty(prop) == null)) {
+ return elem.getPropertyDouble(prop);
+ }
+ String val = curCSS(elem, prop, force);
+ if ("thick".equalsIgnoreCase(val)) {
+ return (5);
+ } else if ("medium".equalsIgnoreCase(val)) {
+ return (3);
+ } else if ("thin".equalsIgnoreCase(val)) {
+ return (1);
+ }
+ if (!val.matches("^[\\d\\.]+.*$")) {
+ val = curCSS(elem, prop, false);
+ }
+ val = val.trim().replaceAll("[^\\d\\.\\-]+.*$", "");
+ return val.length() == 0 ? 0 : Double.parseDouble(val);
+ }
+
/**
* Return the string value of a css property of an element.
*
- * The parameter force has a special meaning here: - When force is false,
- * returns the value of the css property defined in the style attribute of the
- * element. - Otherwise it returns the real computed value.
+ * The parameter force has a special meaning:
+ * - When force is false, returns the value of the css property defined
+ * in the set of style attributes.
+ * - Otherwise it returns the real computed value.
*
- * For instance if you define 'display=none' not in the element style but in
- * the css stylesheet, it returns an empty string unless you pass the
+ * For instance if you do not define 'display=none' in the element style but in
+ * the css stylesheet, it will return an empty string unless you pass the
* parameter force=true.
*/
public String curCSS(Element elem, String name, boolean force) {
}
}
-
/**
* Fix style property names.
*/
*/\r
package com.google.gwt.query.client.plugins;\r
\r
+import java.util.ArrayList;\r
+\r
import com.google.gwt.animation.client.Animation;\r
import com.google.gwt.dom.client.Element;\r
import com.google.gwt.query.client.Function;\r
-import com.google.gwt.query.client.GQUtils;\r
import com.google.gwt.query.client.GQuery;\r
import com.google.gwt.query.client.JSArray;\r
import com.google.gwt.query.client.Properties;\r
import com.google.gwt.query.client.Regexp;\r
\r
-import java.util.ArrayList;\r
-\r
/**\r
* Animation effects on any numeric CSS property. \r
*/\r
if (hidden){\r
g.show();\r
}\r
- double start = GQUtils.cur(e, key, true), end = start;\r
+ double start = g.cur(key, true), end = start;\r
\r
if ("show".equals(val)) {\r
g.saveCssAttrs(key);\r
if (!"px".equals(unit)) {\r
double to = end == 0 ? 1 : end;\r
g.css(key, to + unit);\r
- start = to * start / GQUtils.cur(e, key, true);\r
+ start = to * start / g.cur(key, true);\r
g.css(key, start + unit);\r
}\r
if (parts.getStr(1) != null) {\r
assertEquals(122, g.height());
assertEquals(120, g.clientWidth());
assertEquals(120, g.clientHeight());
- assertEquals(100, (int)GQUtils.cur(g.get(0), "width", false));
- assertEquals(100, (int)GQUtils.cur(g.get(0), "height", false));
- assertEquals(100, (int)GQUtils.cur(g.get(0), "width", true));
- assertEquals(100, (int)GQUtils.cur(g.get(0), "height", true));
+ assertEquals(100d, g.cur("width", false));
+ assertEquals(100d, g.cur("height", false));
+ assertEquals(100d, g.cur("width", true));
+ assertEquals(100d, g.cur("height", true));
assertEquals("100px", g.css("width"));
assertEquals("100px", g.css("height"));
assertEquals("100px", g.get(0).getStyle().getProperty("width"));
$("p", e, Events.Events).trigger(Event.ONCLICK);
assertEquals("red", $("p", e).css("color"));
assertEquals("green", $("p", e).css("background-color"));
- assertEquals(24.0d, GQUtils.cur($("p", e).get(0), "fontSize", true));
+ assertEquals(24.0d, $("p", e).cur("fontSize", true));
$("p", e).css("color","").css("background","").css("fontSize", "12px");
assertFalse("red".equalsIgnoreCase($("p", e).css("color")));
assertFalse("green".equalsIgnoreCase($("p", e).css("background-color")));
- assertEquals(12.0d, GQUtils.cur($("p", e).get(0), "fontSize", true));
+ assertEquals(12.0d, $("p", e).cur("fontSize", true));
$("p", e, Events.Events).unbind("click.first.namespace");
$("p", e, Events.Events).trigger(Event.ONCLICK);
assertFalse("red".equalsIgnoreCase($("p", e).css("color")));
assertEquals("green", $("p", e).css("background-color"));
- assertEquals(24.0d, GQUtils.cur($("p", e).get(0), "fontSize", true));
+ assertEquals(24.0d, $("p", e).cur("fontSize", true));
$("p", e).css("color","").css("background","").css("fontSize", "12px");
assertFalse("red".equalsIgnoreCase($("p", e).css("color")));
assertFalse("green".equalsIgnoreCase($("p", e).css("background-color")));
- assertEquals(12.0d, GQUtils.cur($("p", e).get(0), "fontSize", true));
+ assertEquals(12.0d, $("p", e).cur("fontSize", true));
$("p", e, Events.Events).unbind("click");
$("p", e, Events.Events).trigger(Event.ONCLICK);
assertFalse("red".equalsIgnoreCase($("p", e).css("color")));
assertFalse("green".equalsIgnoreCase($("p", e).css("background-color")));
- assertEquals(12.0d, GQUtils.cur($("p", e).get(0), "fontSize", true));
+ assertEquals(12.0d, $("p", e).cur("fontSize", true));
}
public void testSubmitEvent() {
RootPanel.get().remove(b);
}
-
public void testUnbindMultipleEvents() {
String content = "<p>content</p>";
$(e).html(content);