Преглед изворни кода

Fix issue #75 : chargement des images en lazyload, reste à le rendre optionnel

Marien Fressinaud пре 13 година
родитељ
комит
1d459af046

+ 1 - 0
app/App_FrontController.php

@@ -56,6 +56,7 @@ class App_FrontController extends FrontController {
 			View::appendScript ('https://login.persona.org/include.js');
 		}
 		View::appendScript (Url::display ('/scripts/jquery.js'));
+		View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js'));
 		View::appendScript (Url::display ('/scripts/notification.js'));
 	}
 

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

@@ -1,4 +1,12 @@
 <?php
+function lazyimg($content) {
+	return preg_replace(
+		'/<img([^<]+)src=([\'"])([^"\']*)([\'"])([^<]*)>/i',
+		'<img$1src="' . Url::display('/data/grey.gif') . '" data-original="$3"$5>',
+		$content
+	);
+}
+
 $output = Request::param ('output', 'normal');
 
 if ($output == 'rss') {
@@ -58,7 +66,7 @@ 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 $item->content (); ?>
+				<?php echo lazyimg($item->content ()); ?>
 			</div>
 
 			<ul class="horizontal-list bottom">

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

@@ -109,8 +109,8 @@ function mark_favorite (active) {
 }
 
 function init_img () {
-	$(".flux .content img").each (function () {
-		if ($(this).width () > ($("#stream .content").width()) / 2) {
+	$(".flux_content .content img").each (function () {
+		if ($(this).width () > ($(".flux_content .content").width()) / 2) {
 			$(this).addClass("big");
 		}
 	});
@@ -125,6 +125,8 @@ function init_posts () {
 	<?php } ?>
 
 	init_img ();
+	// TODO rendre optionnel
+	$(".flux .content img").lazyload();
 
 	if (hide_posts) {
 		$(".flux:not(.active) .flux_content").hide ();

Разлика између датотеке није приказан због своје велике величине
+ 14 - 0
public/scripts/jquery.lazyload.min.js


Неке датотеке нису приказане због велике количине промена