From 7396b3d89724a6280684f0d2099fe17834a0f923 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 23 Jun 2013 17:40:05 +0200 Subject: Fix #77 : articles marqués comme lus au défilement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Possibilité de marquer les articles automatiquement comme lus lors du défilement de la page. Le marquage survient aux 3/4 de l'article visible. Ajout d'une option pour activer / désactiver (défaut) la fonctionnalité et disparition de l'option de marquage au chargement de la page. Ajout de 2 boutons pour marquer comme lu et en favori en bas des articles --- app/views/javascript/main.phtml | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'app/views/javascript/main.phtml') diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index e51cf978e..da95f9c04 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -58,6 +58,12 @@ function mark_read (active, only_not_read) { return false; } + if (active.hasClass ("not_read")) { + active.removeClass ("not_read"); + } else { + active.addClass ("not_read"); + } + url = active.find ("a.read").attr ("href"); if (url === undefined) { return false; @@ -71,11 +77,6 @@ function mark_read (active, only_not_read) { res = jQuery.parseJSON(data); active.find ("a.read").attr ("href", res.url); - if (active.hasClass ("not_read")) { - active.removeClass ("not_read"); - } else { - active.addClass ("not_read"); - } }); } @@ -139,14 +140,19 @@ function init_img () { }); } -function init_posts () { - - if ($(".flux.not_read")[0] != undefined) { - url = $(".nav_menu a.read_all").attr ("href"); - redirect (url, false); - } - +function inMarkViewport(flux) { + var top = flux.position().top; + var height = flux.height(); + var begin = top + 3 * height / 4; + var bot = top + height; + + var windowTop = $(window).scrollTop(); + var windowBot = windowTop + $(window).height(); + return (windowBot >= begin && windowBot <= bot); +} + +function init_posts () { init_img (); conf->lazyload() == 'yes') { ?> $(".flux .content img").lazyload(); @@ -186,6 +192,17 @@ function init_posts () { mark_read($(this).parent().parent().parent(), true); }); + + + var flux = $('.flux'); + $(window).scroll(function() { + flux.each(function() { + if($(this).hasClass('not_read') && inMarkViewport($(this))) { + mark_read($(this), true); + } + }); + }); + } function init_column_categories () { -- cgit v1.2.3