diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-07-15 08:38:44 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-07-15 08:38:44 +0000 |
commit | 27f613240b8286f699b8c5b3b11a46644cc085c4 (patch) | |
tree | 8d73aafce6d0880ac43b74bb802a669a5530b795 /gwtquery-core | |
parent | 9956daf4ec363fd4e213a7a9e544c36aef72a907 (diff) | |
download | gwtquery-27f613240b8286f699b8c5b3b11a46644cc085c4.tar.gz gwtquery-27f613240b8286f699b8c5b3b11a46644cc085c4.zip |
Add validation dependencies to avoid warnings when running tests. Change gotoEnd parameter to boolean like jquery does. When jumtoEnd == true run callback functions. Jaadocs
Diffstat (limited to 'gwtquery-core')
11 files changed, 132 insertions, 73 deletions
diff --git a/gwtquery-core/pom.xml b/gwtquery-core/pom.xml index 2d8559ab..84f7c690 100644 --- a/gwtquery-core/pom.xml +++ b/gwtquery-core/pom.xml @@ -30,6 +30,19 @@ <version>${gwtversion}</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>1.0.0.GA</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>1.0.0.GA</version> + <classifier>sources</classifier> + <scope>provided</scope> + </dependency> </dependencies> <build> <resources> diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index d6c158ca..e58250cf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -2968,7 +2968,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
/**
- * Put a {@link Function} at the end of the Effects queue.
+ * Put a set of {@link Function} at the end of the Effects queue.
*
* Example:
*
@@ -2994,12 +2994,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * call dequeue() just before the done() call.
* {@see #dequeue()}
*/
- public GQuery queue(Function f) {
+ public GQuery queue(Function... f) {
return as(Effects).queue(f);
}
/**
- * Put a {@link Function} at the end of a queue.
+ * Put a set of {@link Function} at the end of a queue.
*
* Example:
*
@@ -3021,7 +3021,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * function unless you use the Effects ('fx') namespace.
* {@see #dequeue()}
*/
- public GQuery queue(String queueName, Function f) {
+ public GQuery queue(String queueName, Function... f) {
if (queueName == null || "fx".equalsIgnoreCase(queueName)) {
return as(Effects).queue(f);
}
@@ -3465,24 +3465,46 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
/**
- * Stop the animation currently running.
+ * When .stop() is called on an element, the currently-running animation (if any)
+ * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
+ * when .stop() is called, the element will now still be displayed, but will be
+ * a fraction of its previous height. Callback functions are not called but
+ * the next animation in the queue begins immediately.
*/
public GQuery stop() {
return stop(false);
}
/**
- * Stop the animation currently running.
+ * When .stop() is called on an element, the currently-running animation (if any)
+ * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
+ * when .stop() is called, the element will now still be displayed, but will be
+ * a fraction of its previous height. Callback functions are not called but
+ * the next animation in the queue begins immediately.
+ *
+ * If the clearQueue parameter is provided with a value of true, then the rest of the
+ * animations in the queue are removed and never run.
*/
public GQuery stop(boolean clearQueue) {
return stop(clearQueue, false);
}
/**
- * Stop the animation currently running.
+ * When .stop() is called on an element, the currently-running animation (if any)
+ * is immediately stopped. If, for instance, an element is being hidden with .slideUp()
+ * when .stop() is called, the element will now still be displayed, but will be
+ * a fraction of its previous height. Callback functions are not called but
+ * the next animation in the queue begins immediately.
+ *
+ * If the clearQueue parameter is provided with a value of true, then the rest of the
+ * animations in the queue are removed and never run.
+ *
+ * If the jumpToEnd property is provided with a value of true, the current animation stops,
+ * but the element is immediately given its target values for each CSS property.
+ * The callback functions are then immediately called, if provided.
*/
public GQuery stop(boolean clearQueue, boolean jumpToEnd) {
- return as(Effects).stop(clearQueue, (Object) jumpToEnd);
+ return as(Effects).stop(clearQueue, jumpToEnd);
}
/**
@@ -4229,7 +4251,4 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { dataCache.delete(id);
}
}
-
-
-
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index ea330292..84753e54 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -407,8 +407,8 @@ public interface LazyGQuery<T> extends LazyBase<T>{ LazyGQuery<T> bind(String eventType, Object data, Function... funcs); /** - * Bind a set of functions to the blur event of each matched element. Or - * trigger the blur event if no functions are provided. + * Bind a set of functions to the blur event of each matched element. + * Or trigger the blur event if no functions are provided. */ LazyGQuery<T> blur(Function... f); @@ -1032,7 +1032,8 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Bind a set of functions to the focus event of each matched element. Or - * trigger the event if no functions are provided. + * trigger the event and move the input focus to the first element + * if no functions are provided. */ LazyGQuery<T> focus(Function... f); @@ -1685,7 +1686,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ LazyGQuery<T> prop(String key, Function closure); /** - * Put a {@link Function} at the end of the Effects queue. + * Put a set of {@link Function} at the end of the Effects queue. * * Example: * @@ -1711,10 +1712,10 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * call dequeue() just before the done() call. * {@see #dequeue()} */ - LazyGQuery<T> queue(Function f); + LazyGQuery<T> queue(Function... f); /** - * Put a {@link Function} at the end of a queue. + * Put a set of {@link Function} at the end of a queue. * * Example: * @@ -1736,7 +1737,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * function unless you use the Effects ('fx') namespace. * {@see #dequeue()} */ - LazyGQuery<T> queue(String queueName, Function f); + LazyGQuery<T> queue(String queueName, Function... f); /** * Removes all matched elements from the DOM. @@ -1972,17 +1973,39 @@ public interface LazyGQuery<T> extends LazyBase<T>{ Effects slideUp(int millisecs, Function... f); /** - * Stop the animation currently running. + * When .stop() is called on an element, the currently-running animation (if any) + * is immediately stopped. If, for instance, an element is being hidden with .slideUp() + * when .stop() is called, the element will now still be displayed, but will be + * a fraction of its previous height. Callback functions are not called but + * the next animation in the queue begins immediately. */ LazyGQuery<T> stop(); /** - * Stop the animation currently running. + * When .stop() is called on an element, the currently-running animation (if any) + * is immediately stopped. If, for instance, an element is being hidden with .slideUp() + * when .stop() is called, the element will now still be displayed, but will be + * a fraction of its previous height. Callback functions are not called but + * the next animation in the queue begins immediately. + * + * If the clearQueue parameter is provided with a value of true, then the rest of the + * animations in the queue are removed and never run. */ LazyGQuery<T> stop(boolean clearQueue); /** - * Stop the animation currently running. + * When .stop() is called on an element, the currently-running animation (if any) + * is immediately stopped. If, for instance, an element is being hidden with .slideUp() + * when .stop() is called, the element will now still be displayed, but will be + * a fraction of its previous height. Callback functions are not called but + * the next animation in the queue begins immediately. + * + * If the clearQueue parameter is provided with a value of true, then the rest of the + * animations in the queue are removed and never run. + * + * If the jumpToEnd property is provided with a value of true, the current animation stops, + * but the element is immediately given its target values for each CSS property. + * The callback functions are then immediately called, if provided. */ LazyGQuery<T> stop(boolean clearQueue, boolean jumpToEnd); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index bd8bca3b..e021a14a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -26,7 +26,7 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNative extends SelectorEngineImpl { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:first|:last|:even|:odd).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = ".*(\\.//|:contains|!=|:first|:last|:even|:odd).*"; private static HasSelector impl; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java index af9d05d6..e4f1be98 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java @@ -55,7 +55,7 @@ public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } } - public static final String STOP_DATA_KEY = "com.google.gwt.query.client.plugins.QueuePlugin.StopData"; + public static final String JUMP_TO_END = "com.google.gwt.query.client.plugins.QueuePlugin.StopData"; private static final String QUEUE_DATA_PREFIX = "GQueryQueue_"; @@ -96,13 +96,15 @@ public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } /** - * Adds a new function, to be executed, onto the end of the queue of all + * Adds new functions, to be executed, onto the end of the queue of all * matched elements. */ @SuppressWarnings("unchecked") - public T queue(Function func) { + public T queue(Function... funcs) { for (Element e : elements()) { - queue(e, func); + for (Function f: funcs) { + queue(e, f); + } } return (T) this; } @@ -132,7 +134,7 @@ public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { * - or remove all functions in the queue. */ public T stop(boolean clearQueue) { - return stop(clearQueue, null); + return stop(clearQueue, false); } /** @@ -141,9 +143,9 @@ public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { * - or remove all functions in the queue. */ @SuppressWarnings("unchecked") - public T stop(boolean clearQueue, Object stopData) { + public T stop(boolean clearQueue, boolean jumpToEnd) { for (Element e : elements()) { - stop(e, clearQueue, stopData); + stop(e, clearQueue, jumpToEnd); } return (T) this; } @@ -199,22 +201,16 @@ public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } } - private void stop(Element elem, boolean clear, Object data) { + private void stop(Element elem, boolean clear, boolean jumpToEnd) { Queue<?> q = queue(elem, null); if (q != null) { Object f = q.peek(); if (f != null) { if (f instanceof Function) { - boolean putData = data != null; - if (putData){ - $(elem).data(STOP_DATA_KEY, data); - } - + // pass jumpToEnd to Annimation.onCancel() via the element's data object + $(elem).data(JUMP_TO_END, new Boolean(jumpToEnd)); ((Function) f).cancel(elem); - - if (putData){ - $(elem).removeData(STOP_DATA_KEY); - } + $(elem).removeData(JUMP_TO_END); } } if (clear) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/SimpleNamedQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/SimpleNamedQueue.java index 5387f83b..823ce857 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/SimpleNamedQueue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/SimpleNamedQueue.java @@ -28,15 +28,18 @@ public class SimpleNamedQueue extends QueuePlugin<SimpleNamedQueue>{ } @Override - public SimpleNamedQueue queue(final String queueName, final Function func) { + public SimpleNamedQueue queue(final String queueName, Function... funcs) { this.queueName = queueName; - return queue(new Function(){ - @Override - public void f(Element e) { - func.f(e.<com.google.gwt.dom.client.Element>cast()); - dequeueIfNotDoneYet(e, this); - } - }); + for (final Function f: funcs) { + queue(new Function(){ + @Override + public void f(Element e) { + f.f(e.<com.google.gwt.dom.client.Element>cast()); + dequeueIfNotDoneYet(e, this); + } + }); + } + return this; } @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java index f1c6b4ef..9ca86fb6 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java @@ -74,17 +74,16 @@ public class ClipAnimation extends Animation { @Override
public void onCancel() {
- Boolean jumpToEnd = Effects.$(e).data(Effects.STOP_DATA_KEY, Boolean.class);
-
+ Boolean jumpToEnd = Effects.$(e).data(Effects.JUMP_TO_END, Boolean.class);
if (jumpToEnd != null && jumpToEnd) {
onCompleteImpl();
}
+ //Do not dequeue here, stop() will do
}
@Override
public void onComplete() {
onCompleteImpl();
- g.each(funcs);
g.dequeue();
}
@@ -138,7 +137,6 @@ public class ClipAnimation extends Animation { }
private void onCompleteImpl(){
-
super.onComplete();
if (action == Action.HIDE) {
g.hide();
@@ -147,5 +145,6 @@ public class ClipAnimation extends Animation { back.remove();
back = Effects.$();
g.css("clip", "");
+ g.each(funcs);
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java index a0f8dcfe..48514d18 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java @@ -210,16 +210,16 @@ public class PropertiesAnimation extends Animation { @Override
public void onCancel() {
- Boolean jumpToEnd = Effects.$(e).data(Effects.STOP_DATA_KEY, Boolean.class);
+ Boolean jumpToEnd = Effects.$(e).data(Effects.JUMP_TO_END, Boolean.class);
if (jumpToEnd != null && jumpToEnd){
onCompleteImpl();
}
+ //Do not dequeue here, stop() will do
}
@Override
public void onComplete() {
onCompleteImpl();
- g.each(funcs);
g.dequeue();
}
@@ -278,6 +278,7 @@ public class PropertiesAnimation extends Animation { }
}
g.restoreCssAttrs(ATTRS_TO_SAVE);
+ g.each(funcs);
}
}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 653dd93e..4aefc20c 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -1295,7 +1295,7 @@ public class GQueryCoreTest extends GWTTestCase { $("#parent", e).data("key", "parent"); $("#parent", e).click(noFailCallback); - GQuery $parent = $("div", e).detach("#child"); + $("div", e).detach("#child"); //child was removed but not the parent assertEquals(0,$("#child", e).length()); @@ -1305,7 +1305,7 @@ public class GQueryCoreTest extends GWTTestCase { assertEquals("child", $(child).data("key")); assertEquals("parent",$(parent).data("key")); - $(e).append($parent.filter("#child")); + $(e).append($(child)); assertEquals(1,$("#child", e).length()); assertEquals(1,$("#parent", e).length()); @@ -1634,9 +1634,9 @@ public class GQueryCoreTest extends GWTTestCase { public void testXpathSelector() { $(e).html("<table border=1 id=idtest width=440><tr><td width=50%>A Text</td><td width=50%>B</td></tr></table>"); SelectorEngineCssToXPath s = new SelectorEngineCssToXPath(); - for (String selector : Arrays.asList("td[width]", "table > td", "*[width!=440]")) { + for (String selector : Arrays.asList("td[width]", "table > tr > td", "*[width!='440']")) { String xselector = s.css2Xpath(selector); - assertEquals($(selector).toString(), $(xselector).toString()); + assertEquals($(selector).size(), $(xselector).size()); } } @@ -1644,7 +1644,6 @@ public class GQueryCoreTest extends GWTTestCase { GQuery test = $(" <div>blop</div><!-- comment --> <p>test2</p> "); test.addClass("test"); test.removeClass("test"); - } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTest.java index f101c94f..63be9225 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTest.java @@ -48,7 +48,13 @@ public class SelectorEnginesTest extends GWTTestCase { assertEquals(".//div[not(contains(concat(' ',normalize-space(@class),' '),' example '))]", sel.css2Xpath("div:not(.example)")); + + assertEquals(".//*", + sel.css2Xpath("*")); + assertEquals(".//input[@checked='checked']", + sel.css2Xpath("input:checked")); + assertEquals(".//*[@myAttr]", sel.css2Xpath("[myAttr]")); @@ -56,12 +62,17 @@ public class SelectorEnginesTest extends GWTTestCase { sel.css2Xpath("tag[myAttr=abcd]")); assertEquals(".//a[@href and (@lang) and (@class)]", - sel.css2Xpath("a[href][lang][class]")); + sel.css2Xpath("a[href][lang][class]")); + + assertEquals(".//*[@checked='checked']|.//*[not(@disabled)]|.//*[@disabled]", + sel.css2Xpath(":checked, :enabled, :disabled")); - assertEquals(".//*[@checked='checked']|*[not(@disabled)]|*[@disabled]", - sel.css2Xpath(":checked, :enabled, :disabled")); + assertEquals(".//table[contains(string(.),'String With | @ ~= Space Points.s and Hash#es')]", + sel.css2Xpath("table:contains('String With | @ ~= Space Points.s and Hash#es')")); + + assertEquals(".//div[@class='comment' and (contains(string(.),'John'))]", + sel.css2Xpath("div[@class='comment']:contains('John')")); } - } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/rebind/SelectorGeneratorsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/rebind/SelectorGeneratorsTest.java index a66f328b..05b3c5fb 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/rebind/SelectorGeneratorsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/rebind/SelectorGeneratorsTest.java @@ -17,9 +17,7 @@ package com.google.gwt.query.rebind; import java.util.ArrayList; -import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.impl.SelectorEngineCssToXPath; @@ -94,10 +92,9 @@ public class SelectorGeneratorsTest extends GWTTestCase { assertEquals(".//table[contains(string(.),'String With | @ ~= Space Points.s and Hash#es')]", sel.css2Xpath("table:contains('String With | @ ~= Space Points.s and Hash#es')")); - - String xsel = sel.css2Xpath("div[@class='comment']:contains('John')"); - sel.validateXpath(xsel); - assertEquals(".//div[@class='comment' and (contains(string(.),'John'))]", xsel); + + assertEquals(".//div[@class='comment' and (contains(string(.),'John'))]", + sel.css2Xpath("div[@class='comment']:contains('John')")); } public void testReplaceAll() { @@ -111,10 +108,8 @@ public class SelectorGeneratorsTest extends GWTTestCase { public void testValidation() throws XPathExpressionException { SelectorGeneratorCssToXPath sel = new SelectorGeneratorCssToXPath(); - XPathFactory factory = XPathFactory.newInstance(); - XPath xpath = factory.newXPath(); - System.out.println(sel.css2Xpath("path[to=1428],#from-1428")); - xpath.compile(sel.css2Xpath("path[to=1428],#from-1428")); - xpath.compile(sel.css2Xpath("a[href^=http][href*=youtube.com/]")); + sel.validateXpath(sel.css2Xpath("path[to=1428],#from-1428")); + sel.validateXpath(sel.css2Xpath("a[href^=http][href*=youtube.com/]")); + sel.validateXpath(sel.css2Xpath("div[@class='comment']:contains('John')")); } } |