From 84c03dda5f8c938317ec6f049301d1acaa00d0de Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 29 Oct 2013 21:53:02 +0100 Subject: LazyLoad manuel pour les articles repliés MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LazyLoad.js utilise énormément de CPU et ralentit considérablement le défilement de page, en particulier lorsque le nombre d'articles augmente. Dans le cas des articles repliés, il n'y a en fait pas besoin du mécanisme complexe de LazyLoad.js basé sur les événements scroll, car il suffit de charger les images lors du dépliage es articles, et cela allège énormément l'expérience. --- app/App_FrontController.php | 2 +- public/scripts/main.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 844956cf9..a9a0a564f 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -62,7 +62,7 @@ class App_FrontController extends FrontController { View::appendScript ('https://login.persona.org/include.js'); } View::appendScript (Url::display ('/scripts/jquery.min.js')); - if ($this->conf->lazyload () === 'yes') { + if ($this->conf->displayPosts () === 'yes' && $this->conf->lazyload () === 'yes') { View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js')); } View::appendScript (Url::display ('/scripts/notification.js')); diff --git a/public/scripts/main.js b/public/scripts/main.js index 72795be51..f01781bf7 100644 --- a/public/scripts/main.js +++ b/public/scripts/main.js @@ -24,6 +24,13 @@ function redirect (url, new_tab) { } function toggleContent (new_active, old_active) { + if (does_lazyload) { + new_active.find('img[data-original]').each(function() { + this.setAttribute('src', this.getAttribute('data-original')); + this.removeAttribute('data-original'); + }); + } + old_active.removeClass ("active"); if (old_active[0] != new_active[0]) { new_active.addClass ("active"); @@ -62,10 +69,6 @@ function toggleContent (new_active, old_active) { new_scroll = $(box_to_move).scrollTop (new_pos).scrollTop (); } - if ((new_scroll === old_scroll) && $.fn.lazyload) { - $(window).trigger ("scroll"); //When no scroll was done, generate fake scroll event for LazyLoad to load images - } - if (auto_mark_article) { mark_read(new_active, true); } @@ -182,7 +185,7 @@ function inMarkViewport(flux, box_to_follow, relative_follow) { function init_posts () { init_img (); - if (does_lazyload) { + if ($.fn.lazyload) { if (is_global_mode()) { $(".flux .content img").lazyload({ container: $("#panel") -- cgit v1.2.3 From 1a209f1e9b791d5339d0968b55e78844281daf0e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 30 Oct 2013 11:06:38 +0100 Subject: Ajoute le cas de la vue lecture --- app/App_FrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/App_FrontController.php b/app/App_FrontController.php index a9a0a564f..314e92ebc 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -62,7 +62,7 @@ class App_FrontController extends FrontController { View::appendScript ('https://login.persona.org/include.js'); } View::appendScript (Url::display ('/scripts/jquery.min.js')); - if ($this->conf->displayPosts () === 'yes' && $this->conf->lazyload () === 'yes') { + if ($this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js')); } View::appendScript (Url::display ('/scripts/notification.js')); -- cgit v1.2.3