Added multi-tagging (#159)

Updated all scripts to deal with multiple tags, the only thing missing is to actually multi-tag all snippets retroactively.
This commit is contained in:
Angelos Chalaris
2018-01-05 14:35:43 +02:00
parent 800978d152
commit 20b018359b
7 changed files with 61 additions and 28 deletions

View File

@ -18,7 +18,7 @@
⚠️ **WARNING:** Snippets are not production ready.
You can find a package with all the snippets on [npm](https://www.npmjs.com/package/30-seconds-of-code).
You can find a package with all the snippets on [npm](https://www.npmjs.com/package/30-seconds-of-code).
```
npm install 30-seconds-of-code

View File

@ -14,13 +14,17 @@
<link rel="icon" type="image/png" href="favicon.png">
<script>
const search = (node) => {
let matchingTags = [];
Array.from(node.parentElement.parentElement.getElementsByTagName('a')).forEach(x => {
x.style.display = x.getAttribute("href").toUpperCase().indexOf(node.value.toUpperCase()) + 1 ? '' : 'none'
let data = [x.innerText.toLowerCase(), ...x.getAttribute('tags').split(',')].map(v => !!(v.indexOf(node.value.toLowerCase()) + 1));
if(data.includes(true)){
x.style.display = '';
matchingTags.push(x.getAttribute('tags').split(',')[0]);
}
else x.style.display = 'none';
});
Array.from( node.parentElement.parentElement.children )
.filter( x => !( x.tagName == 'A' && x.style.display == 'none' ) )
.forEach( ( element, index, source) => {
element.style.display = (element.tagName == 'H3' && index + 1 == source.length ? 'none' : element.tagName == 'H3' && source[index + 1].tagName == 'H3' ? 'none' : '')
Array.from(node.parentElement.parentElement.getElementsByTagName('h3')).forEach(x => {
x.style.display = matchingTags.includes(x.innerText.toLowerCase()) ? '' : 'none';
})
}
function loader() {