* Return a style property on the first matched element.\r
*/\r
public String css(String name) {\r
- return styleImpl.curCSS(get(0), name, false);\r
+ return css(name, false);\r
}\r
\r
/**\r
* parameter force=true.\r
*/\r
public String css(String name, boolean force) {\r
- return styleImpl.curCSS(get(0), name, force);\r
+ return size() == 0 ? "" : styleImpl.curCSS(get(0), name, force);\r
}\r
\r
/**\r
*/\r
@SuppressWarnings("unchecked")\r
public <T> T data(String name, Class<T> clz) {\r
- return (T) data(elements.getItem(0), name, null);\r
+ return size() == 0 ? null: (T)data(elements.getItem(0), name, null);\r
}\r
\r
/**\r
* Get the innerHTML of the first matched element.\r
*/\r
public String html() {\r
- return get(0).getInnerHTML();\r
+ return size() == 0 ? "" : get(0).getInnerHTML();\r
}\r
\r
/**\r
* but not the vertical scrollbar height, border, or margin.\r
*/\r
public int innerHeight() {\r
- return get(0).getClientHeight();\r
+ return size() == 0 ? 0 : get(0).getClientHeight();\r
}\r
\r
/**\r
* not the vertical scrollbar width, border, or margin.\r
*/\r
public int innerWidth() {\r
- return get(0).getClientWidth();\r
+ return size() == 0 ? 0 : get(0).getClientWidth();\r
}\r
\r
/**\r
* left. The method works only with visible elements.\r
*/\r
public com.google.gwt.query.client.GQuery.Offset offset() {\r
- return new Offset(get(0).getAbsoluteLeft(), get(0).getAbsoluteTop());\r
+ return size() == 0 ? new Offset(0, 0) : new Offset(get(0).getAbsoluteLeft(), get(0).getAbsoluteTop());\r
}\r
\r
/**\r
* elements, including padding, border, and optionally margin.\r
*/\r
public int outerHeight(boolean includeMargin) {\r
+ if (size() == 0) {\r
+ return 0;\r
+ }\r
int outerHeight = get(0).getOffsetHeight(); // height including padding and\r
// border\r
if (includeMargin) {\r
* elements, including padding and border and optionally margin.\r
*/\r
public int outerWidth(boolean includeMargin) {\r
+ if (size() == 0) {\r
+ return 0;\r
+ }\r
int outerWidth = get(0).getOffsetWidth(); // width including padding and\r
// border\r
if (includeMargin) {\r
* the minimum amount necessary.\r
*/\r
public GQuery scrollIntoView(boolean ensure) {\r
- if (ensure) {\r
+ if (size() > 0 && ensure) {\r
DOM.scrollIntoView((com.google.gwt.user.client.Element) get(0));\r
} else {\r
scrollIntoView();\r
*/\r
public int scrollLeft() {\r
Element e = get(0);\r
+ if (e == null) {\r
+ return 0;\r
+ }\r
if (e == window || e.getNodeName() == null) {\r
return Window.getScrollLeft();\r
} else if (e == (Node) document) {\r
* for both visible and hidden elements.\r
*/\r
public int scrollTop() {\r
+ if (e == null) {\r
+ return 0;\r
+ }\r
Element e = get(0);\r
if (e == window || e.getNodeName() == null) {\r
return Window.getScrollTop();\r
* Return true if the first element is visible.\r
*/\r
public boolean visible() {\r
- return styleImpl.isVisible(get(0));\r
+ return size() == 0 ? false : styleImpl.isVisible(get(0));\r
}\r
\r
/**\r