2022-09-16 23:32:54 +03:00
|
|
|
<!-- Package Grid -->
|
|
|
|
|
|
|
|
<section>
|
2022-11-10 00:31:57 +03:00
|
|
|
|
2022-11-10 08:45:48 +03:00
|
|
|
{{- partial "search-menu.html" "searchTermDesktop" -}}
|
2022-11-10 00:31:57 +03:00
|
|
|
<hr>
|
|
|
|
|
2022-10-29 00:07:47 +03:00
|
|
|
<div class="package-grid">
|
2022-09-16 23:32:54 +03:00
|
|
|
|
|
|
|
<!-- Start Package Grid -->
|
|
|
|
|
|
|
|
<div class="row package-row black-bg g-0">
|
2022-10-21 10:56:04 +03:00
|
|
|
<div id="packageGrid" class="package-grid">
|
2022-10-13 08:48:14 +03:00
|
|
|
{{ range $.Site.Data.packages }}
|
2022-10-12 09:04:13 +03:00
|
|
|
{{- partial "package-thumbnail.html" .}}
|
|
|
|
{{ end }}
|
2022-09-16 23:32:54 +03:00
|
|
|
</div>
|
2022-12-21 03:53:12 +03:00
|
|
|
{{- partial "no-results-found.html" }}
|
2022-09-16 23:32:54 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-15 16:07:54 +03:00
|
|
|
<hr>
|
|
|
|
<div id="loadMoreSection" class="container small">
|
|
|
|
<div id="loadMorePackagesBtn"><i class="icon-enter-arrow"></i> SHOW MORE</div>
|
|
|
|
</div>
|
2022-09-16 23:32:54 +03:00
|
|
|
</section>
|
2022-10-12 09:04:13 +03:00
|
|
|
|
|
|
|
<style>
|
2022-10-15 16:07:54 +03:00
|
|
|
.container.small {
|
|
|
|
padding-top: 1em;
|
|
|
|
padding-bottom: 1em;
|
|
|
|
}
|
2022-10-12 09:04:13 +03:00
|
|
|
.package-grid {
|
|
|
|
display: grid;
|
2022-11-15 05:23:07 +03:00
|
|
|
grid-template-columns: auto;
|
2022-10-12 09:04:13 +03:00
|
|
|
}
|
2022-10-15 16:07:54 +03:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
2022-10-12 09:04:13 +03:00
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
}
|
2022-10-15 16:07:54 +03:00
|
|
|
|
|
|
|
.card-thumbnail.hidden {
|
|
|
|
height: 0px;
|
|
|
|
padding: 0px;
|
|
|
|
margin: 0px;
|
|
|
|
border: 0px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2022-10-14 23:23:32 +03:00
|
|
|
</style>
|
2022-11-09 15:51:15 +03:00
|
|
|
<script async src="https://unpkg.com/string-similarity@4.0.1/umd/string-similarity.min.js"></script>
|
2022-10-15 16:07:54 +03:00
|
|
|
<script language="javascript" type="text/javascript">
|
2022-10-24 11:59:38 +03:00
|
|
|
const sortOptions = {
|
|
|
|
popularity: 'popularity',
|
|
|
|
last_modified: 'last_modified',
|
|
|
|
}
|
2022-11-15 05:23:07 +03:00
|
|
|
const showAllPackages = window.location.pathname.includes("/+/");
|
|
|
|
|
2022-10-24 14:40:19 +03:00
|
|
|
let sortBy = sortOptions.popularity; // last_modified
|
2022-10-21 10:56:04 +03:00
|
|
|
let sortDirection = 'desc'; // asc
|
2022-10-15 16:07:54 +03:00
|
|
|
let limit = 16;
|
2022-10-24 11:59:38 +03:00
|
|
|
|
2022-11-09 15:16:24 +03:00
|
|
|
const grid = document.getElementById('packageGrid');
|
|
|
|
const packagesCache = Array.from(grid.children).filter((e) => e.dataset && e.dataset.name);
|
|
|
|
|
|
|
|
function debounce(fn, delay) {
|
|
|
|
var timer = null;
|
|
|
|
return function () {
|
|
|
|
var context = this, args = arguments;
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(function () {
|
|
|
|
fn.apply(context, args);
|
|
|
|
}, delay);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const onSearch = debounce(() => {
|
2022-11-10 08:45:48 +03:00
|
|
|
const searchInput = document.getElementById('searchTermDesktop');
|
2022-12-21 03:53:12 +03:00
|
|
|
const noResult = document.getElementById('noResult');
|
2022-11-09 15:16:24 +03:00
|
|
|
if (searchInput.value) {
|
|
|
|
const term = searchInput.value;
|
|
|
|
const packages = getPackageThumbs();
|
|
|
|
const sortedPackages = packages.sort((a, b) => {
|
|
|
|
const aScore = getMatchScore(term, a.dataset);
|
|
|
|
const bScore = getMatchScore(term, b.dataset);
|
|
|
|
return bScore - aScore;
|
|
|
|
});
|
|
|
|
const grid = document.getElementById('packageGrid');
|
|
|
|
grid.textContent = '';
|
2022-12-21 03:53:12 +03:00
|
|
|
let searchCount = 0;
|
2022-11-09 15:16:24 +03:00
|
|
|
for(const sp of sortedPackages) {
|
|
|
|
const score = getMatchScore(term, sp.dataset);
|
2022-11-10 08:45:48 +03:00
|
|
|
if (score > 20) {
|
2022-11-09 15:16:24 +03:00
|
|
|
sp.classList.remove('hidden');
|
2022-12-21 03:53:12 +03:00
|
|
|
searchCount++;
|
2022-11-09 15:16:24 +03:00
|
|
|
} else {
|
|
|
|
sp.classList.add('hidden');
|
|
|
|
}
|
|
|
|
grid.appendChild(sp);
|
|
|
|
}
|
2022-12-21 03:53:12 +03:00
|
|
|
|
|
|
|
if (searchCount) {
|
2022-12-22 02:46:10 +03:00
|
|
|
loadMoreSection.classList.remove('hidden');
|
2022-12-21 03:53:12 +03:00
|
|
|
noResult.classList.remove('show');
|
|
|
|
} else {
|
2022-12-22 02:46:10 +03:00
|
|
|
loadMoreSection.classList.add('hidden');
|
2022-12-21 03:53:12 +03:00
|
|
|
noResult.classList.add('show');
|
|
|
|
}
|
2022-12-22 02:46:10 +03:00
|
|
|
|
2022-11-09 15:16:24 +03:00
|
|
|
} else {
|
2022-12-21 03:53:12 +03:00
|
|
|
noResult.classList.remove('show');
|
2022-11-09 15:16:24 +03:00
|
|
|
sortPackages();
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
|
2022-11-10 08:45:48 +03:00
|
|
|
const searchInputDesktop = document.getElementById('searchTermDesktop');
|
|
|
|
searchInputDesktop.addEventListener("search", onSearch);
|
|
|
|
searchInputDesktop.addEventListener("change", onSearch);
|
|
|
|
searchInputDesktop.addEventListener("keyup", onSearch);
|
|
|
|
|
2022-10-24 11:59:38 +03:00
|
|
|
function getPackageThumbs() {
|
2022-11-09 15:16:24 +03:00
|
|
|
// const grid = document.getElementById('packageGrid');
|
|
|
|
return packagesCache;
|
2022-10-24 11:59:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const packagesCount = getPackageThumbs().length;
|
2022-10-15 16:07:54 +03:00
|
|
|
|
2022-10-21 10:56:04 +03:00
|
|
|
function sortPackages() {
|
2022-10-24 11:59:38 +03:00
|
|
|
const packages = getPackageThumbs();
|
|
|
|
const sortedPackages = packages.sort((a, b) => {
|
|
|
|
if (sortBy === sortOptions.popularity) {
|
2022-10-21 10:56:04 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2022-10-24 11:59:38 +03:00
|
|
|
|
2022-10-21 10:56:04 +03:00
|
|
|
const grid = document.getElementById('packageGrid');
|
2022-10-24 11:59:38 +03:00
|
|
|
grid.textContent = '';
|
|
|
|
|
2022-10-21 10:56:04 +03:00
|
|
|
for(const sp of sortedPackages) {
|
|
|
|
grid.appendChild(sp);
|
|
|
|
}
|
2022-10-24 23:54:47 +03:00
|
|
|
|
2022-10-24 14:40:19 +03:00
|
|
|
const isPopularity = sortBy === sortOptions.popularity;
|
|
|
|
|
|
|
|
setBtnStyles(sortOptions.popularity, isPopularity);
|
|
|
|
setBtnStyles(sortOptions.last_modified, !isPopularity);
|
2022-10-21 10:56:04 +03:00
|
|
|
refreshDisplayedPackages();
|
|
|
|
}
|
|
|
|
|
2022-10-15 16:07:54 +03:00
|
|
|
function refreshDisplayedPackages() {
|
2022-10-24 11:59:38 +03:00
|
|
|
const packages = getPackageThumbs();
|
2022-10-21 10:56:04 +03:00
|
|
|
let i = 0;
|
|
|
|
for(const sp of packages) {
|
2022-11-15 05:23:07 +03:00
|
|
|
if (i >= limit && !showAllPackages) {
|
2022-10-21 10:56:04 +03:00
|
|
|
sp.classList.add('hidden');
|
2022-10-15 16:07:54 +03:00
|
|
|
} else {
|
2022-10-21 10:56:04 +03:00
|
|
|
sp.classList.remove('hidden');
|
2022-10-15 16:07:54 +03:00
|
|
|
}
|
2022-10-21 10:56:04 +03:00
|
|
|
i++;
|
2022-10-15 16:07:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 15:16:24 +03:00
|
|
|
function getMatchScore(term, dataset) {
|
|
|
|
// provide higher value with name
|
|
|
|
const { name, description } = dataset;
|
|
|
|
const nameScore = stringSimilarity.compareTwoStrings(name, term);
|
|
|
|
const descriptionScore = stringSimilarity.compareTwoStrings(description, term);
|
|
|
|
return (nameScore*80) + (descriptionScore*20)
|
|
|
|
}
|
|
|
|
|
2022-10-15 16:07:54 +03:00
|
|
|
const loadMoreButton = document.getElementById('loadMorePackagesBtn');
|
2022-11-15 05:23:07 +03:00
|
|
|
if (showAllPackages) {
|
|
|
|
loadMoreSection.classList.add('hidden');
|
|
|
|
} else {
|
|
|
|
loadMoreSection.classList.remove('hidden');
|
|
|
|
}
|
2022-10-15 16:07:54 +03:00
|
|
|
loadMoreButton.addEventListener('click',() => {
|
|
|
|
limit += 16;
|
|
|
|
refreshDisplayedPackages();
|
|
|
|
if (limit >= packagesCount) {
|
|
|
|
const loadMoreSection = document.getElementById('loadMoreSection');
|
|
|
|
loadMoreSection.classList.add('hidden');
|
|
|
|
}
|
2022-10-24 11:59:38 +03:00
|
|
|
}, false);
|
|
|
|
|
2022-10-24 14:40:19 +03:00
|
|
|
function getSortBtns(type) {
|
|
|
|
const typeBtn = document.getElementById(`dropdown-${type}-btn`);
|
|
|
|
const typeDownBtn = document.getElementById(`${type}-down-btn`);
|
|
|
|
const typeUpBtn = document.getElementById(`${type}-up-btn`);
|
|
|
|
return { typeBtn, typeDownBtn, typeUpBtn };
|
|
|
|
}
|
2022-10-24 11:59:38 +03:00
|
|
|
|
2022-10-24 14:40:19 +03:00
|
|
|
function setBtnStyles(type, active) {
|
|
|
|
const { typeBtn, typeDownBtn, typeUpBtn } = getSortBtns(type);
|
|
|
|
if (active) {
|
|
|
|
typeBtn.classList.add('active');
|
|
|
|
if (sortDirection === 'asc') {
|
|
|
|
typeUpBtn.classList.add('active');
|
|
|
|
typeDownBtn.classList.remove('active');
|
|
|
|
} else {
|
|
|
|
typeDownBtn.classList.add('active');
|
|
|
|
typeUpBtn.classList.remove('active');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
typeBtn.classList.remove('active');
|
|
|
|
typeDownBtn.classList.remove('active');
|
|
|
|
typeUpBtn.classList.remove('active');
|
2022-10-24 11:59:38 +03:00
|
|
|
}
|
2022-10-24 14:40:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function configureSortButton(type) {
|
|
|
|
const { typeBtn, typeDownBtn, typeUpBtn } = getSortBtns(type);
|
|
|
|
typeBtn.addEventListener('click',() => {
|
|
|
|
if (sortBy != type) {
|
|
|
|
sortBy = type;
|
|
|
|
sortPackages();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
typeDownBtn.addEventListener('click',() => {
|
|
|
|
if (sortBy != type || sortDirection != 'desc') {
|
|
|
|
sortBy = type;
|
|
|
|
sortDirection = 'desc';
|
|
|
|
sortPackages();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
typeUpBtn.addEventListener('click',() => {
|
|
|
|
if (sortBy != type || sortDirection != 'asc') {
|
|
|
|
sortBy = type;
|
|
|
|
sortDirection = 'asc';
|
|
|
|
sortPackages();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
configureSortButton(sortOptions.popularity);
|
|
|
|
configureSortButton(sortOptions.last_modified);
|
2022-10-24 11:59:38 +03:00
|
|
|
|
2022-10-21 10:56:04 +03:00
|
|
|
sortPackages();
|
2022-10-15 16:07:54 +03:00
|
|
|
</script>
|