From 65e1a52b204f5f0fe2de480fb68962e68bf9c35a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 9 Oct 2013 12:18:22 +0200 Subject: [PATCH] Endless scrolling mode --- config.ini | 1 + public_html/media/js/post-list-endless.js | 32 +++++++++++++++++++++++ src/Controllers/PostController.php | 2 ++ src/Views/post-list.phtml | 20 +++++++------- 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 public_html/media/js/post-list-endless.js diff --git a/config.ini b/config.ini index 831968ed..bd754ac5 100644 --- a/config.ini +++ b/config.ini @@ -14,6 +14,7 @@ postsPerPage=20 thumbWidth=150 thumbHeight=150 thumbStyle=outside +endlessScrolling=1 [registration] emailActivation = 0 diff --git a/public_html/media/js/post-list-endless.js b/public_html/media/js/post-list-endless.js new file mode 100644 index 00000000..94265f0b --- /dev/null +++ b/public_html/media/js/post-list-endless.js @@ -0,0 +1,32 @@ +function scrolled() +{ + var margin = 150; + if ($(document).height() <= $(window).scrollTop() + $(window).height() + margin) + { + var pageNext = $(document).data('page-next'); + var pageDone = $(document).data('page-done'); + if (pageNext == null) + { + pageNext = $('.paginator .next:not(.inactive) a').attr('href'); + } + if (pageNext != null && pageNext != pageDone) + { + $(document).data('page-done', pageNext); + $.get(pageNext, [], function(response) + { + var dom = $(response); + var nextPage = dom.find('.paginator .next:not(.inactive) a').attr('href'); + $(document).data('page-next', nextPage); + $('.posts').append($(response).find('.posts').children().fadeIn('slow')); + $('body').trigger('postsLoaded'); + }); + } + } +} + +$(function() +{ + $('.paginator').hide(); + $(window).scroll(scrolled); + scrolled(); +}); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index e4d3a68c..cc51fbc6 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -21,6 +21,8 @@ class PostController public function listAction($page = 1, $query = null) { $this->context->stylesheets []= 'post-list.css'; + if ($this->config->browsing->endlessScrolling) + $this->context->scripts []= 'post-list-endless.js'; #redirect requests in form of /posts/?query=... to canonical address $formQuery = InputHelper::get('query'); diff --git a/src/Views/post-list.phtml b/src/Views/post-list.phtml index 7e5e777c..4df9dfd8 100644 --- a/src/Views/post-list.phtml +++ b/src/Views/post-list.phtml @@ -1,11 +1,13 @@ context->transport->errorMessage)): ?>

context->transport->errorMessage ?>

- context->transport->posts as $post): ?> - - @<?php echo $post['id'] ?> - - +
+ context->transport->posts as $post): ?> + + @<?php echo $post['id'] ?> + + +