Use generateGridCard() for showing news items, load images lazily

master
Skylar Ittner 5 years ago
parent a59a830f5e
commit 24ebebb0dc

@ -128,32 +128,9 @@ foreach ($newsitems as $item) {
break;
}
$count++;
?>
<div class="col-12 col-sm-6 col-md-6 col-lg-4 px-1 m-0 grid__brick" data-groups='["<?php echo $item->getCategory()->toString(); ?>"]'>
<div class="card mb-2">
<?php if (!empty($item->getImage())) { ?>
<a href="<?php echo $item->getURL(); ?>" target="_BLANK">
<?php
if (strpos($item->getImage(), "preview.redd.it") !== false) {
$imgurl = $item->getImage();
} else {
$imgurl = Thumbnail::getThumbnailCacheURL($item->getImage(), 500);
}
?>
<img src="<?php echo $imgurl; ?>" class="card-img-top newscard-img" alt="">
</a>
<?php } ?>
<div class="card-body">
<a class="text-dark" href="<?php echo $item->getURL(); ?>" target="_BLANK">
<h4 class="card-title">
<?php echo htmlentities($item->getHeadline()); ?>
</h4>
</a>
<p class="small"><?php echo $item->getSource(); ?></p>
</div>
</div>
</div>
<?php } ?>
echo $item->generateGridCard(false);
}
?>
<div class="col-1 sizer-element"></div>

@ -30,31 +30,11 @@ $newsitems = News::getItems();
<div class="row" id="news-grid">
<?php foreach ($newsitems as $item) { ?>
<div class="col-12 col-sm-6 col-md-6 col-lg-4 px-1 m-0 grid__brick" data-groups='["<?php echo $item->getCategory()->toString(); ?>"]'>
<div class="card mb-2">
<?php if (!empty($item->getImage())) { ?>
<a href="<?php echo $item->getURL(); ?>" target="_BLANK">
<img src="<?php
if (strpos($item->getImage(), "preview.redd.it") !== false) {
echo $item->getImage();
} else {
echo Thumbnail::getThumbnailCacheURL($item->getImage(), 500);
}
?>" class="card-img-top newscard-img" alt="">
</a>
<?php } ?>
<div class="card-body">
<a class="text-dark" href="<?php echo $item->getURL(); ?>" target="_BLANK">
<h4 class="card-title">
<?php echo htmlentities($item->getHeadline()); ?>
</h4>
</a>
<p class="small"><?php echo $item->getSource(); ?></p>
</div>
</div>
</div>
<?php } ?>
<?php
foreach ($newsitems as $item) {
echo $item->generateGridCard(true);
}
?>
<div class="col-1 sizer-element"></div>

@ -2,4 +2,4 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
*/

@ -4,9 +4,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
function fetchVisibleGridImages() {
$(".grid__brick").each(function () {
if ($(this).css("opacity") == "1") {
$("img.newscard-img", this).attr("src", $("img.newscard-img", this).data("src"));
}
});
}
$("input[name=newscategory]").on("change", function () {
window.shuffleInstance.filter($(this).val());
$(this).button('toggle');
setTimeout(fetchVisibleGridImages, 500);
});
window.shuffleInstance.filter("general");
window.shuffleInstance.filter("general");
setTimeout(fetchVisibleGridImages, 500);

@ -13,13 +13,6 @@ setInterval(function () {
window.shuffleInstance.layout();
}, 500);
$("img.newscard-img").on("error", function () {
if ($(this).data("reloaded")) {
return;
}
var img = $(this);
setTimeout(function () {
img.attr("src", $(this).attr("src"));
img.data("reloaded", true);
}, 500);
});
// Show the images using JavaScript, to make sure we don't see double
// when JS is disabled
$("img.newscard-img.d-none").removeClass("d-none");
Loading…
Cancel
Save