소스 검색

Fix issue #125 : "Load more" automatique

En bas de page, si l'option a été cochée (ne l'est pas par défaut), on
va charger automatiquement les articles suivants
Marien Fressinaud 12 년 전
부모
커밋
456c95d2db

+ 3 - 0
app/controllers/configureController.php

@@ -144,6 +144,7 @@ class configureController extends ActionController {
 			$nb = Request::param ('posts_per_page', 10);
 			$mode = Request::param ('view_mode', 'normal');
 			$view = Request::param ('default_view', 'all');
+			$auto_load_more = Request::param ('auto_load_more', 'no');
 			$display = Request::param ('display_posts', 'no');
 			$lazyload = Request::param ('lazyload', 'no');
 			$sort = Request::param ('sort_order', 'low_to_high');
@@ -160,6 +161,7 @@ class configureController extends ActionController {
 			$this->view->conf->_postsPerPage (intval ($nb));
 			$this->view->conf->_viewMode ($mode);
 			$this->view->conf->_defaultView ($view);
+			$this->view->conf->_autoLoadMore ($auto_load_more);
 			$this->view->conf->_displayPosts ($display);
 			$this->view->conf->_lazyload ($lazyload);
 			$this->view->conf->_sortOrder ($sort);
@@ -179,6 +181,7 @@ class configureController extends ActionController {
 				'posts_per_page' => $this->view->conf->postsPerPage (),
 				'view_mode' => $this->view->conf->viewMode (),
 				'default_view' => $this->view->conf->defaultView (),
+				'auto_load_more' => $this->view->conf->autoLoadMore (),
 				'display_posts' => $this->view->conf->displayPosts (),
 				'lazyload' => $this->view->conf->lazyload (),
 				'sort_order' => $this->view->conf->sortOrder (),

+ 1 - 0
app/i18n/en.php

@@ -155,6 +155,7 @@ return array (
 	'articles_per_page'		=> 'Number of articles per page',
 	'default_view'			=> 'Default view',
 	'sort_order'			=> 'Sort order',
+	'auto_load_more'		=> 'Load next articles at the page bottom',
 	'display_articles_unfolded'	=> 'Show articles unfolded by default',
 	'img_with_lazyload'		=> 'Use "lazy load" mode to load pictures',
 	'auto_read_when'		=> 'Mark as read when',

+ 1 - 0
app/i18n/fr.php

@@ -155,6 +155,7 @@ return array (
 	'articles_per_page'		=> 'Nombre d\'articles par page',
 	'default_view'			=> 'Vue par défaut',
 	'sort_order'			=> 'Ordre de tri',
+	'auto_load_more'		=> 'Charger les articles suivants en bas de page',
 	'display_articles_unfolded'	=> 'Afficher les articles dépliés par défaut',
 	'img_with_lazyload'		=> 'Utiliser le mode "lazy load" pour charger les images',
 	'auto_read_when'		=> 'Marquer comme lu lorsque',

+ 1 - 1
app/models/RSSConfiguration.php

@@ -100,7 +100,7 @@ class RSSConfiguration extends Model {
 		return $this->token;
 	}
 	public function autoLoadMore () {
-		return $this->autoLoadMore;
+		return $this->auto_load_more;
 	}
 
 	public function _language ($value) {

+ 10 - 0
app/views/configure/display.phtml

@@ -89,6 +89,16 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<div class="group-controls">
+				<label class="checkbox" for="auto_load_more">
+					<input type="checkbox" name="auto_load_more" id="auto_load_more" value="yes"<?php echo $this->conf->autoLoadMore () == 'yes' ? ' checked="checked"' : ''; ?> />
+					<?php echo Translate::t ('auto_load_more'); ?>
+					<?php echo $this->conf->displayPosts () == 'no' ? '<noscript> - <b>' . Translate::t ('javascript_should_be_activated') . '</b></noscript>' : ''; ?>
+				</label>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<div class="group-controls">
 				<label class="checkbox" for="display_posts">

+ 11 - 0
app/views/javascript/main.phtml

@@ -7,6 +7,7 @@ var hide_posts = false;
 <?php
 	$s = $this->conf->shortcuts ();
 	$mark = $this->conf->markWhen ();
+	$auto_load_more = $this->conf->autoLoadMore ()
 ?>
 
 function is_reader_mode() {
@@ -210,6 +211,16 @@ function init_posts () {
 		});
 	});
 	<?php } ?>
+
+	<?php if ($auto_load_more == 'yes') { ?>
+	$(window).scroll(function() {
+		var windowBot = $(window).scrollTop() + $(window).height();
+		var load_more_top = $("#load_more").position().top;
+		if(windowBot >= load_more_top) {
+			load_more_posts ();
+		}
+	});
+	<?php } ?>
 }
 
 function init_column_categories () {

+ 7 - 3
public/scripts/endless_mode.js

@@ -1,5 +1,5 @@
 var url_load_more = "";
-var load = false;
+var load_more = false;
 
 function init_load_more() {
 	url_load_more = $("a#load_more").attr("href");
@@ -12,7 +12,11 @@ function init_load_more() {
 }
 
 function load_more_posts () {
-	load = true;
+	if(load_more == true) {
+		return;
+	}
+
+	load_more = true;
 	$("#load_more").addClass("loading");
 	$.get (url_load_more, function (data) {
 		$("#stream .flux:last").after($("#stream .flux", data));
@@ -22,7 +26,7 @@ function load_more_posts () {
 		init_posts();
 		
 		$("#load_more").removeClass("loading");
-		load = false;
+		load_more = false;
 	});
 }