Przeglądaj źródła

Add a configuration option to get sticky articles

Now the user can choose if an opened article will be repositioned to the top or not

See #338
Alexis Degrugillier 12 lat temu
rodzic
commit
1e105a64ab

+ 1 - 0
app/Controllers/configureController.php

@@ -148,6 +148,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 			$this->view->conf->_display_posts(Minz_Request::param('display_posts', false));
 			$this->view->conf->_onread_jump_next(Minz_Request::param('onread_jump_next', false));
 			$this->view->conf->_lazyload (Minz_Request::param('lazyload', false));
+			$this->view->conf->_sticky_post (Minz_Request::param('sticky_post', false));
 			$this->view->conf->_sort_order(Minz_Request::param('sort_order', 'DESC'));
 			$this->view->conf->_mark_when (array(
 				'article' => Minz_Request::param('mark_open_article', false),

+ 4 - 0
app/Models/Configuration.php

@@ -17,6 +17,7 @@ class FreshRSS_Configuration {
 		'display_posts' => false,
 		'onread_jump_next' => true,
 		'lazyload' => true,
+		'sticky_post' => true,
 		'sort_order' => 'DESC',
 		'anon_access' => false,
 		'mark_when' => array(
@@ -140,6 +141,9 @@ class FreshRSS_Configuration {
 	public function _lazyload ($value) {
 		$this->data['lazyload'] = ((bool)$value) && $value !== 'no';
 	}
+	public function _sticky_post($value) {
+		$this->data['sticky_post'] = ((bool)$value) && $value !== 'no';
+	}
 	public function _sort_order ($value) {
 		$this->data['sort_order'] = $value === 'ASC' ? 'ASC' : 'DESC';
 	}

+ 1 - 0
app/i18n/en.php

@@ -215,6 +215,7 @@ return array (
 	'top_line'			=> 'Top line',
 	'bottom_line'			=> 'Bottom line',
 	'img_with_lazyload'		=> 'Use "lazy load" mode to load pictures',
+	'sticky_post'			=> 'Stick the article to the top when opened',
 	'auto_read_when'		=> 'Mark article as read…',
 	'article_selected'		=> 'when article is selected',
 	'article_open_on_website'	=> 'when article is opened on its original website',

+ 1 - 0
app/i18n/fr.php

@@ -215,6 +215,7 @@ return array (
 	'top_line'			=> 'Ligne du haut',
 	'bottom_line'			=> 'Ligne du bas',
 	'img_with_lazyload'		=> 'Utiliser le mode “chargement différé” pour les images',
+	'sticky_post'			=> 'Aligner l’article en haut quand il est ouvert',
 	'auto_read_when'		=> 'Marquer un article comme lu…',
 	'article_selected'		=> 'lorsque l’article est sélectionné',
 	'article_open_on_website'	=> 'lorsque l’article est ouvert sur le site d’origine',

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

@@ -110,6 +110,16 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<div class="group-controls">
+				<label class="checkbox" for="sticky_post">
+					<input type="checkbox" name="sticky_post" id="sticky_post" value="1"<?php echo $this->conf->sticky_post ? ' checked="checked"' : ''; ?> />
+					<?php echo Minz_Translate::t ('sticky_post'); ?>
+					<noscript> — <strong><?php echo Minz_Translate::t ('javascript_should_be_activated'); ?></strong></noscript>
+				</label>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<label class="group-name"><?php echo Minz_Translate::t ('auto_read_when'); ?></label>
 			<div class="group-controls">

+ 2 - 1
app/views/helpers/javascript_vars.phtml

@@ -11,7 +11,8 @@ echo 'var ',
 	',auto_mark_scroll=', $mark['scroll'] ? 'true' : 'false',
 	',auto_load_more=', $this->conf->auto_load_more ? 'true' : 'false',
 	',full_lazyload=', $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param('output') === 'reader') ? 'true' : 'false',
-	',does_lazyload=', $this->conf->lazyload ? 'true' : 'false';
+	',does_lazyload=', $this->conf->lazyload ? 'true' : 'false',
+	',sticky_post=', $this->conf->sticky_post ? 'true' : 'false';
 
 $s = $this->conf->shortcuts;
 echo ',shortcuts={',

+ 18 - 16
p/scripts/main.js

@@ -238,26 +238,28 @@ function toggleContent(new_active, old_active) {
 
 	var new_pos = new_active.position().top,
 		old_scroll = $(box_to_move).scrollTop();
-	if (hide_posts) {
+	if (sticky_post) {
+		if (hide_posts) {
 
-		new_pos = new_active.position().top;
-		old_scroll = $(box_to_move).scrollTop();
+			new_pos = new_active.position().top;
+			old_scroll = $(box_to_move).scrollTop();
 
-		if (relative_move) {
-			new_pos += old_scroll;
-		}
+			if (relative_move) {
+				new_pos += old_scroll;
+			}
 
-		if (old_active[0] !== new_active[0]) {
-			new_active.children(".flux_content").first().each(function () {
-				$(box_to_move).scrollTop(new_pos).scrollTop();
-			});
-		}
-	} else {
-		if (relative_move) {
-			new_pos += old_scroll;
-		}
+			if (old_active[0] !== new_active[0]) {
+				new_active.children(".flux_content").first().each(function () {
+					$(box_to_move).scrollTop(new_pos).scrollTop();
+				});
+			}
+		} else {
+			if (relative_move) {
+				new_pos += old_scroll;
+			}
 
-		$(box_to_move).scrollTop(new_pos).scrollTop();
+			$(box_to_move).scrollTop(new_pos).scrollTop();
+		}
 	}
 
 	if (auto_mark_article) {