diff --git a/README.md b/README.md index 3f2b8210..ecca520d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ Exclusive jQuery components : - based on [https://github.com/woothemes/FlexSlider](https://github.com/woothemes/FlexSlider) - **InPlaceEditor** - based on [http://www.appelsiini.net/projects/jeditable](http://www.appelsiini.net/projects/jeditable) +- **PageScroller** + - Infinite Scrolling Pagination. Example on how to use it: [TML](/src/test/resources/org/got5/tapestry5/jquery/pages/PageScroll.tml) & [Java](/src/test/java/org/got5/tapestry5/jquery/pages/PageScroll.java) - **RangeSlider** - based on [http://jqueryui.com/demos/slider/#range](http://jqueryui.com/demos/slider/#range) - **Slider** diff --git a/src/main/java/org/got5/tapestry5/jquery/components/PageScroll.java b/src/main/java/org/got5/tapestry5/jquery/components/PageScroll.java index 5a1e4cc0..49b1dad5 100644 --- a/src/main/java/org/got5/tapestry5/jquery/components/PageScroll.java +++ b/src/main/java/org/got5/tapestry5/jquery/components/PageScroll.java @@ -25,7 +25,6 @@ import org.apache.tapestry5.internal.util.CaptureResultCallback; import org.apache.tapestry5.ioc.services.TypeCoercer; import org.apache.tapestry5.json.JSONObject; -import org.apache.tapestry5.services.Request; import org.apache.tapestry5.services.javascript.JavaScriptSupport; import org.got5.tapestry5.jquery.JQueryEventConstants; @@ -107,9 +106,6 @@ public class PageScroll implements ClientElement { @Inject private TypeCoercer typeCoercer; - @Inject - private Request request; - private EventContext eventContext; @BeginRender @@ -124,6 +120,7 @@ void addJavaScript() { .put("scroller", scroller) .put("scrollURI", getScrollURI()) .put("zoneId", zone) + .put("firstPageNumber", pageNumber) .put("params", params); javaScriptSupport.require("tjq/PageScroll").with(specs); diff --git a/src/main/resources/META-INF/modules/tjq/PageScroll.js b/src/main/resources/META-INF/modules/tjq/PageScroll.js index d1073fcb..12d52fd1 100644 --- a/src/main/resources/META-INF/modules/tjq/PageScroll.js +++ b/src/main/resources/META-INF/modules/tjq/PageScroll.js @@ -14,16 +14,24 @@ define([ "t5/core/dom", "t5/core/zone", "t5/core/events", "tjq/vendor/components activeZone; if (typeof (this.pageIndex) == "undefined") { - this.pageIndex = 0; + this.pageIndex = specs.firstPageNumber >= 0 ? specs.firstPageNumber : 0; } if (this.pageIndex === -1 || this.disable) { return; } + var pageZoneId = specs.zoneId + pageIndex; element = dom.wrap(specs.scroller); - element.attr("data-update-zone", specs.zoneId); + element.attr("data-update-zone", pageZoneId); activeZone = zone.findZone(element); + + var newPageZone = dom.wrap(activeZone.$.clone()); + var nextPageIndex = pageIndex + 1; + var nextPageZoneId = specs.zoneId + nextPageIndex; + newPageZone.attr("id", nextPageZoneId); + activeZone.insertAfter(newPageZone); + element.attr("data-update-zone", nextPageZoneId); this.disable = true; scroller.addClass("scrollExtend-loading"); diff --git a/src/test/java/org/got5/tapestry5/jquery/PageScrollTest.java b/src/test/java/org/got5/tapestry5/jquery/PageScrollTest.java index e86d6629..0e78f382 100644 --- a/src/test/java/org/got5/tapestry5/jquery/PageScrollTest.java +++ b/src/test/java/org/got5/tapestry5/jquery/PageScrollTest.java @@ -22,6 +22,18 @@ public void page_scroll_works(){ assertTrue(isTextPresent("Element#300")); assertTrue(isTextPresent("Element#302")); + + assertFalse(isTextPresent("Element#500")); + assertFalse(isTextPresent("Element#502")); + + this.runScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight," + + "document.body.scrollHeight,document.documentElement.clientHeight));"); + + sleep(1500); + + assertTrue(isTextPresent("Element#500")); + assertTrue(isTextPresent("Element#502")); + } } diff --git a/src/test/java/org/got5/tapestry5/jquery/pages/PageScroll.java b/src/test/java/org/got5/tapestry5/jquery/pages/PageScroll.java index f9574e77..7a861bfa 100644 --- a/src/test/java/org/got5/tapestry5/jquery/pages/PageScroll.java +++ b/src/test/java/org/got5/tapestry5/jquery/pages/PageScroll.java @@ -2,8 +2,10 @@ import java.util.ArrayList; import java.util.List; + import org.apache.tapestry5.annotations.OnEvent; import org.apache.tapestry5.annotations.Property; +import org.got5.tapestry5.jquery.JQueryEventConstants; public class PageScroll { @@ -15,7 +17,7 @@ public class PageScroll { private static final int PAGE_SIZE = 100; - @OnEvent("nextPage") + @OnEvent(JQueryEventConstants.NEXT_PAGE) List moreValues(int multiplyBy) throws InterruptedException { List values = new ArrayList(); for (int i = pageNumber * PAGE_SIZE; diff --git a/src/test/java/org/got5/tapestry5/jquery/services/AppModule.java b/src/test/java/org/got5/tapestry5/jquery/services/AppModule.java index 9c743847..aa1aacfd 100644 --- a/src/test/java/org/got5/tapestry5/jquery/services/AppModule.java +++ b/src/test/java/org/got5/tapestry5/jquery/services/AppModule.java @@ -56,7 +56,7 @@ public static void contributeApplicationDefaults(MappedConfiguration
  • Element#${value}
  • -
  • +