mirror of
https://github.com/placeAtlas/atlas.git
synced 2025-01-16 00:07:08 +01:00
Simplify by using shared elements
This commit is contained in:
parent
b2f287180c
commit
5d21513263
2 changed files with 19 additions and 27 deletions
|
@ -13,6 +13,11 @@
|
||||||
========================================================================
|
========================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const baseLinkElement = document.createElement("a")
|
||||||
|
baseLinkElement.className = "btn btn-primary text-truncate"
|
||||||
|
baseLinkElement.target = "_blank"
|
||||||
|
baseLinkElement.rel = "noopener noreferrer"
|
||||||
|
|
||||||
function createLabel(name, value, parent) {
|
function createLabel(name, value, parent) {
|
||||||
const nameElement = document.createElement("span")
|
const nameElement = document.createElement("span")
|
||||||
nameElement.className = "fw-bold"
|
nameElement.className = "fw-bold"
|
||||||
|
@ -107,10 +112,7 @@ function createInfoBlock(entry, isPreview) {
|
||||||
entry.links.subreddit.forEach(subreddit => {
|
entry.links.subreddit.forEach(subreddit => {
|
||||||
if (subreddit) {
|
if (subreddit) {
|
||||||
subreddit = "r/" + subreddit
|
subreddit = "r/" + subreddit
|
||||||
const subredditLinkElement = document.createElement("a")
|
const subredditLinkElement = baseLinkElement.cloneNode()
|
||||||
subredditLinkElement.className = "btn btn-primary text-truncate"
|
|
||||||
subredditLinkElement.target = "_blank"
|
|
||||||
subredditLinkElement.rel = "noopener noreferrer"
|
|
||||||
subredditLinkElement.href = "https://reddit.com/" + subreddit
|
subredditLinkElement.href = "https://reddit.com/" + subreddit
|
||||||
subredditLinkElement.innerHTML = `<i class="bi bi-reddit" aria-hidden="true"></i> ${subreddit}`
|
subredditLinkElement.innerHTML = `<i class="bi bi-reddit" aria-hidden="true"></i> ${subreddit}`
|
||||||
subredditGroupElement.appendChild(subredditLinkElement)
|
subredditGroupElement.appendChild(subredditLinkElement)
|
||||||
|
@ -125,10 +127,7 @@ function createInfoBlock(entry, isPreview) {
|
||||||
|
|
||||||
entry.links.website.forEach(link => {
|
entry.links.website.forEach(link => {
|
||||||
if (link) {
|
if (link) {
|
||||||
const websiteLinkElement = document.createElement("a")
|
const websiteLinkElement = baseLinkElement.cloneNode()
|
||||||
websiteLinkElement.className = "btn btn-primary text-truncate"
|
|
||||||
websiteLinkElement.target = "_blank"
|
|
||||||
websiteLinkElement.rel = "noopener noreferrer"
|
|
||||||
websiteLinkElement.href = link
|
websiteLinkElement.href = link
|
||||||
try {
|
try {
|
||||||
const urlObject = new URL(link)
|
const urlObject = new URL(link)
|
||||||
|
@ -148,10 +147,7 @@ function createInfoBlock(entry, isPreview) {
|
||||||
|
|
||||||
entry.links.discord.forEach(link => {
|
entry.links.discord.forEach(link => {
|
||||||
if (link) {
|
if (link) {
|
||||||
const discordLinkElement = document.createElement("a")
|
const discordLinkElement = baseLinkElement.cloneNode()
|
||||||
discordLinkElement.className = "btn btn-primary text-truncate"
|
|
||||||
discordLinkElement.target = "_blank"
|
|
||||||
discordLinkElement.rel = "noopener noreferrer"
|
|
||||||
discordLinkElement.href = "https://discord.gg/" + link
|
discordLinkElement.href = "https://discord.gg/" + link
|
||||||
discordLinkElement.innerHTML = `<i class="bi bi-discord" aria-hidden="true"></i> ${link}`
|
discordLinkElement.innerHTML = `<i class="bi bi-discord" aria-hidden="true"></i> ${link}`
|
||||||
discordGroupElement.appendChild(discordLinkElement)
|
discordGroupElement.appendChild(discordLinkElement)
|
||||||
|
@ -166,10 +162,7 @@ function createInfoBlock(entry, isPreview) {
|
||||||
|
|
||||||
entry.links.wiki.forEach(link => {
|
entry.links.wiki.forEach(link => {
|
||||||
if (link) {
|
if (link) {
|
||||||
const wikiLinkElement = document.createElement("a")
|
const wikiLinkElement = baseLinkElement.cloneNode()
|
||||||
wikiLinkElement.className = "btn btn-primary text-truncate"
|
|
||||||
wikiLinkElement.target = "_blank"
|
|
||||||
wikiLinkElement.rel = "noopener noreferrer"
|
|
||||||
wikiLinkElement.href = "https://place-wiki.stefanocoding.me/wiki/" + link.replace(/ /g, '_')
|
wikiLinkElement.href = "https://place-wiki.stefanocoding.me/wiki/" + link.replace(/ /g, '_')
|
||||||
wikiLinkElement.innerHTML = `<i class="bi bi-book" aria-hidden="true"></i> Wiki Article`
|
wikiLinkElement.innerHTML = `<i class="bi bi-book" aria-hidden="true"></i> Wiki Article`
|
||||||
wikiGroupElement.appendChild(wikiLinkElement)
|
wikiGroupElement.appendChild(wikiLinkElement)
|
||||||
|
|
|
@ -45,6 +45,12 @@ const entriesList = document.getElementById("entriesList")
|
||||||
|
|
||||||
let entriesListShown = false
|
let entriesListShown = false
|
||||||
|
|
||||||
|
const drawButton = document.getElementById("drawLink")
|
||||||
|
const objectEditNav = document.createElement("a")
|
||||||
|
objectEditNav.className = "btn btn-outline-primary"
|
||||||
|
objectEditNav.id = "objectEditNav"
|
||||||
|
objectEditNav.innerText = "Edit"
|
||||||
|
|
||||||
let sortedAtlas
|
let sortedAtlas
|
||||||
|
|
||||||
const entriesLimit = 50
|
const entriesLimit = 50
|
||||||
|
@ -796,20 +802,13 @@ function highlightEntryFromUrl() {
|
||||||
document.title = entry.name + " on the 2022 r/place Atlas"
|
document.title = entry.name + " on the 2022 r/place Atlas"
|
||||||
|
|
||||||
if ((!entry.diff || entry.diff !== "delete")) {
|
if ((!entry.diff || entry.diff !== "delete")) {
|
||||||
if (document.getElementById("objectEditNav")) {
|
objectEditNav.href = "./?mode=draw&id=" + id
|
||||||
document.getElementById("objectEditNav").href = "./?mode=draw&id=" + id
|
objectEditNav.title = "Edit " + entry.name
|
||||||
document.getElementById("objectEditNav").title = "Edit " + entry.name
|
if (!objectEditNav.isConnected) {
|
||||||
} else {
|
|
||||||
const objectEditNav = document.createElement("a")
|
|
||||||
objectEditNav.className = "btn btn-outline-primary"
|
|
||||||
objectEditNav.id = "objectEditNav"
|
|
||||||
objectEditNav.innerText = "Edit"
|
|
||||||
objectEditNav.href = "./?mode=draw&id=" + id
|
|
||||||
objectEditNav.title = "Edit " + entry.name
|
|
||||||
showListButton.parentElement.appendChild(objectEditNav)
|
showListButton.parentElement.appendChild(objectEditNav)
|
||||||
}
|
}
|
||||||
} else if (entry.diff === "delete" && document.getElementById("objectEditNav")) {
|
} else if (entry.diff === "delete" && document.getElementById("objectEditNav")) {
|
||||||
document.getElementById("objectEditNav").remove()
|
objectEditNav.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
const infoElement = createInfoBlock(entry)
|
const infoElement = createInfoBlock(entry)
|
||||||
|
|
Loading…
Reference in a new issue