-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update other files * Child select col elements * remove commented text * fix button alignment * add banner documentation * add autocomplete search to header * add search feature to ds header * fix component urls * add tag matching * add page tags for search * add button alignment text * center widget buttons * add flat polyfill
- Loading branch information
Showing
16 changed files
with
45,308 additions
and
580 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import pageData from '../data.njk.json'; | ||
|
||
const headerSearchJS = () => { | ||
const autoComplete = document.getElementById('wmndsMegaMenuSearch'); | ||
const autoCompleteSuggestions = document.getElementById('wmndsSearchSuggestions'); | ||
const pages = [ | ||
...pageData.navItems.map(navItem => { | ||
if (!navItem.subnavItems) { | ||
return navItem; | ||
} | ||
const childMenus = navItem.subnavItems.map(({ name, href, subnavItems, unlinked, tags }) => { | ||
const linkedChildMenu = !unlinked ? [{ name, href, tags, parent: navItem.name }] : []; | ||
if (!subnavItems) { | ||
return linkedChildMenu; | ||
} | ||
|
||
return [ | ||
...linkedChildMenu, | ||
subnavItems.map(grandChildItem => ({ | ||
name: grandChildItem.name, | ||
parent: name, | ||
grandparent: navItem.name, | ||
tags: grandChildItem.tags, | ||
href: grandChildItem.href | ||
})) | ||
]; | ||
}); | ||
return childMenus.flat(); | ||
}) | ||
] | ||
.flat(2) | ||
.map(menu => { | ||
const newMenu = menu; | ||
if (!menu.href) { | ||
delete newMenu.href; | ||
} | ||
if (!menu.tags) { | ||
delete newMenu.tags; | ||
} | ||
return newMenu; | ||
}); | ||
|
||
if (autoComplete) { | ||
autoComplete.addEventListener('keydown', e => { | ||
if (e.key === ' ') e.target.value = `${e.target.value} `; | ||
}); | ||
autoComplete.addEventListener('keyup', e => { | ||
const query = e.target.value; | ||
autoCompleteSuggestions.innerHTML = ''; | ||
if (query.length > 2) { | ||
const matchedPages = pages.filter(page => { | ||
let hasMatch = false; | ||
if ( | ||
page.name.toLowerCase().includes(e.target.value.toLowerCase()) || | ||
(page.parent && page.parent.toLowerCase().includes(e.target.value.toLowerCase())) || | ||
(page.grandparent && | ||
page.grandparent.toLowerCase().includes(e.target.value.toLowerCase())) || | ||
(page.tags && page.tags.toLowerCase().includes(e.target.value.toLowerCase())) | ||
) { | ||
hasMatch = true; | ||
} | ||
return hasMatch; | ||
}); | ||
|
||
if (matchedPages.length) { | ||
autoCompleteSuggestions.style.display = 'block'; | ||
matchedPages.forEach(page => { | ||
// Construct page text node | ||
const text = document.createTextNode(page.name); | ||
const suggestionText = document.createElement('strong'); | ||
suggestionText.classList.add('wmnds-col-1'); | ||
suggestionText.appendChild(text); | ||
|
||
// Construct breadcrumbs node | ||
const crumbs = document.createTextNode( | ||
`${page.grandparent ? `${page.grandparent} > ` : ''}${ | ||
page.parent ? `${page.parent} > ` : '' | ||
}${page.name}` | ||
); | ||
const suggestionCrumbs = document.createElement('span'); | ||
suggestionCrumbs.appendChild(crumbs); | ||
|
||
const url = str => str.toLowerCase().replace(' ', '-'); | ||
const suggestionHref = | ||
page.href || | ||
`/${page.grandparent ? `${url(page.grandparent)}/` : ''}${ | ||
page.parent && page.grandparent !== 'Components' ? `${url(page.parent)}/` : '' | ||
}${url(page.name)}/`; | ||
|
||
const suggestionLink = document.createElement('a'); | ||
suggestionLink.setAttribute('href', suggestionHref); | ||
suggestionLink.setAttribute('tabindex', '0'); | ||
suggestionLink.classList.add('wmnds-autocomplete-suggestions__li', 'wmnds-col-1'); | ||
suggestionLink.appendChild(suggestionText); | ||
suggestionLink.appendChild(suggestionCrumbs); | ||
|
||
autoCompleteSuggestions.appendChild(suggestionLink); | ||
}); | ||
} else { | ||
autoCompleteSuggestions.style.display = 'none'; | ||
} | ||
} else { | ||
autoCompleteSuggestions.style.display = 'none'; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export default headerSearchJS; |
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
Oops, something went wrong.