From: Manolo Carrasco Date: Fri, 13 Aug 2010 14:54:50 +0000 (+0000) Subject: adding parameter to stop meaning stop current and remove all functions X-Git-Tag: release-1.3.2~630 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=961837348f50ddd0d3c08cbe6f3d86a6931eac84;p=gwtquery.git adding parameter to stop meaning stop current and remove all functions --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java index ba7c3a9d..7b44b33c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java @@ -53,7 +53,7 @@ public abstract class GQueryQueue> extends GQuery { @SuppressWarnings("unchecked") public T dequeue() { for (Element e : elements()) { - dequeue(e); + dequeueCurrentAndRunNext(e); } return (T)this; } @@ -83,12 +83,22 @@ public abstract class GQueryQueue> extends GQuery { /** * Stop the function which is currently in execution, remove it - * from the queue an start the next one. + * from the queue and start the next one. */ - @SuppressWarnings("unchecked") public T stop() { + return stop(false); + } + + /** + * Stop the function which is currently in execution and depending + * on the value of the parameter: + * - remove it from the queue and start the next one. + * - or remove all functions in the queue. + */ + @SuppressWarnings("unchecked") + public T stop(boolean clearQueue) { for (Element e : elements()) { - stop(e); + stop(e, clearQueue); } return (T)this; } @@ -97,10 +107,12 @@ public abstract class GQueryQueue> extends GQuery { return QUEUE_DATA_PREFIX + this.getClass().getName(); } - private void dequeue(Element elem) { + private void dequeueCurrentAndRunNext(Element elem) { Queue q = queue(elem, null); if (q != null) { + // Remove current function q.poll(); + // Run the next in the queue Object f = q.peek(); if (f != null) { if (f instanceof Function) { @@ -136,7 +148,7 @@ public abstract class GQueryQueue> extends GQuery { } } - private void stop(Element elem) { + private void stop(Element elem, boolean clear) { Queue q = queue(elem, null); if (q != null) { Object f = q.peek(); @@ -145,7 +157,11 @@ public abstract class GQueryQueue> extends GQuery { ((Function) f).cancel(elem); } } - dequeue(); + if (clear) { + q.clear(); + } else { + dequeueCurrentAndRunNext(elem); + } } } }