return JsUtils.isWindow(jso) ? $(jso.<Element> cast()) :
JsUtils.isElement(jso) ? $(jso.<Element> cast()) :
JsUtils.isEvent(jso) ? $(jso.<Event> cast()) :
- JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) :
+ JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) :
$(jso.<Element> cast());
}
public static <T extends GQuery> Class<T> registerPlugin(Class<T> plugin, Plugin<T> pluginFactory) {
// TODO: decide whether change plugins type to java.util.list
- // Right now we only test static methods in gquery, so this is only needed when initializing
+ // Right now we only test static methods in gquery, so this is only needed when initializing
// plugins shortcuts in gquery.
if (GWT.isClient()) {
if (plugins == null) {
}
return plugin;
}
-
+
/**
* Provides a way to execute callback Functions based on one or more objects
* that represent asynchronous events.
- *
+ *
* Arguments can be of any Object, but normally you would pass Promises.
* In the case you provide a GQuery object it will call the promise() method to return
* a Promise which will be executed when the queue is resolved.
* In the case you provide a normal Object, it will return a promise which will be immediately
* resolved with the object as argument.
* In the case you provide a Function it will executed and if the f(Object...) method returns
- * a new promise it will be used, otherwise we will use the returned object like in the last case.
- *
+ * a new promise it will be used, otherwise we will use the returned object like in the last case.
+ *
* It Returns a new promise which will be finalized when all of its subordinates finish.
* In the case of all subordinates are resolved correctly the promise will be resolved
* otherwise it will be rejected.
public static Promise when(Object... subordinates) {
return Deferred.when(subordinates);
}
-
+
/**
* A constructor function that returns a chainable utility object with methods to register
* multiple callbacks into callback queues, invoke callback queues, and relay the success
* adding something that was matched before the last traversal.
*/
public GQuery andSelf() {
- return add(previousObject);
+ return previousObject != null ? add(previousObject) : this;
}
/**
*
- * The animate() method allows you to create animation effects on any numeric HTML Attribute,
+ * The animate() method allows you to create animation effects on any numeric HTML Attribute,
* CSS property, or color CSS property.
*
* Concerning to numeric properties, values are treated as a number of pixels unless otherwise
*
* By default animate considers css properties, if you wanted to animate element attributes you
* should to prepend the symbol dollar to the attribute name. It's useful to animate svg elements.
- *
+ *
* NOTE: The ability of animating attribute values is only available in gquery but not jquery
- *
+ *
*
* Example:
*
* <pre class="code">
* //move the element from its original position to left:500px
* $("#foo").animate("left:'500'");
- *
+ *
* // Change the width html attribute of a table, note the symbol '$' to
* // tell gquery which it is an html-attribute instead of a css-property.
* $("table").animate("$width:'500'");
* <pre class="code">
* //move the element from its original position to 500px to the left for 500ms and
* // change the background color of the element at the end of the animation
- *
+ *
* $("#foo").animate("left:'+=500'", new Function(){
* public void f(Element e){
* $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED);
/**
*
- * The animate() method allows you to create animation effects on any numeric HTML Attribute,
+ * The animate() method allows you to create animation effects on any numeric HTML Attribute,
* CSS property, or color CSS property.
*
* Concerning to numeric properties, values are treated as a number of pixels unless otherwise
*
* By default animate considers css properties, if you wanted to animate element attributes you
* should to prepend the symbol dollar to the attribute name. It's useful to animate svg elements.
- *
+ *
* NOTE: The ability of animating attribute values is only available in gquery but not jquery
- *
+ *
*
* Example:
*
* <pre class="code">
* //move the element from its original position to left:500px for 500ms using a swing easing
* $("#foo").animate("left:'500'", 500, Easing.SWING);
- *
+ *
* // Change the width html attribute of a table, note the symbol '$' to
* // tell gquery which it is an html-attribute instead of a css-property.
* // the animation will last 400ms, and we use the LINEAR easing algorithm
}
/**
- * The animate() method allows you to create animation effects on any numeric HTML Attribute,
+ * The animate() method allows you to create animation effects on any numeric HTML Attribute,
* CSS property, or color CSS property.
*
* Concerning to numeric properties, values are treated as a number of pixels unless otherwise
*
* By default animate considers css properties, if you wanted to animate element attributes you
* should to prepend the symbol dollar to the attribute name. It's useful to animate svg elements.
- *
+ *
* NOTE: The ability of animating attribute values is only available in gquery but not jquery
- *
+ *
*
* Example:
*
* <pre class="code">
* //move the element from its original position to left:500px for 500ms
* $("#foo").animate("left:'500'", 500);
- *
+ *
* // Change the width html attribute of a table, note the symbol '$' to
* // tell gquery which it is an html-attribute instead of a css-property.
* // the animation will last 400ms
public GQuery fadeIn(int millisecs, Function... f) {
return as(Effects).fadeIn(millisecs, f);
}
-
+
/**
* Fade the opacity of all matched elements to a specified opacity and firing
* an optional callback after completion. Only the opacity is adjusted for
public GQuery fadeTo(int millisecs, double opacity, Function... f) {
return as(Effects).fadeTo(millisecs, opacity, f);
}
-
+
/**
* Fade the opacity of all matched elements to a specified opacity and firing
* an optional callback after completion. Only the opacity is adjusted for
if (filters.length == 0 || filters[0] == null) {
return this;
}
-
+
JsNodeArray array = JsNodeArray.create();
/*
* StringBuilder filterBuilder = new StringBuilder(); for (int i = 0; i < filters.length ; i++){
par = par.getParentNode();
}
}
- return new GQuery(unique(result));
+ return new GQuery(unique(result)).setPreviousObject(this);
}
/**
}
return pushStack(unique(result), "prevUntil", getSelector());
}
-
+
/**
- * Returns a dynamically generated Promise that is resolved once all actions
+ * Returns a dynamically generated Promise that is resolved once all actions
* in the queue have ended.
*/
public Promise promise() {
return as(Queue).promise();
}
-
+
/**
- * Returns a dynamically generated Promise that is resolved once all actions
+ * Returns a dynamically generated Promise that is resolved once all actions
* in the named queue have ended.
*/
public Promise promise(String name) {
return as(Queue).promise(name);
}
-
+
/**
* Get the value of a property for the first element in the set of matched elements.
*
* @return the value of the property, in the case the property is a 'boolean' it
* returns a Boolean object, and a Double if is a 'number', so be prepared
* if you cast to other numeric objects. In the case of the property is undefined
- * it returns null.
+ * it returns null.
*/
public <T> T prop(String key) {
assert key != null : "Key is null";
return isEmpty() ? null : JsUtils.<T>prop(get(0), key);
}
-
+
/**
* Get the value of a property for the first element in the set of matched elements.
*
* @param key the name of the property to be accessed
* @param clz the class of the type to return
- *
- * @return the value of the property, it safely check the type passed as parameter
- * and preform the aproproate transformations for numbers and booleans.
- * In the case of the property is undefined it returns null.
+ *
+ * @return the value of the property, it safely check the type passed as parameter
+ * and preform the aproproate transformations for numbers and booleans.
+ * In the case of the property is undefined it returns null.
*/
public <T> T prop(String key, Class<? extends T> clz) {
assert key != null : "Key is null";
return isEmpty() ? null : JsUtils.<T>prop(get(0), key, clz);
}
-
+
/**
* Sets a property to a value on all matched elements.
*
return this;
}
- public void setPreviousObject(GQuery previousObject) {
+ public GQuery setPreviousObject(GQuery previousObject) {
this.previousObject = previousObject;
+ return this;
}
public GQuery setSelector(String selector) {
public boolean visible() {
return isVisible();
}
-
+
/**
* Return the first non null attached widget from the matched elements or null if there isn't any.
*/
*/
package com.google.gwt.query.client;
-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;
-import static com.google.gwt.query.client.GQuery.window;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import com.google.gwt.query.client.GQuery.Offset;
-import junit.framework.Assert;
-
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.junit.DoNotRunWith;
import com.google.gwt.junit.Platform;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.query.client.GQuery.Offset;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.RGBColor;
import com.google.gwt.query.client.impl.SelectorEngineCssToXPath;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
+import junit.framework.Assert;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+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;
+import static com.google.gwt.query.client.GQuery.window;
/**
* Test class for testing gwtquery-core api.
});
assertEquals(true, $("#checkBox2",e).prop("checked"));
assertEquals(false, $("#checkBox1",e).prop("checked"));
-
+
$(window).prop("foo", 234);
assertEquals(234d, $(window).prop("foo"));
assertEquals(234l, (long)$(window).prop("foo", Long.class));
assertFalse(JsUtils.truth(null));
assertFalse(JsUtils.truth(""));
}
-
+
public void testUtilsCallFunc() {
Element e = JsUtils.runJavascriptFunction(document, "createElement", "div");
assertNotNull(e);
assertEquals(e.getTagName().toLowerCase(), "div");
-
+
e = JsUtils.runJavascriptFunction(document, "foo", "bar", 2, true);
assertNull(e);
}
assertEquals("disabled", ie.getAttribute("disabled"));
}
-
+
public void testAttr_Issue165() {
$(e).html("<a href='#' title='a title'>anchor</a>");
Element a = $("a", e).get(0);
-
+
assertEquals("a title", a.getAttribute("title"));
assertTrue(JsUtils.hasAttribute(a, "title"));
-
+
$(a).removeAttr("title");
assertEquals("", a.getAttribute("title"));
assertFalse(JsUtils.hasAttribute(a, "title"));
}
public void testDetachedElement(){
- GQuery view = $("<div id='view' style='width: 300px;'><div style='width: 50%'></div></div>");
+ GQuery view = $("<div id='view' style='width: 300px;'><div style='width: 50%'></div></div>");
+
+ int viewWidth = view.width();
+
+ assertEquals(300, viewWidth);
+
+ int innerViewWidth = view.children().width();
+
+ assertEquals(150, innerViewWidth);
+ }
+
+ public void testParentAndSelf() {
+ $(e).html("<ul><li><span>test</span></li></ul>");
+
+ Element span = $("span", e).get(0);
+ Element li = $("li", e).get(0);
+ int ulParentsNumber = $("ul", e).parents().size();
+
+ assertNotNull(span);
+ assertNotNull(li);
- int viewWidth = view.width();
+ GQuery result = $(span).parents().andSelf();
- assertEquals(300, viewWidth);
+ assertEquals(ulParentsNumber + 3, result.size());
- int innerViewWidth = view.children().width();
+ result = $(li).parents().andSelf();
- assertEquals(150, innerViewWidth);
+ assertEquals(ulParentsNumber + 2, result.size());
}
}