Hi, everybody!
I’ve been looking for posts and tutorials on how to fix it since yesterday but I didn’t find anything.
So, I hope some of you guys can help me getting this done. I’ll try to explain what I want objectively, but if you need more information, please ask me.
Here we go:
Let’s say I’ve got a card with the following tags …
…and I want to display some of them in the Back side but hide others. So I use the .replace()
method to hide those I don’t want to display (in this exemple, it was ::is_a
and DELTA::is_d
).
This is what I got:
But this is what I want:
This is the script I’m using to display the tags:
<div id="tags-container"></div>
<script>
//Vars
var tagsPresent = false;
var tags;
var tagContent = "{{Tags}}";
// Place all specified tag colors here
var tagMap = [
// "fallback" should be set to desired default color
fallback = {
name: "",
color: ""
},
];
//Calls
tags = searchTags();
checkTags(tags);
// Functions
//Find out if tags are there or not, and if so split at each word
function searchTags(){
//Check if there are any tags
if (tagContent == null || tagContent === ""){
tagsPresent = false;
} else {
// Check if there is more than one tag
if (tagContent.search(" ") >= 1){
tagsPresent = true;
tags = tagContent.split(" ");
} else {
tagsPresent = true;
var tags = [tagContent];
}
}
return tags;
}
// Loop through all tags in array and create a new div for each w/ respective color
function checkTags(tags){
if (tagsPresent) {
addTags(tags);
} else {
console.log("tags are not present");
}
}
function addTags(tags){
for (var i in tags) {
var newDiv = document.createElement("div");
newDiv.id = "tag";
newDiv.innerHTML = tags[i];
newDiv.style.display = "inline-block";
// Choose background fill
newDiv.style.backgroundColor = determineTagColor(tags[i]);
//Choose outline
newDiv.style.border = "1px solid" + determineTagColor(tags[i]);
document.getElementById("tags-container").appendChild(newDiv);
}
}
// Determine Tag Color by running through each tag
function determineTagColor(tag) {
for (var i = 0; i < tagMap.length; i++){
if (tagMap[i].name === tag){
return tagMap[i].color;
}
}
return tagMap[0].color;
}
</script>
This is the script I’m using to replace the tags and “_” with white space:
<script>
q = document.getElementById("tags-container");
q.innerHTML = q.innerHTML.replace(/\b(DELTA::is_d|::a)\b/g, ' ').replace(/\_/g, ' ');
</script>
This is the CSS for the tags:
<style>
#tag {
display: inline-block;
color: rgba(0,0,0, 0.65);
font-weight: 700;
background-color: #f0f0f0;
opacity: 1;
padding: .01em .3rem .1em .3rem;
border: solid .04rem;
border-radius: 0.1rem;
box-shadow: rgba(60, 64, 67, 0.03) 0px 1px 2px 2px, rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
font-size: .7rem;
}
</style>
Can you help me with that?