jney/jquery.pageless — pull request #27 by noto (2014-02-24 09:19:25+00:00)
Title: adds $.pagelessCurrentPage and modifies stopListner() to avoid undefined error

Thank you for your awesome jQuery plugin!
Maybe you find it useful:

* When PageLess is used with [Turbolinks](https://github.com/rails/turbolinks), I'd like to restart PageLess with the CurrentPage it has been already fetched, even after clicking browsers' back button. In such case we have to know the page number already fetched. Because CurrentPage is incremented inside of jquery.pageless.js, I guess that the public function is necesaary to do it.

* With Turbolinks, $.pagelessReset() may be called on all page transitions, for example, on 'page:change' event. If it is not called, XHR continues on scroll events of pages with PageLess off. But if PageLess is not started on the previous page, $.pagelessReset() causes `Uncaught TypeError: Cannot call method 'unbind' of undefined`. To avoid it, this adds a check if $container is defined.

## Use Case

JavaScript (in app/assets/javascripts)

```javascript

// all page transitions ( https://github.com/rails/turbolinks#events )
$(document).on('page:change', function(e) {
$.pagelessReset();

// paths of PageLess-enabled pages
pageless_paths = { '/items': true, '/users': true };

var path = document.location.pathname;
if (pageless_paths[path]) {

var total_pages = Number($('#pageless-total-pages').text());
var current_page = Number($('#pageless-current-page').text());
var loader_image = $('#pageless-loader-image').attr('src');
var writeCurrentPage = function () {
$('#pageless-current-page').text(String($.pagelessCurrentPage()));
};

$('#results').pageless({ totalPages: total_pages,
currentPage: current_page,
url: path,
loaderMsg: "Loading more results",
loaderImage: loader_image,
complete: writeCurrentPage});
}
});
```

partial view of PageLess-enabled pages:

```erb

<%= @items.total_pages %>

1

```