rawfeed 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,102 +0,0 @@
1
- document.addEventListener("DOMContentLoaded", () => {
2
- /* blog search open
3
- --------------------------------------------------------------------------------------------------
4
- */
5
- const btn = document.getElementById('blog-search__btn');
6
- const box = document.querySelector('.blog-search');
7
- const searchInput = document.getElementById('blog-search__input');
8
- const blogPosts = document.getElementById('posts');
9
- const searchResults = document.getElementById('blog-search__results');
10
- const searchResultsWrapper = document.getElementById('blog-search__results-wrapper');
11
- const btnSearchClean = document.getElementById('blog-search__btn-clean');
12
- const blogSeachInput = document.getElementById('blog-search__input');
13
-
14
-
15
- if (!btn || !box) return;
16
-
17
- const openSearch = () => {
18
- box.classList.add('is-open');
19
- box.style.maxHeight = box.scrollHeight + 'px';
20
- box.style.opacity = '1';
21
- box.addEventListener('transitionend', function onOpened(e) {
22
- if (e.propertyName === 'max-height') {
23
- box.style.maxHeight = 'none';
24
- box.removeEventListener('transitionend', onOpened);
25
- }
26
- });
27
- blogSeachInput.focus();
28
- };
29
-
30
- const closeSearch = () => {
31
- box.style.maxHeight = box.scrollHeight + 'px';
32
- void box.offsetHeight; // reflow force
33
- requestAnimationFrame(() => {
34
- box.style.maxHeight = '0';
35
- box.style.opacity = '0';
36
- });
37
- box.classList.remove('is-open');
38
- };
39
-
40
- btn.addEventListener('click', (e) => {
41
- e.preventDefault();
42
- // if are already in /blog/, toggle
43
- const pathname = location.pathname.replace(/\/$/, '');
44
- const isBlog = pathname === '/blog' || pathname === '/blog/index.html';
45
-
46
- if (!isBlog) {
47
- // if are on another page, go to /blog/ and open it
48
- window.location.href = '/blog/?search=open';
49
- return;
50
- }
51
-
52
- // toggle
53
- if (box.classList.contains('is-open')) {
54
- closeSearch();
55
- searchInput.value = '';
56
- blogPosts.classList.remove('disabled');
57
- searchResultsWrapper.classList.add('disabled');
58
- } else {
59
- openSearch();
60
- }
61
- });
62
-
63
- // opens automatically if arrived from another link with ?search=open
64
- const params = new URLSearchParams(location.search);
65
- if (params.get('search') === 'open') {
66
- setTimeout(openSearch, 30);
67
- }
68
-
69
- /* clean button input blog search
70
- --------------------------------------------------------------------------------------------------
71
- */
72
- function clearSearch() {
73
- blogSeachInput.value = '';
74
- blogPosts.classList.remove('disabled');
75
- searchResults.classList.add('disabled');
76
- searchResultsWrapper.classList.add('disabled');
77
- blogSeachInput.focus();
78
- }
79
- btnSearchClean.addEventListener('click', clearSearch);
80
- document.addEventListener('keydown', (e) => {
81
- if (e.key === 'Escape') {
82
- clearSearch();
83
- closeSearch();
84
- }
85
- });
86
-
87
- /* open results and close posts in search (toggle)
88
- --------------------------------------------------------------------------------------------------
89
- */
90
- searchInput.addEventListener('input', () => {
91
- if (searchInput.value.trim().length > 0) {
92
- blogPosts.classList.add('disabled');
93
- searchResults.classList.remove('disabled');
94
- searchResultsWrapper.classList.remove('disabled');
95
- } else {
96
- blogPosts.classList.remove('disabled');
97
- searchResults.classList.add('disabled');
98
- searchResultsWrapper.classList.add('disabled');
99
- }
100
- });
101
-
102
- });