aboutsummaryrefslogtreecommitdiffstats
path: root/gwtquery-core
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2011-02-25 10:32:55 +0000
committerManolo Carrasco <manolo@apache.org>2011-02-25 10:32:55 +0000
commit84811d17bf8bc0d00064356d5a301c69220a5698 (patch)
treea74148c74e4b974d9eee153a9d18a130500bf469 /gwtquery-core
parent45de0912002973a5ba43baf88abd5cb042017bb2 (diff)
downloadgwtquery-84811d17bf8bc0d00064356d5a301c69220a5698.tar.gz
gwtquery-84811d17bf8bc0d00064356d5a301c69220a5698.zip
add scrollTo and scrollIntoView methods
Diffstat (limited to 'gwtquery-core')
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java48
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java31
2 files changed, 75 insertions, 4 deletions
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 e34cf1cc..fdf7f716 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
@@ -526,6 +526,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
private static native String[] jsArrayToString0(JsArrayString array) /*-{
return array;
}-*/;
+
+ private static native void scrollIntoViewImpl(Node n) /*-{
+ if (n) n.scrollIntoView()
+ }-*/;
private static native <T extends Node> T[] reinterpretCast(NodeList<T> nl) /*-{
return nl;
@@ -2173,6 +2177,31 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
public GQuery scroll(Function...f) {
return bindOrFire(Event.ONSCROLL, null, f);
}
+
+ /**
+ * Scrolls the first matched element into view.
+ */
+ public GQuery scrollIntoView() {
+ scrollIntoViewImpl(get(0));
+ return this;
+ }
+
+ /**
+ * Scrolls the first matched element into view.
+ *
+ * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft and
+ * scrollTop properties of each scroll-able element to ensure that the
+ * specified element is completely in view. It adjusts each scroll position by
+ * the minimum amount necessary.
+ */
+ public GQuery scrollIntoView(boolean ensure) {
+ if (ensure) {
+ DOM.scrollIntoView((com.google.gwt.user.client.Element)get(0));
+ } else {
+ scrollIntoView();
+ }
+ return this;
+ }
/**
* Gets the scroll left offset of the first matched element. This method works
@@ -2190,7 +2219,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * When a value is passed in, the scroll left offset is set to that value on
+ * The scroll left offset is set to the passed value on
* all matched elements. This method works for both visible and hidden
* elements.
*/
@@ -2204,6 +2233,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
return this;
}
+
+ /**
+ *
+ * Scrolls the contents of all matched elements to the specified co-ordinate
+ * becoming the top left corner of the viewable area.
+ *
+ * This method is only useful where there are areas of the document not viewable within
+ * the current viewable area of the window and the visible property
+ * of the window's scrollbar must be set to true.
+ *
+ */
+ public GQuery scrollTo(int left, int top) {
+ scrollLeft(left).scrollTop(top);
+ return this;
+ }
/**
* Gets the scroll top offset of the first matched element. This method works
@@ -2221,7 +2265,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * When a value is passed in, the scroll top offset is set to that value on
+ * The scroll top offset is set to the passed value on
* all matched elements. This method works for both visible and hidden
* elements.
*/
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 38a31b24..7a3c2e9b 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
@@ -998,26 +998,53 @@ public interface LazyGQuery<T> extends LazyBase<T>{
LazyGQuery<T> scroll(Function...f);
/**
+ * Scrolls the first matched element into view.
+ */
+ LazyGQuery<T> scrollIntoView();
+
+ /**
+ * Scrolls the first matched element into view.
+ *
+ * If ensure == true, it crawls up the DOM hierarchy, adjusting the scrollLeft and
+ * scrollTop properties of each scroll-able element to ensure that the
+ * specified element is completely in view. It adjusts each scroll position by
+ * the minimum amount necessary.
+ */
+ LazyGQuery<T> scrollIntoView(boolean ensure);
+
+ /**
* Gets the scroll left offset of the first matched element. This method works
* for both visible and hidden elements.
*/
int scrollLeft();
/**
- * When a value is passed in, the scroll left offset is set to that value on
+ * The scroll left offset is set to the passed value on
* all matched elements. This method works for both visible and hidden
* elements.
*/
LazyGQuery<T> scrollLeft(int left);
/**
+ *
+ * Scrolls the contents of all matched elements to the specified co-ordinate
+ * becoming the top left corner of the viewable area.
+ *
+ * This method is only useful where there are areas of the document not viewable within
+ * the current viewable area of the window and the visible property
+ * of the window's scrollbar must be set to true.
+ *
+ */
+ LazyGQuery<T> scrollTo(int left, int top);
+
+ /**
* Gets the scroll top offset of the first matched element. This method works
* for both visible and hidden elements.
*/
int scrollTop();
/**
- * When a value is passed in, the scroll top offset is set to that value on
+ * The scroll top offset is set to the passed value on
* all matched elements. This method works for both visible and hidden
* elements.
*/