|
|
@ -2,8 +2,25 @@ let tagroot = document.querySelector('article.tags')
|
|
|
|
let sel_tags = tagroot.querySelector('div.tag_container.tags_selected')
|
|
|
|
let sel_tags = tagroot.querySelector('div.tag_container.tags_selected')
|
|
|
|
let page_tags = tagroot.querySelector('div.tag_container.tags_inpage')
|
|
|
|
let page_tags = tagroot.querySelector('div.tag_container.tags_inpage')
|
|
|
|
|
|
|
|
|
|
|
|
let search_input = tagroot.querySelector('.searchbox > input[name=tagsearch]')
|
|
|
|
let searchroot = tagroot.querySelector('.searchbox')
|
|
|
|
let search_dropdown = tagroot.querySelector('.searchbox > .search_dropdown')
|
|
|
|
searchroot.insertAdjacentHTML("beforeend", `<input type="hidden" name="tags">`)
|
|
|
|
|
|
|
|
let search_input = searchroot.querySelector('input[name=tags][type=text]')
|
|
|
|
|
|
|
|
search_input.removeAttribute('name')
|
|
|
|
|
|
|
|
search_input.value = ''
|
|
|
|
|
|
|
|
let search_hidden = document.querySelector('input[name=tags][type=hidden]')
|
|
|
|
|
|
|
|
let search_dropdown = searchroot.querySelector('.search_dropdown')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
|
|
|
|
|
|
|
|
function getJsonFromUrl(url) {
|
|
|
|
|
|
|
|
if(!url) url = location.search;
|
|
|
|
|
|
|
|
var query = url.substr(1);
|
|
|
|
|
|
|
|
var result = {};
|
|
|
|
|
|
|
|
query.split("&").forEach(function(part) {
|
|
|
|
|
|
|
|
var item = part.split("=");
|
|
|
|
|
|
|
|
result[item[0]] = decodeURIComponent(item[1]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function newseltag(tagname) {
|
|
|
|
function newseltag(tagname) {
|
|
|
|
let tag = document.createElement("a")
|
|
|
|
let tag = document.createElement("a")
|
|
|
@ -16,8 +33,23 @@ function newseltag(tagname) {
|
|
|
|
<span class="fa fa-close close"></span>
|
|
|
|
<span class="fa fa-close close"></span>
|
|
|
|
`)
|
|
|
|
`)
|
|
|
|
tag.querySelector("span.name").textContent = tagname.replace(/_/g, ' ')
|
|
|
|
tag.querySelector("span.name").textContent = tagname.replace(/_/g, ' ')
|
|
|
|
|
|
|
|
// tag.querySelector("input[type=hidden]").setAttribute('name', `tag#${tagname}`)
|
|
|
|
return tag
|
|
|
|
return tag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tags_input_addtag(tagname) {
|
|
|
|
|
|
|
|
let val = search_hidden.value.split(' ')
|
|
|
|
|
|
|
|
val.push(tagname)
|
|
|
|
|
|
|
|
search_hidden.value = val.join(' ').trim()
|
|
|
|
|
|
|
|
// console.log(search_hidden.value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function tags_input_removetag(tagname) {
|
|
|
|
|
|
|
|
let val = search_hidden.value.split(' ')
|
|
|
|
|
|
|
|
val.splice(val.indexOf(tagname), 1)
|
|
|
|
|
|
|
|
search_hidden.value = val.join(' ').trim()
|
|
|
|
|
|
|
|
// console.log(search_hidden.value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addseltag(tagname) {
|
|
|
|
function addseltag(tagname) {
|
|
|
|
// let pagetag = page_tags.querySelector("a.tag-"+tagname)
|
|
|
|
// let pagetag = page_tags.querySelector("a.tag-"+tagname)
|
|
|
|
let pagetag = page_tags.querySelector(`a[data-tagname=${tagname}]`)
|
|
|
|
let pagetag = page_tags.querySelector(`a[data-tagname=${tagname}]`)
|
|
|
@ -27,25 +59,37 @@ function addseltag(tagname) {
|
|
|
|
let newtag = newseltag(tagname)
|
|
|
|
let newtag = newseltag(tagname)
|
|
|
|
newtag.addEventListener('click', (event) => {
|
|
|
|
newtag.addEventListener('click', (event) => {
|
|
|
|
removeseltag(event.target.dataset.tagname)
|
|
|
|
removeseltag(event.target.dataset.tagname)
|
|
|
|
console.log(`Deselected: ${event.target.dataset.tagname}`)
|
|
|
|
// console.log(`Deselected: ${event.target.dataset.tagname}`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
sel_tags.appendChild(newtag)
|
|
|
|
sel_tags.appendChild(newtag)
|
|
|
|
|
|
|
|
tags_input_addtag(tagname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function removeseltag(tagname) {
|
|
|
|
function removeseltag(tagname) {
|
|
|
|
let pagetag = page_tags.querySelector(`a[data-tagname=${tagname}]`)
|
|
|
|
let pagetag = page_tags.querySelector(`a[data-tagname=${tagname}]`)
|
|
|
|
if (pagetag) {
|
|
|
|
if (pagetag) {
|
|
|
|
pagetag.classList.remove('tag_hide')
|
|
|
|
pagetag.classList.remove('tag_hide')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sel_tags.querySelector(`a[data-tagname=${tagname}]`).remove()
|
|
|
|
sel_tags.querySelector(`a[data-tagname=${tagname}]`).remove()
|
|
|
|
|
|
|
|
tags_input_removetag(tagname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page_tags.querySelectorAll("a").forEach(element => {
|
|
|
|
page_tags.querySelectorAll("a").forEach(element => {
|
|
|
|
element.addEventListener('click', (event) => {
|
|
|
|
element.addEventListener('click', (event) => {
|
|
|
|
addseltag(event.target.dataset.tagname)
|
|
|
|
addseltag(event.target.dataset.tagname)
|
|
|
|
console.log(`Selected: ${event.target.dataset.tagname}`)
|
|
|
|
// console.log(`Selected: ${event.target.dataset.tagname}`)
|
|
|
|
event.preventDefault()
|
|
|
|
event.preventDefault()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let query = getJsonFromUrl()
|
|
|
|
|
|
|
|
if (query['tags']) {
|
|
|
|
|
|
|
|
query['tags'].split('+').forEach((tag) => {
|
|
|
|
|
|
|
|
addseltag(tag)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Suggestions
|
|
|
|
function newsugtag(tagname) {
|
|
|
|
function newsugtag(tagname) {
|
|
|
|
let tag = document.createElement("a")
|
|
|
|
let tag = document.createElement("a")
|
|
|
|
tag.classList.add("tagsuggestion")
|
|
|
|
tag.classList.add("tagsuggestion")
|
|
|
@ -77,13 +121,19 @@ function rendersuggestions(data) {
|
|
|
|
search_dropdown.appendChild(sugtag)
|
|
|
|
search_dropdown.appendChild(sugtag)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var search_timeout
|
|
|
|
var search_timeout
|
|
|
|
search_input.addEventListener('input', (event) => {
|
|
|
|
search_input.addEventListener('input', (event) => {
|
|
|
|
clearTimeout(search_timeout)
|
|
|
|
clearTimeout(search_timeout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let value = search_input.value.trim()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value.length < 2) {
|
|
|
|
|
|
|
|
rendersuggestions([])
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
search_timeout = setTimeout(() => {
|
|
|
|
search_timeout = setTimeout(() => {
|
|
|
|
fetch('/api/tags?q='+search_input.value).then((response) => {
|
|
|
|
fetch('/api/tags?q='+value).then((response) => {
|
|
|
|
console.log(response)
|
|
|
|
console.log(response)
|
|
|
|
return response.json()
|
|
|
|
return response.json()
|
|
|
|
}).then((data) => {
|
|
|
|
}).then((data) => {
|
|
|
@ -94,11 +144,22 @@ search_input.addEventListener('input', (event) => {
|
|
|
|
}, 500)
|
|
|
|
}, 500)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
search_input.addEventListener('keypress', (event) => {
|
|
|
|
// search_input.addEventListener('keypress', (event) => {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
// if (event.keyCode == 13) {
|
|
|
|
event.preventDefault()
|
|
|
|
// // event.preventDefault()
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
|
|
|
|
// search_input.addEventListener('blur', (event) => {
|
|
|
|
|
|
|
|
// if (event.explicitOriginalTarget != null) {
|
|
|
|
|
|
|
|
// classlist = event.explicitOriginalTarget.parentNode.classList
|
|
|
|
|
|
|
|
// if (classlist.contains('tags_selected') || classlist.contains('tags_inpage') || classlist.contains('search_dropdown')) {
|
|
|
|
|
|
|
|
// setTimeout(() => search_input.focus(), 2)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// console.log(event)
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// page_tags.querySelectorAll('a').forEach((el) => el.removeAttribute('href'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(page_tags)
|
|
|
|
// console.log(page_tags)
|
|
|
|
// console.log(sel_tags)
|
|
|
|
// console.log(sel_tags)
|
|
|
|