Kaynağa Gözat

Merge pull request #794 from aledeg/auto-remove-when-read

Add a cleaning process in the auto-remove feature.
Marien Fressinaud 11 yıl önce
ebeveyn
işleme
edc6816aec
1 değiştirilmiş dosya ile 18 ekleme ve 18 silme
  1. 18 18
      p/scripts/main.js

+ 18 - 18
p/scripts/main.js

@@ -238,12 +238,7 @@ function toggleContent(new_active, old_active) {
 		old_active.removeClass("active current");
 		old_active.removeClass("active current");
 		new_active.addClass("current");
 		new_active.addClass("current");
 		if (context['auto_remove_article'] && !old_active.hasClass('not_read')) {
 		if (context['auto_remove_article'] && !old_active.hasClass('not_read')) {
-			var p = old_active.prev();
-			var n = old_active.next();
-			if (p.hasClass('day') && n.hasClass('day')) {
-				p.remove();
-			}
-			old_active.remove();
+			auto_remove(old_active);
 		}
 		}
 	} else {
 	} else {
 		new_active.toggleClass('active');
 		new_active.toggleClass('active');
@@ -258,7 +253,7 @@ function toggleContent(new_active, old_active) {
 
 
 	if (context['sticky_post']) {
 	if (context['sticky_post']) {
 		var prev_article = new_active.prevAll('.flux'),
 		var prev_article = new_active.prevAll('.flux'),
-		    new_pos = new_active.position().top,
+			new_pos = new_active.position().top,
 			old_scroll = $(box_to_move).scrollTop();
 			old_scroll = $(box_to_move).scrollTop();
 
 
 		if (prev_article.length > 0 && new_pos - prev_article.position().top <= 150) {
 		if (prev_article.length > 0 && new_pos - prev_article.position().top <= 150) {
@@ -289,6 +284,16 @@ function toggleContent(new_active, old_active) {
 	}
 	}
 }
 }
 
 
+function auto_remove(element) {
+	var p = element.prev();
+	var n = element.next();
+	if (p.hasClass('day') && n.hasClass('day')) {
+		p.remove();
+	}
+	element.remove();
+	$('#stream > .flux:not(.not_read):not(.active)').remove();
+}
+
 function prev_entry() {
 function prev_entry() {
 	var old_active = $(".flux.current"),
 	var old_active = $(".flux.current"),
 		new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first");
 		new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first");
@@ -683,7 +688,7 @@ function init_stream(divStream) {
 		}
 		}
 		var old_active = $(".flux.current"),
 		var old_active = $(".flux.current"),
 			new_active = $(this).parent();
 			new_active = $(this).parent();
-			isCollapsed = true;
+		isCollapsed = true;
 		if (e.target.tagName.toUpperCase() === 'A') {	//Leave real links alone
 		if (e.target.tagName.toUpperCase() === 'A') {	//Leave real links alone
 			if (context['auto_mark_article']) {
 			if (context['auto_mark_article']) {
 				mark_read(new_active, true);
 				mark_read(new_active, true);
@@ -696,12 +701,7 @@ function init_stream(divStream) {
 	divStream.on('click', '.flux a.read', function () {
 	divStream.on('click', '.flux a.read', function () {
 		var active = $(this).parents(".flux");
 		var active = $(this).parents(".flux");
 		if (context['auto_remove_article'] && active.hasClass('not_read')) {
 		if (context['auto_remove_article'] && active.hasClass('not_read')) {
-			var p = active.prev();
-			var n = active.next();
-			if (p.hasClass('day') && n.hasClass('day')) {
-				p.remove();
-			}
-			active.remove();
+			auto_remove(active);
 		}
 		}
 		mark_read(active, false);
 		mark_read(active, false);
 		return false;
 		return false;
@@ -882,8 +882,8 @@ function notifs_html5_show(nb) {
 
 
 	if (context['html5_notif_timeout'] !== 0){
 	if (context['html5_notif_timeout'] !== 0){
 		setTimeout(function() {
 		setTimeout(function() {
-					notification.close();
-				}, context['html5_notif_timeout'] * 1000);
+			notification.close();
+		}, context['html5_notif_timeout'] * 1000);
 	}
 	}
 }
 }
 
 
@@ -899,7 +899,7 @@ function init_notifs_html5() {
 function refreshUnreads() {
 function refreshUnreads() {
 	$.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
 	$.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
 		var isAll = $('.category.all.active').length > 0,
 		var isAll = $('.category.all.active').length > 0,
-		    new_articles = false;
+			new_articles = false;
 
 
 		$.each(data, function(feed_id, nbUnreads) {
 		$.each(data, function(feed_id, nbUnreads) {
 			feed_id = 'f_' + feed_id;
 			feed_id = 'f_' + feed_id;
@@ -1195,7 +1195,7 @@ function faviconNbUnread(n) {
 
 
 function init_slider_observers() {
 function init_slider_observers() {
 	var slider = $('#slider'),
 	var slider = $('#slider'),
-	    closer = $('#close-slider');
+		closer = $('#close-slider');
 	if (slider.length < 1) {
 	if (slider.length < 1) {
 		return;
 		return;
 	}
 	}