diff options
author | Thomas Davis <thomasalwyndavis@gmail.com> | 2012-04-28 14:35:19 +1000 |
---|---|---|
committer | Thomas Davis <thomasalwyndavis@gmail.com> | 2012-04-28 14:35:19 +1000 |
commit | fbfbab5219e14442becd8633004eed5d8eab9d0b (patch) | |
tree | c9b0e5696b9176a52918e8dc49473c39441b88a9 | |
parent | 000695a49ef36762fb53c5712aed7cab56a2e054 (diff) | |
download | backbonetutorials-fbfbab5219e14442becd8633004eed5d8eab9d0b.zip backbonetutorials-fbfbab5219e14442becd8633004eed5d8eab9d0b.tar.gz backbonetutorials-fbfbab5219e14442becd8633004eed5d8eab9d0b.tar.bz2 |
reverse highlighting
-rw-r--r-- | _posts/2011-4-28-infinite-scrolling.md | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/_posts/2011-4-28-infinite-scrolling.md b/_posts/2011-4-28-infinite-scrolling.md index 23652da..f053c6c 100644 --- a/_posts/2011-4-28-infinite-scrolling.md +++ b/_posts/2011-4-28-infinite-scrolling.md @@ -25,8 +25,7 @@ Twitter offers a jsonp API for browsing tweets. The first thing to note is that Using the 'q' and 'page' query parameters we can find the results we are after. In the collection definition below we have set some defaults which can be overridden at any point. Twitter's search API actually returns a whole bunch of meta information alongside the results. Though this is a problem for Backbone.js because a Collection expects to be populated with an array of objects. So in our collection definition we can override the Backbone.js default parse function to instead choose the correct property to populate the collection. - - ```javascript + // collections/twitter.js define([ 'jquery', @@ -48,22 +47,19 @@ Twitter's search API actually returns a whole bunch of meta information alongsid return Tweets; }); - ``` _Note: Feel free to attach the meta information returned by Twitter to the collection itself e.g._ - - ```javascript + parse: function(resp, xhr) { this.completed_in = resp.completed_in return resp.results; }, - ``` + ## Setting up the View The first thing to do is load our Twitter collection and template into the widget module. We should attach our collection to our view in our `initialize` function. `loadResults` will be responsible for calling fetch on our Twitter collection. On success we will append the latest results to our widget using our template. Our Backbone.js `events` will listen for `scroll` on the current `el` of the view which is '.twitter-widget'. If the current `scrollTop` is at the bottom then we simply increment the Twitter collections current page property and call `loadResults` again. - ```javascript // views/twitter/widget.js define([ 'jquery', @@ -112,7 +108,7 @@ The first thing to do is load our Twitter collection and template into the widge }); return TwitterWidget; }); - ``` + _Note: `triggerPoint` will allow you to set an offset where the user has to scroll to before loading the next page_ ## The widget template |