-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jurj-Bogdan <[email protected]>
- Loading branch information
1 parent
0325362
commit 3b467e2
Showing
3 changed files
with
89 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,102 @@ | ||
'use strict'; | ||
|
||
$(document).ready(function () { | ||
$('.package-button').click(function (e) { | ||
e.preventDefault(); | ||
|
||
const url = new URL(window.location.href); | ||
const params = new URLSearchParams(url.search); | ||
const entry = $(this).data('value'); | ||
|
||
if ($(this).hasClass('keyword')) { | ||
if (! params.has("keywords[]", entry)) { | ||
params.append("keywords[]", entry); | ||
url.search = params.toString(); | ||
|
||
window.location.replace(url.toString()); | ||
} | ||
document.querySelectorAll('.package-button.type, .package-button.category, .package-button.usage').forEach(button => { | ||
button.addEventListener('click', handleFilters); | ||
}) | ||
|
||
document.querySelectorAll('.package-button.keyword').forEach(button => { | ||
button.addEventListener('click', handleKeywords); | ||
}) | ||
|
||
document.querySelectorAll('.ecosystem-filter').forEach(button => { | ||
button.addEventListener('click', removeKeyword); | ||
}) | ||
|
||
document.querySelectorAll('#ecosystem-pagination a').forEach(a => { | ||
const url = new URL(a.href) | ||
for (let [k,v] of new URLSearchParams(window.location.search).entries()) { | ||
if (k === 'keywords[]' || k === 'q' || k === 'type' || k === 'category' || k === 'usage') { | ||
url.searchParams.set(k,v); | ||
} | ||
} | ||
a.href = url.toString(); | ||
}) | ||
|
||
if ($(this).hasClass('type')) { | ||
if (! params.has("type", entry)) { | ||
url.searchParams.set('type', entry); | ||
|
||
window.location.replace(url.toString()); | ||
} else if (params.get("type") === entry) { | ||
url.searchParams.delete("type"); | ||
document.querySelector('#clear-filters-button')?.addEventListener('click', function () { | ||
const url = new URL(window.location.href); | ||
|
||
window.location.replace(url.toString()); | ||
} | ||
for (let [k,v] of new URLSearchParams(window.location.search).entries()) { | ||
if (k !== 'page') { | ||
url.searchParams.delete(k); | ||
} | ||
} | ||
|
||
if ($(this).hasClass('category')) { | ||
if (! params.has("category", entry)) { | ||
url.searchParams.set('category', entry); | ||
|
||
window.location.replace(url.toString()); | ||
} else if (params.get("category") === entry) { | ||
url.searchParams.delete("category"); | ||
|
||
window.location.replace(url.toString()); | ||
} | ||
} | ||
window.location.replace(url.toString()); | ||
}); | ||
|
||
if ($(this).hasClass('usage')) { | ||
if (! params.has("usage", entry)) { | ||
url.searchParams.set('usage', entry); | ||
document.querySelector('#ecosystem-search-btn').addEventListener('click', function () { | ||
setSearchQuery(document.querySelector('#ecosystem-search').value); | ||
}); | ||
|
||
window.location.replace(url.toString()); | ||
} else if (params.get("usage") === entry) { | ||
url.searchParams.delete("usage"); | ||
document.querySelector('#ecosystem-search').addEventListener('keypress', function (e) { | ||
const search = this.value; | ||
if (e.which === 13) { | ||
setSearchQuery(search); | ||
} | ||
}) | ||
|
||
window.location.replace(url.toString()); | ||
} | ||
function handleFilters() { | ||
for (const filter of ['type', 'category', 'usage']) { | ||
if (this.classList.contains(filter)) { | ||
handleParams(filter, this.dataset.value); | ||
} | ||
}); | ||
|
||
$('.ecosystem-filter').click(function (e) { | ||
e.preventDefault(); | ||
} | ||
} | ||
|
||
const url = new URL(window.location.href); | ||
const params = new URLSearchParams(url.search); | ||
const entry = $(this).data('value'); | ||
function handleParams(filterKey, filterValue) { | ||
const url = new URL(window.location.href); | ||
const params = new URLSearchParams(url.search); | ||
|
||
if ($(this).hasClass('keyword')) { | ||
if (params.has("keywords[]", entry)) { | ||
params.delete("keywords[]", entry); | ||
url.search = params.toString(); | ||
if (! params.has(filterKey, filterValue)) { | ||
url.searchParams.set(filterKey, filterValue); | ||
|
||
window.location.replace(url.toString()); | ||
} | ||
} | ||
}); | ||
|
||
[...$('#ecosystem-pagination a')].forEach(a => { | ||
const url = new URL(a.href) | ||
for (let [k,v] of new URLSearchParams(window.location.search).entries()) { | ||
if (k === 'keywords[]' || k === 'q' || k === 'type' || k === 'category' || k === 'usage') { | ||
url.searchParams.set(k,v) | ||
} | ||
} | ||
a.href = url.toString(); | ||
}) | ||
window.location.replace(url.toString()); | ||
} else if (params.get(filterKey) === filterValue) { | ||
url.searchParams.delete(filterKey); | ||
|
||
$('#ecosystem-search').keypress(function (e) { | ||
const search = $(this).val(); | ||
if (e.which === 13) { | ||
setSearchQuery(search); | ||
} | ||
}); | ||
window.location.replace(url.toString()); | ||
} | ||
} | ||
|
||
$('#ecosystem-search-btn').click(function (e) { | ||
const search = $('#ecosystem-search').val(); | ||
setSearchQuery(search); | ||
}); | ||
function handleKeywords() { | ||
const url = new URL(window.location.href); | ||
const params = new URLSearchParams(url.search); | ||
const keyword = this.dataset.value; | ||
|
||
function setSearchQuery(search) { | ||
const url = new URL(window.location.href); | ||
if (! params.has("keywords[]", keyword)) { | ||
params.append("keywords[]", keyword); | ||
url.search = params.toString(); | ||
|
||
url.searchParams.set('q', search); | ||
window.location.replace(url.toString()); | ||
} | ||
} | ||
|
||
$('#clear-filters-button').click(function (e) { | ||
const url = new URL(window.location.href); | ||
function removeKeyword() { | ||
const url = new URL(window.location.href); | ||
const params = new URLSearchParams(url.search); | ||
const keyword = this.dataset.value; | ||
|
||
for (let [k,v] of new URLSearchParams(window.location.search).entries()) { | ||
if (k === 'type' || k === 'category' || k === 'usage') { | ||
url.searchParams.delete(k) | ||
} | ||
} | ||
if (params.has("keywords[]", keyword)) { | ||
params.delete("keywords[]", keyword); | ||
url.search = params.toString(); | ||
|
||
window.location.replace(url.toString()); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
function setSearchQuery(search) { | ||
const url = new URL(window.location.href); | ||
|
||
url.searchParams.set('q', search); | ||
window.location.replace(url.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,4 +541,4 @@ article { | |
gap: .5em; | ||
align-items: baseline; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters