Browse Source

Lazyload facultatif (issue #75 ok)

Marien Fressinaud 12 years ago
parent
commit
0ff751b443

+ 3 - 0
app/controllers/configureController.php

@@ -142,6 +142,7 @@ class configureController extends ActionController {
 			$nb = Request::param ('posts_per_page', 10);
 			$view = Request::param ('default_view', 'all');
 			$display = Request::param ('display_posts', 'no');
+			$lazyload = Request::param ('lazyload', 'yes');
 			$sort = Request::param ('sort_order', 'low_to_high');
 			$old = Request::param ('old_entries', 3);
 			$mail = Request::param ('mail_login', false);
@@ -154,6 +155,7 @@ class configureController extends ActionController {
 			$this->view->conf->_postsPerPage (intval ($nb));
 			$this->view->conf->_defaultView ($view);
 			$this->view->conf->_displayPosts ($display);
+			$this->view->conf->_lazyload ($lazyload);
 			$this->view->conf->_sortOrder ($sort);
 			$this->view->conf->_oldEntries ($old);
 			$this->view->conf->_mailLogin ($mail);
@@ -169,6 +171,7 @@ class configureController extends ActionController {
 				'posts_per_page' => $this->view->conf->postsPerPage (),
 				'default_view' => $this->view->conf->defaultView (),
 				'display_posts' => $this->view->conf->displayPosts (),
+				'lazyload' => $this->view->conf->lazyload (),
 				'sort_order' => $this->view->conf->sortOrder (),
 				'old_entries' => $this->view->conf->oldEntries (),
 				'mail_login' => $this->view->conf->mailLogin (),

+ 1 - 0
app/i18n/en.php

@@ -144,6 +144,7 @@ return array (
 	'default_view'			=> 'Default view',
 	'sort_order'			=> 'Sort order',
 	'display_articles_unfolded'	=> 'Show articles unfolded by default',
+	'img_with_lazyload'		=> 'Use "lazy load" mode to load pictures',
 	'auto_read_when'		=> 'Mark automatically as read when',
 	'article_selected'		=> 'Article is selected',
 	'article_open_on_website'	=> 'Article is opened on its original website',

+ 1 - 0
app/i18n/fr.php

@@ -144,6 +144,7 @@ return array (
 	'default_view'			=> 'Vue par défaut',
 	'sort_order'			=> 'Ordre de tri',
 	'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 automatiquement comme lu lorsque',
 	'article_selected'		=> 'L\'article est sélectionné',
 	'article_open_on_website'	=> 'L\'article est ouvert sur le site d\'origine',

+ 16 - 0
app/models/RSSConfiguration.php

@@ -9,6 +9,7 @@ class RSSConfiguration extends Model {
 	private $posts_per_page;
 	private $default_view;
 	private $display_posts;
+	private $lazyload;
 	private $sort_order;
 	private $old_entries;
 	private $shortcuts = array ();
@@ -22,6 +23,7 @@ class RSSConfiguration extends Model {
 		$this->_postsPerPage ($confDAO->posts_per_page);
 		$this->_defaultView ($confDAO->default_view);
 		$this->_displayPosts ($confDAO->display_posts);
+		$this->_lazyload ($confDAO->lazyload);
 		$this->_sortOrder ($confDAO->sort_order);
 		$this->_oldEntries ($confDAO->old_entries);
 		$this->_shortcuts ($confDAO->shortcuts);
@@ -45,6 +47,9 @@ class RSSConfiguration extends Model {
 	public function displayPosts () {
 		return $this->display_posts;
 	}
+	public function lazyload () {
+		return $this->lazyload;
+	}
 	public function sortOrder () {
 		return $this->sort_order;
 	}
@@ -100,6 +105,13 @@ class RSSConfiguration extends Model {
 			$this->display_posts = 'no';
 		}
 	}
+	public function _lazyload ($value) {
+		if ($value == 'no') {
+			$this->lazyload = 'no';
+		} else {
+			$this->lazyload = 'yes';
+		}
+	}
 	public function _sortOrder ($value) {
 		if ($value == 'high_to_low') {
 			$this->sort_order = 'high_to_low';
@@ -144,6 +156,7 @@ class RSSConfigurationDAO extends Model_array {
 	public $posts_per_page = 20;
 	public $default_view = 'not_read';
 	public $display_posts = 'no';
+	public $lazyload = 'yes';
 	public $sort_order = 'low_to_high';
 	public $old_entries = 3;
 	public $shortcuts = array (
@@ -178,6 +191,9 @@ class RSSConfigurationDAO extends Model_array {
 		if (isset ($this->array['display_posts'])) {
 			$this->display_posts = $this->array['display_posts'];
 		}
+		if (isset ($this->array['lazyload'])) {
+			$this->lazyload = $this->array['lazyload'];
+		}
 		if (isset ($this->array['sort_order'])) {
 			$this->sort_order = $this->array['sort_order'];
 		}

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

@@ -67,6 +67,20 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<label class="group-name"><?php echo Translate::t ('img_with_lazyload'); ?></label>
+			<div class="group-controls">
+				<label class="radio" for="lazyload_yes">
+					<input type="radio" name="lazyload" id="lazyload_yes" value="yes"<?php echo $this->conf->lazyload () == 'yes' ? ' checked="checked"' : ''; ?> />
+					<?php echo Translate::t ('yes'); ?><noscript> - <b><?php echo Translate::t ('javascript_should_be_activated'); ?></b></noscript>
+				</label>
+				<label class="radio" for="lazyload_no">
+					<input type="radio" name="lazyload" id="lazyload_no" value="no"<?php echo $this->conf->lazyload () == 'no' ? ' checked="checked"' : ''; ?> />
+					<?php echo Translate::t ('no'); ?>
+				</label>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<label class="group-name"><?php echo Translate::t ('display_articles_unfolded'); ?></label>
 			<div class="group-controls">

+ 7 - 1
app/views/index/index.phtml

@@ -66,7 +66,13 @@ if ($output == 'rss') {
 				<h1 class="title"><?php echo $item->title (); ?></h1>
 				<?php $author = $item->author (); ?>
 				<?php echo $author != '' ? '<div class="author">' . Translate::t ('by_author', $author) . '</div>' : ''; ?>
-				<?php echo lazyimg($item->content ()); ?>
+				<?php
+					if($this->conf->lazyload() == 'yes') {
+						echo lazyimg($item->content ());
+					} else {
+						echo $item->content();
+					}
+				?>
 			</div>
 
 			<ul class="horizontal-list bottom">

+ 2 - 1
app/views/javascript/main.phtml

@@ -125,8 +125,9 @@ function init_posts () {
 	<?php } ?>
 
 	init_img ();
-	// TODO rendre optionnel
+	<?php if($this->conf->lazyload() == 'yes') { ?>
 	$(".flux .content img").lazyload();
+	<?php } ?>
 
 	if (hide_posts) {
 		$(".flux:not(.active) .flux_content").hide ();