Tag creation for approved users

This commit is contained in:
mid
2024-07-18 22:53:44 +03:00
parent bccc0ef742
commit 61fd417013
8 changed files with 213 additions and 34 deletions

View File

@@ -11,6 +11,7 @@ div.tagbox {
user-select: contain;
padding: 0.4em;
border-radius: 3px;
box-sizing: border-box;
}
div.tagbox::after {
content: "penis";
@@ -113,6 +114,7 @@ input[type='text'], input[type='number'] {
border: 1px solid gray;
border-radius: 3px;
font-size: 1em;
box-sizing: border-box;
}
input::placeholder {
color: #C0C0C0;
@@ -125,6 +127,7 @@ ul.over18 {
padding: 0 0.4em 0 0.4em;
width: 100%;
text-align: center;
box-sizing: border-box;
}
ul.over18 label {
cursor: pointer;
@@ -210,4 +213,27 @@ footer {
margin-top: 2em;
width: 100%;
text-align: center;
}
}
div.tag.tcNew::before {
content: "New";
}
div#newtagsform {
position: fixed;
width: 50vw;
height: 50vh;
top: 25vh;
left: 25vw;
background: white;
border: 1px solid black;
padding: 1em;
}
div#newtagsform select {
border: 0;
}
.hidden {
visibility: hidden;
}

View File

@@ -1,13 +1,28 @@
function createtag(name, tc, tagid) {
var newtag = document.createElement("div")
newtag.classList.toggle("tag")
newtag.classList.toggle("tc" + (tc || "New"))
if(tagid) {
newtag.setAttribute("data-tagid", tagid)
}
newtag.innerText = name
return newtag
}
var acTimer;
document.getElementById(document.querySelector("div.tagbox").getAttribute("data-formid")).addEventListener("submit", function(ev) {
function tagbox_updateformdata() {
document.getElementById(document.querySelector("div.tagbox").getAttribute("data-formparaminputid")).value = Array.from(document.querySelectorAll("div.tagbox div.tag")).map(function(a) {return a.getAttribute("data-tagid")}).join(",")
})
}
document.getElementById(document.querySelector("div.tagbox").getAttribute("data-formid")).addEventListener("submit", tagbox_updateformdata)
document.querySelector("div.tagbox").onclick = function(ev) {
this.querySelector('span').focus()
}
var UnknownTagsMode = document.querySelector("div.tagbox").getAttribute("data-unknowntags") !== null
document.querySelector("div.tagbox span").onkeydown = function(ev) {
if(ev.keyCode == 13) {
ev.preventDefault()
@@ -15,16 +30,18 @@ document.querySelector("div.tagbox span").onkeydown = function(ev) {
if(document.querySelector("div.tagbox span").innerText.length) {
var from = document.querySelector("div.autocomplete > div.tag.selected") || document.querySelectorAll("div.autocomplete > div.tag")[0]
if(!document.querySelector("div.tagbox div.tag[data-tagid='"+from.getAttribute("data-tagid")+"']")) {
from.classList.remove("selected")
document.querySelector("div.tagbox span").innerText = ""
document.querySelector("div.tagbox").insertBefore(from, document.querySelector("div.tagbox span"))
document.querySelector("div.tagbox").insertBefore(document.createTextNode("\n"), document.querySelector("div.tagbox span"))
var ac = document.querySelector(".autocomplete")
ac.style.visibility = "hidden"
if(from) {
if(!document.querySelector("div.tagbox div.tag[data-tagid='"+from.getAttribute("data-tagid")+"']")) {
from.classList.remove("selected")
document.querySelector("div.tagbox").insertBefore(from, document.querySelector("div.tagbox span"))
document.querySelector("div.tagbox").insertBefore(document.createTextNode("\n"), document.querySelector("div.tagbox span"))
}
}
document.querySelector("div.tagbox span").innerText = ""
var ac = document.querySelector(".autocomplete")
ac.style.visibility = "hidden"
} else {
document.getElementById(document.querySelector("div.tagbox").getAttribute("data-formid")).querySelector("input[type='submit']").click()
}
@@ -75,16 +92,17 @@ document.querySelector("div.tagbox span").oninput = function(ev) {
var ac = document.querySelector(".autocomplete")
ac.style.visibility = ""
while(ac.firstChild) ac.removeChild(ac.firstChild)
if(ajax.responseText == "") {
if(!UnknownTagsMode && ajax.responseText == "") {
ac.innerText = "No such tags found"
} else ajax.responseText.split("\n").slice(0, -1).forEach(function(line) {
var newtag = document.createElement("div")
newtag.classList.toggle("tag")
newtag.classList.toggle("tc" + line.split(",")[2])
newtag.setAttribute("data-tagid", line.split(",")[0])
newtag.innerText = line.split(",")[1]
ac.insertBefore(newtag, null)
})
} else {
ajax.responseText.split("\n").slice(0, -1).forEach(function(line) {
ac.insertBefore(createtag(line.split(",")[1], line.split(",")[2], line.split(",")[0]), null)
})
if(UnknownTagsMode) {
ac.insertBefore(createtag(document.querySelector("div.tagbox span").innerText, null, null), null);
}
}
}
}
ajax.send()
@@ -97,4 +115,4 @@ document.querySelector("div.tagbox span").oninput = function(ev) {
clearTimeout(acTimer)
acTimer = undefined
}
}
}