|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -document.querySelectorAll('.package-button.type, .package-button.category, .package-button.usage').forEach(button => { |
4 | | - button.addEventListener('click', handleFilters); |
5 | | -}) |
6 | | - |
7 | | -document.querySelectorAll('.package-button.keyword').forEach(button => { |
8 | | - button.addEventListener('click', handleKeywords); |
9 | | -}) |
10 | | - |
11 | | -document.querySelectorAll('.integration-filter').forEach(button => { |
12 | | - button.addEventListener('click', removeKeyword); |
13 | | -}) |
14 | | - |
15 | | -document.querySelectorAll('#integration-pagination a').forEach(a => { |
16 | | - const url = new URL(a.href) |
17 | | - for (let [k,v] of new URLSearchParams(window.location.search).entries()) { |
18 | | - if (k === 'keywords[]' || k === 'q' || k === 'type' || k === 'category' || k === 'usage') { |
19 | | - url.searchParams.set(k,v); |
20 | | - } |
| 3 | +document.addEventListener('DOMContentLoaded', () => { |
| 4 | + const onIntegrationPage = document.querySelector('.package-button'); |
| 5 | + if (! onIntegrationPage) { |
| 6 | + return; |
21 | 7 | } |
22 | | - a.href = url.toString(); |
23 | | -}) |
24 | 8 |
|
25 | | -document.querySelector('#clear-filters-button')?.addEventListener('click', function () { |
26 | | - const url = new URL(window.location.href); |
| 9 | + loadIntegrationPage(); |
| 10 | +}); |
27 | 11 |
|
28 | | - for (let [k,v] of new URLSearchParams(window.location.search).entries()) { |
29 | | - if (k !== 'page') { |
30 | | - url.searchParams.delete(k); |
| 12 | +function loadIntegrationPage() |
| 13 | +{ |
| 14 | + document.querySelectorAll('.package-button.type, .package-button.category, .package-button.usage').forEach(button => { |
| 15 | + button.addEventListener('click', handleFilters); |
| 16 | + }) |
| 17 | + |
| 18 | + document.querySelectorAll('.package-button.keyword').forEach(button => { |
| 19 | + button.addEventListener('click', handleKeywords); |
| 20 | + }) |
| 21 | + |
| 22 | + document.querySelectorAll('.integration-filter').forEach(button => { |
| 23 | + button.addEventListener('click', removeKeyword); |
| 24 | + }) |
| 25 | + |
| 26 | + document.querySelectorAll('#integration-pagination a').forEach(a => { |
| 27 | + const url = new URL(a.href) |
| 28 | + for (let [k,v] of new URLSearchParams(window.location.search).entries()) { |
| 29 | + if (k === 'keywords[]' || k === 'q' || k === 'type' || k === 'category' || k === 'usage') { |
| 30 | + url.searchParams.set(k,v); |
| 31 | + } |
31 | 32 | } |
32 | | - } |
| 33 | + a.href = url.toString(); |
| 34 | + }) |
33 | 35 |
|
34 | | - window.location.replace(url.toString()); |
35 | | -}); |
| 36 | + document.querySelector('#clear-filters-button')?.addEventListener('click', function () { |
| 37 | + const url = new URL(window.location.href); |
36 | 38 |
|
37 | | -document.querySelector('#integration-search-btn').addEventListener('click', function () { |
38 | | - setSearchQuery(document.querySelector('#integration-search').value); |
39 | | -}); |
| 39 | + for (let [k,v] of new URLSearchParams(window.location.search).entries()) { |
| 40 | + if (k !== 'page') { |
| 41 | + url.searchParams.delete(k); |
| 42 | + } |
| 43 | + } |
40 | 44 |
|
41 | | -document.querySelector('#integration-search').addEventListener('keypress', function (e) { |
42 | | - const search = this.value; |
43 | | - if (e.which === 13) { |
44 | | - setSearchQuery(search); |
45 | | - } |
46 | | -}) |
| 45 | + window.location.replace(url.toString()); |
| 46 | + }); |
| 47 | + |
| 48 | + document.querySelector('#integration-search-btn').addEventListener('click', function () { |
| 49 | + setSearchQuery(document.querySelector('#integration-search').value); |
| 50 | + }); |
47 | 51 |
|
48 | | -function handleFilters() { |
49 | | - for (const filter of ['type', 'category', 'usage']) { |
50 | | - if (this.classList.contains(filter)) { |
51 | | - handleParams(filter, this.dataset.value); |
| 52 | + document.querySelector('#integration-search').addEventListener('keypress', function (e) { |
| 53 | + const search = this.value; |
| 54 | + if (e.which === 13) { |
| 55 | + setSearchQuery(search); |
| 56 | + } |
| 57 | + }) |
| 58 | + |
| 59 | + function handleFilters() { |
| 60 | + for (const filter of ['type', 'category', 'usage']) { |
| 61 | + if (this.classList.contains(filter)) { |
| 62 | + handleParams(filter, this.dataset.value); |
| 63 | + } |
52 | 64 | } |
53 | 65 | } |
54 | | -} |
55 | 66 |
|
56 | | -function handleParams(filterKey, filterValue) { |
57 | | - const url = new URL(window.location.href); |
58 | | - const params = new URLSearchParams(url.search); |
| 67 | + function handleParams(filterKey, filterValue) { |
| 68 | + const url = new URL(window.location.href); |
| 69 | + const params = new URLSearchParams(url.search); |
59 | 70 |
|
60 | | - if (filterValue === 'all' || params.get(filterKey) === filterValue) { |
61 | | - url.searchParams.delete(filterKey); |
| 71 | + if (filterValue === 'all' || params.get(filterKey) === filterValue) { |
| 72 | + url.searchParams.delete(filterKey); |
62 | 73 |
|
63 | | - window.location.replace(url.toString()); |
64 | | - } else if (! params.has(filterKey, filterValue)) { |
65 | | - url.searchParams.set(filterKey, filterValue); |
| 74 | + window.location.replace(url.toString()); |
| 75 | + } else if (! params.has(filterKey, filterValue)) { |
| 76 | + url.searchParams.set(filterKey, filterValue); |
66 | 77 |
|
67 | | - window.location.replace(url.toString()); |
| 78 | + window.location.replace(url.toString()); |
| 79 | + } |
68 | 80 | } |
69 | | -} |
70 | 81 |
|
71 | | -function handleKeywords() { |
72 | | - const url = new URL(window.location.href); |
73 | | - const params = new URLSearchParams(url.search); |
74 | | - const keyword = this.dataset.value; |
| 82 | + function handleKeywords() { |
| 83 | + const url = new URL(window.location.href); |
| 84 | + const params = new URLSearchParams(url.search); |
| 85 | + const keyword = this.dataset.value; |
75 | 86 |
|
76 | | - if (! params.has("keywords[]", keyword)) { |
77 | | - params.append("keywords[]", keyword); |
78 | | - url.search = params.toString(); |
| 87 | + if (! params.has("keywords[]", keyword)) { |
| 88 | + params.append("keywords[]", keyword); |
| 89 | + url.search = params.toString(); |
79 | 90 |
|
80 | | - window.location.replace(url.toString()); |
| 91 | + window.location.replace(url.toString()); |
| 92 | + } |
81 | 93 | } |
82 | | -} |
83 | 94 |
|
84 | | -function removeKeyword() { |
85 | | - const url = new URL(window.location.href); |
86 | | - const params = new URLSearchParams(url.search); |
87 | | - const keyword = this.dataset.value; |
| 95 | + function removeKeyword() { |
| 96 | + const url = new URL(window.location.href); |
| 97 | + const params = new URLSearchParams(url.search); |
| 98 | + const keyword = this.dataset.value; |
88 | 99 |
|
89 | | - if (params.has("keywords[]", keyword)) { |
90 | | - params.delete("keywords[]", keyword); |
91 | | - url.search = params.toString(); |
| 100 | + if (params.has("keywords[]", keyword)) { |
| 101 | + params.delete("keywords[]", keyword); |
| 102 | + url.search = params.toString(); |
92 | 103 |
|
93 | | - window.location.replace(url.toString()); |
| 104 | + window.location.replace(url.toString()); |
| 105 | + } |
94 | 106 | } |
95 | | -} |
96 | 107 |
|
97 | | -function setSearchQuery(search) { |
98 | | - const url = new URL(window.location.href); |
| 108 | + function setSearchQuery(search) { |
| 109 | + const url = new URL(window.location.href); |
99 | 110 |
|
100 | | - url.searchParams.set('q', search); |
101 | | - window.location.replace(url.toString()); |
| 111 | + url.searchParams.set('q', search); |
| 112 | + window.location.replace(url.toString()); |
| 113 | + } |
102 | 114 | } |
0 commit comments