Created
May 15, 2013 17:47
-
-
Save jescalan/5585871 to your computer and use it in GitHub Desktop.
You can perform some voodo magic within roots to transfer information from your dynamic content into your external javascript. This is a small sample of how one might do this, the specific example being infinite scroll functionality on a blog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| title: 'hello world' | |
| --- | |
| :markdown | |
| blah blah blah |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| doctype !!! | |
| html | |
| head | |
| title testing roots | |
| body | |
| //- render out the first x posts | |
| - number_of_posts = 5 | |
| ul | |
| - for post, i in site.posts | |
| - if (i < number_of_posts){ | |
| li | |
| a(href="#{post.url}")= post.title | |
| - } | |
| //- create an internal API for javascript to paginate | |
| - var remaining = site.posts.splice(0,number_of_posts) | |
| script!= "var remaining_posts = " + JSON.stringify(remaining) | |
| script(src='/js/templates.js') | |
| script(src='/js/main.js') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ -> | |
| items_to_load = 5 | |
| loading = false | |
| $(window).on 'scroll', -> | |
| at_bottom = $(window).scrollTop() + $(window).height() > $(document).height() - 200 | |
| if at_bottom and not loading | |
| loading = true | |
| items = remaining_posts.slice(0,items_to_load).map((item) -> templates.post(item)).join('') | |
| remaining_posts.splice(0,items_to_load) | |
| $('ul').append(items) | |
| loading = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| li | |
| a(href="#{url}")= title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment