www/src/layouts/partials/package-grid.html

176 lines
4.5 KiB
HTML
Raw Normal View History

<!-- Package Grid -->
<section>
<!-- Package Grid Header -->
<hr>
<div class="container package-grid-header">
<section class="flex">
<h3>packages</h3>
{{- partial "sort-dropdown.html" -}}
</section>
2022-10-19 20:50:00 +03:00
<p>There are already plenty of packages available through tea. As the communitea builds the library, contributions will live here.</p>
</div>
<hr>
<div class="container package-grid">
<!-- Start Package Grid -->
<div class="row package-row black-bg g-0">
<div id="packageGrid" class="package-grid">
{{ range $.Site.Data.packages }}
{{- partial "package-thumbnail.html" .}}
{{ end }}
</div>
2022-10-19 20:50:00 +03:00
</div>
</div>
<hr>
<div id="loadMoreSection" class="container small">
<div id="loadMorePackagesBtn"><i class="icon-enter-arrow"></i> SHOW MORE</div>
</div>
</section>
<style>
.container.small {
padding-top: 1em;
padding-bottom: 1em;
}
.package-grid {
display: grid;
grid-template-columns: auto auto;
}
#loadMorePackagesBtn {
cursor: pointer;
font-size: 2rem;
font-family: "pp-neue-machina", sans-serif;
background-color: #1a1a1a;
color: #fff;
padding-top: 0.279vw;
text-decoration: none;
text-transform: uppercase;
transition: 0.1s linear;
}
#loadMorePackagesBtn .icon-enter-arrow {
display: inline-block;
position: relaitve;
transition: all 0.2s ease-in-out;
}
#loadMorePackagesBtn:hover .icon-enter-arrow{
display: inline-block;
transform: rotate(-45deg) !important;
}
#loadMoreSection.hidden {
display: none;
}
@media only screen and (max-width: 576px) {
#loadMoreSection {
display: none;
}
}
@media only screen and (min-width: 576px) {
.package-grid {
/* changes to 3 column thumbs */
grid-template-columns: auto auto auto;
}
}
@media only screen and (min-width: 992px) {
.package-grid {
/* changes to 4 column thumbs */
grid-template-columns: auto auto auto auto;
}
}
.card-thumbnail.hidden {
height: 0px;
padding: 0px;
margin: 0px;
border: 0px;
overflow: hidden;
}
2022-10-14 23:23:32 +03:00
</style>
<script language="javascript" type="text/javascript">
const sortOptions = {
popularity: 'popularity',
last_modified: 'last_modified',
}
let sortBy = 'popularity'; // last_modified
let sortDirection = 'desc'; // asc
let limit = 16;
function getPackageThumbs() {
const grid = document.getElementById('packageGrid');
return Array.from(grid.childNodes).filter((e) => e.dataset && e.dataset.name);
}
const packagesCount = getPackageThumbs().length;
function sortPackages() {
const packages = getPackageThumbs();
const sortedPackages = packages.sort((a, b) => {
if (sortBy === sortOptions.popularity) {
const aPop = +a.dataset.popularity;
const bPop = +b.dataset.popularity;
return sortDirection === 'asc' ? aPop-bPop : bPop - aPop;
} else { // last_modified
const aDate = new Date(a.dataset.last_modified);
const bDate = new Date(b.dataset.last_modified);
return sortDirection === 'asc' ? aDate-bDate : bDate - aDate;
}
});
const grid = document.getElementById('packageGrid');
grid.textContent = '';
for(const sp of sortedPackages) {
grid.appendChild(sp);
}
refreshDisplayedPackages();
}
function refreshDisplayedPackages() {
const packages = getPackageThumbs();
let i = 0;
for(const sp of packages) {
if (i >= limit) {
sp.classList.add('hidden');
} else {
sp.classList.remove('hidden');
}
i++;
}
}
const loadMoreButton = document.getElementById('loadMorePackagesBtn');
loadMoreButton.addEventListener('click',() => {
limit += 16;
refreshDisplayedPackages();
if (limit >= packagesCount) {
const loadMoreSection = document.getElementById('loadMoreSection');
loadMoreSection.classList.add('hidden');
}
}, false);
const dropdownPopularityBtn = document.getElementById('dropdownPopularityBtn');
dropdownPopularityBtn.addEventListener('click',() => {
if (sortBy != sortOptions.popularity) {
sortBy = sortOptions.popularity;
sortPackages();
}
}, false);
const dropdownRecentBtn = document.getElementById('dropdownRecentBtn');
dropdownRecentBtn.addEventListener('click',() => {
if (sortBy != sortOptions.last_modified) {
sortBy = sortOptions.last_modified;
sortPackages();
}
}, false);
sortPackages();
</script>