Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6286033

Browse files
imklaujedrzejchalubek
authored andcommitted
feat(): Introduce search bar for 404 page (#129)
1 parent4d8acd9 commit6286033

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

‎js/index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dropdownMenu from './dropdown-menu'
1010
importanchorsIndicatorfrom'./anchors-indicator'
1111
importcodeExamplefrom'./code-example'
1212
importpopoverfrom'./popover'
13+
importsearchBar404from'./search-bar-404'
1314

1415
feedback()
1516
accordion()
@@ -21,3 +22,4 @@ dropdownMenu()
2122
anchorsIndicator()
2223
codeExample()
2324
popover()
25+
searchBar404()

‎js/popover/index.js‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ const COMPONENT_SELECTOR = `[${COMPONENT_NAME}]`
33
constBODY_SELECTOR='data-popover-body'
44
constTRIGGER_SELECTOR='[data-popover-target]'
55

6-
constcomponents=document.querySelectorAll(COMPONENT_SELECTOR)
6+
exportdefaultfunction(){
7+
constcomponents=document.querySelectorAll(COMPONENT_SELECTOR)
78

8-
for(leti=0;i<components.length;i++){
9-
consttriggers=components[i].querySelectorAll(TRIGGER_SELECTOR)
9+
for(leti=0;i<components.length;i++){
10+
consttriggers=components[i].querySelectorAll(TRIGGER_SELECTOR)
1011

11-
for(leti=0;i<triggers.length;i++){
12-
triggers[i].addEventListener('click',e=>{
13-
e.preventDefault()
12+
for(leti=0;i<triggers.length;i++){
13+
triggers[i].addEventListener('click',e=>{
14+
e.preventDefault()
1415

15-
consttargetBody=document.querySelector(`[${BODY_SELECTOR}=${e.target.dataset.popoverTarget}]`)
16+
consttargetBody=document.querySelector(`[${BODY_SELECTOR}=${e.target.dataset.popoverTarget}]`)
1617

17-
components[i].classList.toggle(components[i].dataset.activeClass)
18-
})
19-
}
18+
components[i].classList.toggle(components[i].dataset.activeClass)
19+
})
20+
}
2021

21-
document.addEventListener('click',e=>{
22-
if(components[i].classList.contains(components[i].dataset.activeClass)){
23-
constpopoverBody=components[i].querySelector(`[${BODY_SELECTOR}]`)
22+
document.addEventListener('click',e=>{
23+
if(components[i].classList.contains(components[i].dataset.activeClass)){
24+
constpopoverBody=components[i].querySelector(`[${BODY_SELECTOR}]`)
2425

25-
for(leti=0;i<triggers.length;i++){
26-
if(!popoverBody.contains(e.target)&&e.target!==triggers[i]){
27-
components[i].classList.remove(components[i].dataset.activeClass)
26+
for(leti=0;i<triggers.length;i++){
27+
if(!popoverBody.contains(e.target)&&e.target!==triggers[i]){
28+
components[i].classList.remove(components[i].dataset.activeClass)
29+
}
2830
}
2931
}
30-
}
31-
})
32+
})
33+
}
3234
}

‎js/search-bar-404/index.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
constCOMPONENT_NAME='data-search'
2+
constCOMPONENT_SELECTOR=`[${COMPONENT_NAME}]`
3+
4+
exportdefaultfunction(){
5+
constsearch=document.querySelectorAll(COMPONENT_SELECTOR)
6+
constpathParts=window.location.pathname.split("/")
7+
constsearchWord=pathParts[pathParts.length-1]
8+
9+
for(leti=0;i<search.length;i++){
10+
constinput=search[i].querySelector('input')
11+
input.value=searchWord
12+
}
13+
}

‎src/404.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1>The page you were looking for doesn’t exist.</h1>
2424
<divclass="flex__column--10 markdown">
2525
<p>You may have mistyped the address or the page may have moved. Double-check the URL and try again or search the term.</p>
2626

27-
<divclass="search">
27+
<divclass="search"data-search>
2828
{% include navbar/search.html placeholder="Enter a search term" %}
2929
</div>
3030
</div>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp