2022-10-18 18:58:04 +02:00
|
|
|
let activeTags = []
|
|
|
|
let modifiers = []
|
2022-10-21 10:38:16 +02:00
|
|
|
let customModifiersGroupElement = undefined
|
2023-06-19 16:24:31 +02:00
|
|
|
let customModifiersInitialContent = ""
|
|
|
|
let modifierPanelFreezed = false
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
let modifiersMainContainer = document.querySelector("#editor-modifiers")
|
|
|
|
let modifierDropdown = document.querySelector("#image-modifier-dropdown")
|
|
|
|
let editorModifiersContainer = document.querySelector("#editor-modifiers")
|
2023-04-27 19:56:56 +02:00
|
|
|
let editorModifierEntries = document.querySelector("#editor-modifiers-entries")
|
|
|
|
let editorModifierTagsList = document.querySelector("#editor-inputs-tags-list")
|
|
|
|
let editorTagsContainer = document.querySelector("#editor-inputs-tags-container")
|
|
|
|
let modifierCardSizeSlider = document.querySelector("#modifier-card-size-slider")
|
|
|
|
let previewImageField = document.querySelector("#preview-image")
|
|
|
|
let modifierSettingsBtn = document.querySelector("#modifier-settings-btn")
|
2023-06-19 16:24:31 +02:00
|
|
|
let modifiersContainerSizeBtn = document.querySelector("#modifiers-container-size-btn")
|
|
|
|
let modifiersCloseBtn = document.querySelector("#modifiers-close-button")
|
|
|
|
let modifiersCollapsiblesBtn = document.querySelector("#modifiers-action-collapsibles-btn")
|
2023-06-27 00:00:27 +02:00
|
|
|
let modifierSettingsDialog = document.querySelector("#modifier-settings-config")
|
2023-04-27 19:56:56 +02:00
|
|
|
let customModifiersTextBox = document.querySelector("#custom-modifiers-input")
|
|
|
|
let customModifierEntriesToolbar = document.querySelector("#editor-modifiers-entries-toolbar")
|
2023-06-27 00:00:27 +02:00
|
|
|
let modifierSettingsCloseBtn = document.querySelector("#modifier-settings-close-button")
|
2023-04-27 19:56:56 +02:00
|
|
|
|
|
|
|
const modifierThumbnailPath = "media/modifier-thumbnails"
|
|
|
|
const activeCardClass = "modifier-card-active"
|
2022-10-21 10:38:16 +02:00
|
|
|
const CUSTOM_MODIFIERS_KEY = "customModifiers"
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-01-17 08:56:44 +01:00
|
|
|
function createModifierCard(name, previews, removeBy) {
|
2023-06-19 16:24:31 +02:00
|
|
|
let cardPreviewImageType = previewImageField.value
|
2023-03-10 21:23:16 +01:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
const modifierCard = document.createElement("div")
|
2023-04-27 19:56:56 +02:00
|
|
|
modifierCard.className = "modifier-card"
|
2022-10-18 18:58:04 +02:00
|
|
|
modifierCard.innerHTML = `
|
|
|
|
<div class="modifier-card-overlay"></div>
|
|
|
|
<div class="modifier-card-image-container">
|
|
|
|
<div class="modifier-card-image-overlay">+</div>
|
2023-06-19 16:24:31 +02:00
|
|
|
<p class="modifier-card-error-label">No Image</p>
|
2022-10-18 18:58:04 +02:00
|
|
|
<img onerror="this.remove()" alt="Modifier Image" class="modifier-card-image">
|
|
|
|
</div>
|
|
|
|
<div class="modifier-card-container">
|
2023-06-19 16:24:31 +02:00
|
|
|
<div class="modifier-card-label">
|
|
|
|
<span class="long-label hidden"></span>
|
|
|
|
<p class="regular-label"></p>
|
|
|
|
</div>
|
2022-10-18 18:58:04 +02:00
|
|
|
</div>`
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
const image = modifierCard.querySelector(".modifier-card-image")
|
2023-06-19 16:24:31 +02:00
|
|
|
const longLabel = modifierCard.querySelector(".modifier-card-label span.long-label")
|
|
|
|
const regularLabel = modifierCard.querySelector(".modifier-card-label p.regular-label")
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (typeof previews == "object") {
|
2023-06-19 16:24:31 +02:00
|
|
|
image.src = previews[cardPreviewImageType == "portrait" ? 0 : 1] // 0 index is portrait, 1 landscape
|
|
|
|
image.setAttribute("preview-type", cardPreviewImageType)
|
2022-10-18 18:58:04 +02:00
|
|
|
} else {
|
|
|
|
image.remove()
|
|
|
|
}
|
|
|
|
|
|
|
|
const maxLabelLength = 30
|
2023-04-27 19:56:56 +02:00
|
|
|
const cardLabel = removeBy ? name.replace("by ", "") : name
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
function getFormattedLabel(length) {
|
|
|
|
if (cardLabel?.length <= length) {
|
|
|
|
return cardLabel
|
|
|
|
} else {
|
|
|
|
return cardLabel.substring(0, length) + "..."
|
|
|
|
}
|
|
|
|
}
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
modifierCard.dataset.fullName = name // preserve the full name
|
|
|
|
regularLabel.dataset.fullName = name // preserve the full name, legacy support for older plugins
|
|
|
|
|
|
|
|
longLabel.innerText = getFormattedLabel(maxLabelLength * 2)
|
|
|
|
regularLabel.innerText = getFormattedLabel(maxLabelLength)
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
if (cardLabel.length > maxLabelLength) {
|
|
|
|
modifierCard.classList.add("support-long-label")
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
if (cardLabel.length > maxLabelLength * 2) {
|
|
|
|
modifierCard.title = `"${name}"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
return modifierCard
|
|
|
|
}
|
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
function createModifierGroup(modifierGroup, isInitiallyOpen, removeBy) {
|
2022-10-21 10:38:16 +02:00
|
|
|
const title = modifierGroup.category
|
|
|
|
const modifiers = modifierGroup.modifiers
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
const titleEl = document.createElement("h5")
|
|
|
|
titleEl.className = "collapsible"
|
2022-10-21 10:38:16 +02:00
|
|
|
titleEl.innerText = title
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
const modifiersEl = document.createElement("div")
|
|
|
|
modifiersEl.classList.add("collapsible-content", "editor-modifiers-leaf")
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
if (isInitiallyOpen === true) {
|
|
|
|
titleEl.classList.add("active")
|
2022-10-21 10:38:16 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
modifiers.forEach((modObj) => {
|
2022-10-21 10:38:16 +02:00
|
|
|
const modifierName = modObj.modifier
|
2023-04-27 19:56:56 +02:00
|
|
|
const modifierPreviews = modObj?.previews?.map(
|
|
|
|
(preview) =>
|
|
|
|
`${IMAGE_REGEX.test(preview.image) ? preview.image : modifierThumbnailPath + "/" + preview.path}`
|
|
|
|
)
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-01-17 08:56:44 +01:00
|
|
|
const modifierCard = createModifierCard(modifierName, modifierPreviews, removeBy)
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (typeof modifierCard == "object") {
|
2022-10-21 10:38:16 +02:00
|
|
|
modifiersEl.appendChild(modifierCard)
|
2022-11-30 12:02:43 +01:00
|
|
|
const trimmedName = trimModifiers(modifierName)
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
modifierCard.addEventListener("click", () => {
|
|
|
|
if (activeTags.map((x) => trimModifiers(x.name)).includes(trimmedName)) {
|
2022-10-21 10:38:16 +02:00
|
|
|
// remove modifier from active array
|
2023-04-27 19:56:56 +02:00
|
|
|
activeTags = activeTags.filter((x) => trimModifiers(x.name) != trimmedName)
|
2022-12-01 07:13:13 +01:00
|
|
|
toggleCardState(trimmedName, false)
|
2022-10-21 10:38:16 +02:00
|
|
|
} else {
|
|
|
|
// add modifier to active array
|
|
|
|
activeTags.push({
|
2023-04-27 19:56:56 +02:00
|
|
|
name: modifierName,
|
|
|
|
element: modifierCard.cloneNode(true),
|
|
|
|
originElement: modifierCard,
|
2023-04-28 12:20:44 +02:00
|
|
|
previews: modifierPreviews,
|
2022-10-21 10:38:16 +02:00
|
|
|
})
|
2022-12-01 07:13:13 +01:00
|
|
|
toggleCardState(trimmedName, true)
|
2022-10-21 10:38:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshTagsList()
|
2023-04-27 19:56:56 +02:00
|
|
|
document.dispatchEvent(new Event("refreshImageModifiers"))
|
2022-10-21 10:38:16 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
let brk = document.createElement("br")
|
|
|
|
brk.style.clear = "both"
|
2022-10-21 10:38:16 +02:00
|
|
|
modifiersEl.appendChild(brk)
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
let e = document.createElement("div")
|
|
|
|
e.className = "modifier-category"
|
2022-10-21 10:38:16 +02:00
|
|
|
e.appendChild(titleEl)
|
|
|
|
e.appendChild(modifiersEl)
|
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
editorModifierEntries.prepend(e)
|
2022-10-21 10:38:16 +02:00
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2022-11-27 12:00:19 +01:00
|
|
|
function trimModifiers(tag) {
|
2023-03-28 12:05:51 +02:00
|
|
|
// Remove trailing '-' and/or '+'
|
2023-04-27 19:56:56 +02:00
|
|
|
tag = tag.replace(/[-+]+$/, "")
|
2023-03-28 12:05:51 +02:00
|
|
|
// Remove parentheses at beginning and end
|
2023-04-27 19:56:56 +02:00
|
|
|
return tag.replace(/^[(]+|[\s)]+$/g, "")
|
2022-11-27 12:00:19 +01:00
|
|
|
}
|
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
async function loadModifiers() {
|
|
|
|
try {
|
2023-04-27 19:56:56 +02:00
|
|
|
let res = await fetch("/get/modifiers")
|
2022-10-18 18:58:04 +02:00
|
|
|
if (res.status === 200) {
|
|
|
|
res = await res.json()
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
modifiers = res // update global variable
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2022-10-21 10:38:16 +02:00
|
|
|
res.reverse()
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2022-10-21 10:38:16 +02:00
|
|
|
res.forEach((modifierGroup, idx) => {
|
2023-06-19 16:24:31 +02:00
|
|
|
const isInitiallyOpen = false // idx === res.length - 1
|
|
|
|
const removeBy = modifierGroup === "Artist" ? true : false // only remove "By " for artists
|
|
|
|
|
|
|
|
createModifierGroup(modifierGroup, isInitiallyOpen, removeBy)
|
2022-10-18 18:58:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
createCollapsibles(editorModifierEntries)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-04-27 19:56:56 +02:00
|
|
|
console.error("error fetching modifiers", e)
|
2022-10-18 18:58:04 +02:00
|
|
|
}
|
2022-10-21 10:38:16 +02:00
|
|
|
|
|
|
|
loadCustomModifiers()
|
2023-03-14 19:02:34 +01:00
|
|
|
resizeModifierCards(modifierCardSizeSlider.value)
|
2023-04-27 19:56:56 +02:00
|
|
|
document.dispatchEvent(new Event("loadImageModifiers"))
|
2022-10-18 18:58:04 +02:00
|
|
|
}
|
|
|
|
|
2023-03-25 10:09:11 +01:00
|
|
|
function refreshModifiersState(newTags, inactiveTags) {
|
2022-11-11 03:36:39 +01:00
|
|
|
// clear existing modifiers
|
2023-04-27 19:56:56 +02:00
|
|
|
document
|
|
|
|
.querySelector("#editor-modifiers")
|
|
|
|
.querySelectorAll(".modifier-card")
|
|
|
|
.forEach((modifierCard) => {
|
2023-06-19 16:24:31 +02:00
|
|
|
const modifierName = modifierCard.dataset.fullName // pick the full modifier name
|
2023-04-27 19:56:56 +02:00
|
|
|
if (activeTags.map((x) => x.name).includes(modifierName)) {
|
|
|
|
modifierCard.classList.remove(activeCardClass)
|
|
|
|
modifierCard.querySelector(".modifier-card-image-overlay").innerText = "+"
|
|
|
|
}
|
|
|
|
})
|
2022-11-11 03:36:39 +01:00
|
|
|
activeTags = []
|
|
|
|
|
|
|
|
// set new modifiers
|
2023-04-27 19:56:56 +02:00
|
|
|
newTags.forEach((tag) => {
|
2022-11-11 03:36:39 +01:00
|
|
|
let found = false
|
2023-04-27 19:56:56 +02:00
|
|
|
document
|
|
|
|
.querySelector("#editor-modifiers")
|
|
|
|
.querySelectorAll(".modifier-card")
|
|
|
|
.forEach((modifierCard) => {
|
2023-06-19 16:24:31 +02:00
|
|
|
const modifierName = modifierCard.dataset.fullName
|
2023-04-27 19:56:56 +02:00
|
|
|
const shortModifierName = modifierCard.querySelector(".modifier-card-label p").innerText
|
2023-06-19 16:24:31 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (trimModifiers(tag) == trimModifiers(modifierName)) {
|
|
|
|
// add modifier to active array
|
|
|
|
if (!activeTags.map((x) => x.name).includes(tag)) {
|
|
|
|
// only add each tag once even if several custom modifier cards share the same tag
|
|
|
|
const imageModifierCard = modifierCard.cloneNode(true)
|
|
|
|
imageModifierCard.querySelector(".modifier-card-label p").innerText = tag.replace(
|
|
|
|
modifierName,
|
|
|
|
shortModifierName
|
|
|
|
)
|
|
|
|
activeTags.push({
|
|
|
|
name: tag,
|
|
|
|
element: imageModifierCard,
|
2023-04-28 12:20:44 +02:00
|
|
|
originElement: modifierCard,
|
2023-04-27 19:56:56 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
modifierCard.classList.add(activeCardClass)
|
|
|
|
modifierCard.querySelector(".modifier-card-image-overlay").innerText = "-"
|
|
|
|
found = true
|
2022-11-20 04:21:36 +01:00
|
|
|
}
|
2023-04-27 19:56:56 +02:00
|
|
|
})
|
|
|
|
if (found == false) {
|
|
|
|
// custom tag went missing, create one here
|
2023-01-17 08:56:44 +01:00
|
|
|
let modifierCard = createModifierCard(tag, undefined, false) // create a modifier card for the missing tag, no image
|
2023-04-27 19:56:56 +02:00
|
|
|
|
|
|
|
modifierCard.addEventListener("click", () => {
|
|
|
|
if (activeTags.map((x) => x.name).includes(tag)) {
|
2022-11-11 03:36:39 +01:00
|
|
|
// remove modifier from active array
|
2023-04-27 19:56:56 +02:00
|
|
|
activeTags = activeTags.filter((x) => x.name != tag)
|
2022-11-11 03:36:39 +01:00
|
|
|
modifierCard.classList.remove(activeCardClass)
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
modifierCard.querySelector(".modifier-card-image-overlay").innerText = "+"
|
2022-11-11 03:36:39 +01:00
|
|
|
}
|
|
|
|
refreshTagsList()
|
|
|
|
})
|
|
|
|
|
|
|
|
activeTags.push({
|
2023-04-27 19:56:56 +02:00
|
|
|
name: tag,
|
|
|
|
element: modifierCard,
|
2023-04-28 12:20:44 +02:00
|
|
|
originElement: undefined, // no origin element for missing tags
|
2022-11-11 03:36:39 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2023-03-25 10:09:11 +01:00
|
|
|
refreshTagsList(inactiveTags)
|
2022-11-11 03:36:39 +01:00
|
|
|
}
|
|
|
|
|
2022-12-28 22:41:36 +01:00
|
|
|
function refreshInactiveTags(inactiveTags) {
|
|
|
|
// update inactive tags
|
|
|
|
if (inactiveTags !== undefined && inactiveTags.length > 0) {
|
2023-04-27 19:56:56 +02:00
|
|
|
activeTags.forEach((tag) => {
|
|
|
|
if (inactiveTags.find((element) => element === tag.name) !== undefined) {
|
2022-12-28 22:41:36 +01:00
|
|
|
tag.inactive = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-04-27 19:56:56 +02:00
|
|
|
|
2022-12-28 22:41:36 +01:00
|
|
|
// update cards
|
2023-06-19 16:24:31 +02:00
|
|
|
let overlays = editorModifierTagsList.querySelectorAll(".modifier-card-overlay")
|
2023-04-27 19:56:56 +02:00
|
|
|
overlays.forEach((i) => {
|
2023-06-19 16:24:31 +02:00
|
|
|
let modifierName = i.parentElement.dataset.fullName
|
|
|
|
|
2023-05-04 18:16:19 +02:00
|
|
|
if (inactiveTags?.find((element) => trimModifiers(element) === modifierName) !== undefined) {
|
2023-04-27 19:56:56 +02:00
|
|
|
i.parentElement.classList.add("modifier-toggle-inactive")
|
2022-12-28 22:41:36 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-25 10:09:11 +01:00
|
|
|
function refreshTagsList(inactiveTags) {
|
2023-04-27 19:56:56 +02:00
|
|
|
editorModifierTagsList.innerHTML = ""
|
2022-10-18 18:58:04 +02:00
|
|
|
|
|
|
|
if (activeTags.length == 0) {
|
2023-04-27 19:56:56 +02:00
|
|
|
editorTagsContainer.style.display = "none"
|
2022-10-18 18:58:04 +02:00
|
|
|
return
|
|
|
|
} else {
|
2023-04-27 19:56:56 +02:00
|
|
|
editorTagsContainer.style.display = "block"
|
2022-10-18 18:58:04 +02:00
|
|
|
}
|
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
if(activeTags.length > 15) {
|
|
|
|
editorModifierTagsList.style["overflow-y"] = "auto"
|
|
|
|
} else {
|
|
|
|
editorModifierTagsList.style["overflow-y"] = "unset"
|
|
|
|
}
|
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
activeTags.forEach((tag, index) => {
|
2023-04-27 19:56:56 +02:00
|
|
|
tag.element.querySelector(".modifier-card-image-overlay").innerText = "-"
|
|
|
|
tag.element.classList.add("modifier-card-tiny")
|
2022-10-18 18:58:04 +02:00
|
|
|
|
|
|
|
editorModifierTagsList.appendChild(tag.element)
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
tag.element.addEventListener("click", () => {
|
|
|
|
let idx = activeTags.findIndex((o) => {
|
|
|
|
return o.name === tag.name
|
|
|
|
})
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2022-12-01 07:13:13 +01:00
|
|
|
if (idx !== -1) {
|
|
|
|
toggleCardState(activeTags[idx].name, false)
|
2022-10-18 18:58:04 +02:00
|
|
|
|
|
|
|
activeTags.splice(idx, 1)
|
|
|
|
refreshTagsList()
|
|
|
|
}
|
2023-04-27 19:56:56 +02:00
|
|
|
document.dispatchEvent(new Event("refreshImageModifiers"))
|
2022-10-18 18:58:04 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
let brk = document.createElement("br")
|
|
|
|
brk.style.clear = "both"
|
2023-06-19 16:24:31 +02:00
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
editorModifierTagsList.appendChild(brk)
|
2023-06-19 16:24:31 +02:00
|
|
|
|
2023-03-25 10:09:11 +01:00
|
|
|
refreshInactiveTags(inactiveTags)
|
2023-06-19 16:24:31 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
document.dispatchEvent(new Event("refreshImageModifiers")) // notify plugins that the image tags have been refreshed
|
2022-10-18 18:58:04 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 07:13:13 +01:00
|
|
|
function toggleCardState(modifierName, makeActive) {
|
2023-06-19 16:24:31 +02:00
|
|
|
const cards = [...document.querySelectorAll("#editor-modifiers .modifier-card")]
|
|
|
|
.filter(cardElem => trimModifiers(cardElem.dataset.fullName) == trimModifiers(modifierName))
|
|
|
|
|
|
|
|
const cardExists = typeof cards == "object" && cards?.length > 0
|
|
|
|
|
|
|
|
if (cardExists) {
|
|
|
|
const card = cards[0]
|
|
|
|
|
|
|
|
if (makeActive) {
|
|
|
|
card.classList.add(activeCardClass)
|
|
|
|
card.querySelector(".modifier-card-image-overlay").innerText = "-"
|
|
|
|
} else {
|
|
|
|
card.classList.remove(activeCardClass)
|
|
|
|
card.querySelector(".modifier-card-image-overlay").innerText = "+"
|
|
|
|
}
|
|
|
|
}
|
2022-11-20 04:25:28 +01:00
|
|
|
}
|
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
function changePreviewImages(val) {
|
2023-04-27 19:56:56 +02:00
|
|
|
const previewImages = document.querySelectorAll(".modifier-card-image-container img")
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
const previewArr = modifiers.flatMap((x) => x.modifiers.map((m) => m.previews))
|
|
|
|
.map((x) => x.reduce((obj, preview) => {
|
2022-10-18 18:58:04 +02:00
|
|
|
obj[preview.name] = preview.path
|
2023-04-27 19:56:56 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
return obj
|
|
|
|
}, {}))
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
previewImages.forEach((previewImage) => {
|
|
|
|
const currentPreviewType = previewImage.getAttribute("preview-type")
|
|
|
|
const relativePreviewPath = previewImage.src.split(modifierThumbnailPath + "/").pop()
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
const previews = previewArr.find((preview) => relativePreviewPath == preview[currentPreviewType])
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (typeof previews == "object") {
|
2022-10-18 18:58:04 +02:00
|
|
|
let preview = null
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (val == "portrait") {
|
2022-10-18 18:58:04 +02:00
|
|
|
preview = previews.portrait
|
2023-04-27 19:56:56 +02:00
|
|
|
} else if (val == "landscape") {
|
2022-10-18 18:58:04 +02:00
|
|
|
preview = previews.landscape
|
|
|
|
}
|
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (preview != null) {
|
2022-10-18 18:58:04 +02:00
|
|
|
previewImage.src = `${modifierThumbnailPath}/${preview}`
|
2023-04-27 19:56:56 +02:00
|
|
|
previewImage.setAttribute("preview-type", val)
|
2022-10-18 18:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function resizeModifierCards(val) {
|
2023-04-27 19:56:56 +02:00
|
|
|
const cardSizePrefix = "modifier-card-size_"
|
|
|
|
const modifierCardClass = "modifier-card"
|
2022-10-18 18:58:04 +02:00
|
|
|
|
|
|
|
const modifierCards = document.querySelectorAll(`.${modifierCardClass}`)
|
2023-04-27 19:56:56 +02:00
|
|
|
const cardSize = (n) => `${cardSizePrefix}${n}`
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
modifierCards.forEach((card) => {
|
2022-10-18 18:58:04 +02:00
|
|
|
// remove existing size classes
|
2023-04-27 19:56:56 +02:00
|
|
|
const classes = card.className.split(" ").filter((c) => !c.startsWith(cardSizePrefix))
|
|
|
|
card.className = classes.join(" ").trim()
|
2022-10-18 18:58:04 +02:00
|
|
|
|
2023-04-27 19:56:56 +02:00
|
|
|
if (val != 0) {
|
2022-10-18 18:58:04 +02:00
|
|
|
card.classList.add(cardSize(val))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
function saveCustomModifiers() {
|
|
|
|
localStorage.setItem(CUSTOM_MODIFIERS_KEY, customModifiersTextBox.value.trim())
|
|
|
|
|
|
|
|
loadCustomModifiers()
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadCustomModifiers() {
|
|
|
|
PLUGINS["MODIFIERS_LOAD"].forEach((fn) => fn.loader.call())
|
|
|
|
}
|
|
|
|
|
|
|
|
function showModifierContainer() {
|
2023-06-27 15:29:58 +02:00
|
|
|
document.addEventListener("mousedown", checkIfClickedOutsideDropdownElem)
|
2023-06-19 16:24:31 +02:00
|
|
|
|
|
|
|
modifierDropdown.dataset.active = true
|
|
|
|
editorModifiersContainer.classList.add("active")
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideModifierContainer() {
|
|
|
|
document.removeEventListener("click", checkIfClickedOutsideDropdownElem)
|
|
|
|
|
|
|
|
modifierDropdown.dataset.active = false
|
|
|
|
editorModifiersContainer.classList.remove("active")
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkIfClickedOutsideDropdownElem(e) {
|
|
|
|
const clickedElement = e.target
|
|
|
|
|
2023-06-27 00:00:27 +02:00
|
|
|
const clickedInsideSpecificElems = [modifierDropdown, editorModifiersContainer, modifierSettingsDialog].some((div) =>
|
2023-06-19 16:24:31 +02:00
|
|
|
div && (div.contains(clickedElement) || div === clickedElement))
|
|
|
|
|
|
|
|
if (!clickedInsideSpecificElems && !modifierPanelFreezed) {
|
|
|
|
hideModifierContainer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function collapseAllModifierCategory() {
|
|
|
|
const collapsibleElems = editorModifierEntries.querySelectorAll(".modifier-category .collapsible"); // needs to have ";"
|
|
|
|
|
|
|
|
[...collapsibleElems].forEach((elem) => {
|
|
|
|
const isActive = elem.classList.contains("active")
|
|
|
|
|
|
|
|
if(isActive) {
|
|
|
|
elem?.click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expandAllModifierCategory() {
|
|
|
|
const collapsibleElems = editorModifierEntries.querySelectorAll(".modifier-category .collapsible"); // needs to have ";"
|
|
|
|
|
|
|
|
[...collapsibleElems].forEach((elem) => {
|
|
|
|
const isActive = elem.classList.contains("active")
|
|
|
|
|
|
|
|
if (!isActive) {
|
|
|
|
elem?.click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
customModifiersTextBox.addEventListener("change", saveCustomModifiers)
|
|
|
|
|
2022-10-18 18:58:04 +02:00
|
|
|
modifierCardSizeSlider.onchange = () => resizeModifierCards(modifierCardSizeSlider.value)
|
|
|
|
previewImageField.onchange = () => changePreviewImages(previewImageField.value)
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-06-27 00:00:27 +02:00
|
|
|
modifierSettingsDialog.addEventListener("keydown", function(e) {
|
2023-03-14 06:07:21 +01:00
|
|
|
switch (e.key) {
|
|
|
|
case "Escape": // Escape to cancel
|
|
|
|
customModifiersTextBox.value = customModifiersInitialContent // undo the changes
|
2023-06-27 00:00:27 +02:00
|
|
|
modifierSettingsDialog.close()
|
2023-03-14 06:07:21 +01:00
|
|
|
e.stopPropagation()
|
|
|
|
break
|
|
|
|
case "Enter":
|
2023-04-27 19:56:56 +02:00
|
|
|
if (e.ctrlKey) {
|
|
|
|
// Ctrl+Enter to confirm
|
2023-06-27 00:00:27 +02:00
|
|
|
modifierSettingsDialog.close()
|
2023-03-14 06:07:21 +01:00
|
|
|
e.stopPropagation()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
modifierDropdown.addEventListener("click", e => {
|
|
|
|
const targetElem = e.target
|
|
|
|
const isDropdownActive = targetElem.dataset.active == "true" ? true : false
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
if (!isDropdownActive)
|
|
|
|
showModifierContainer()
|
|
|
|
else
|
|
|
|
hideModifierContainer()
|
|
|
|
})
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
let collapsiblesBtnState = false
|
2022-10-21 10:38:16 +02:00
|
|
|
|
2023-06-19 16:24:31 +02:00
|
|
|
modifiersCollapsiblesBtn.addEventListener("click", (e) => {
|
|
|
|
const btnElem = modifiersCollapsiblesBtn
|
|
|
|
|
|
|
|
const collapseText = "Collapse Categories"
|
|
|
|
const expandText = "Expand Categories"
|
|
|
|
|
|
|
|
const collapseIconClasses = ["fa-solid", "fa-square-minus"]
|
|
|
|
const expandIconClasses = ["fa-solid", "fa-square-plus"]
|
|
|
|
|
|
|
|
const iconElem = btnElem.querySelector(".modifiers-action-icon")
|
|
|
|
const textElem = btnElem.querySelector(".modifiers-action-text")
|
|
|
|
|
|
|
|
if (collapsiblesBtnState) {
|
|
|
|
collapseAllModifierCategory()
|
|
|
|
|
|
|
|
collapsiblesBtnState = false
|
|
|
|
|
|
|
|
collapseIconClasses.forEach((c) => iconElem.classList.remove(c))
|
|
|
|
expandIconClasses.forEach((c) => iconElem.classList.add(c))
|
|
|
|
|
|
|
|
textElem.innerText = expandText
|
|
|
|
} else {
|
|
|
|
expandAllModifierCategory()
|
|
|
|
|
|
|
|
collapsiblesBtnState = true
|
|
|
|
|
|
|
|
expandIconClasses.forEach((c) => iconElem.classList.remove(c))
|
|
|
|
collapseIconClasses.forEach((c) => iconElem.classList.add(c))
|
|
|
|
|
|
|
|
textElem.innerText = collapseText
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let containerSizeBtnState = false
|
|
|
|
|
|
|
|
modifiersContainerSizeBtn.addEventListener("click", (e) => {
|
|
|
|
const btnElem = modifiersContainerSizeBtn
|
|
|
|
|
|
|
|
const maximizeIconClasses = ["fa-solid", "fa-expand"]
|
|
|
|
const revertIconClasses = ["fa-solid", "fa-compress"]
|
|
|
|
|
|
|
|
modifiersMainContainer.classList.toggle("modifiers-maximized")
|
|
|
|
|
|
|
|
if(containerSizeBtnState) {
|
|
|
|
revertIconClasses.forEach((c) => btnElem.classList.remove(c))
|
|
|
|
maximizeIconClasses.forEach((c) => btnElem.classList.add(c))
|
|
|
|
|
|
|
|
containerSizeBtnState = false
|
|
|
|
} else {
|
|
|
|
maximizeIconClasses.forEach((c) => btnElem.classList.remove(c))
|
|
|
|
revertIconClasses.forEach((c) => btnElem.classList.add(c))
|
|
|
|
|
|
|
|
containerSizeBtnState = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
modifierSettingsBtn.addEventListener("click", (e) => {
|
2023-06-27 00:00:27 +02:00
|
|
|
modifierSettingsDialog.showModal()
|
2023-06-19 16:24:31 +02:00
|
|
|
customModifiersTextBox.setSelectionRange(0, 0)
|
|
|
|
customModifiersTextBox.focus()
|
|
|
|
customModifiersInitialContent = customModifiersTextBox.value // preserve the initial content
|
|
|
|
e.stopPropagation()
|
|
|
|
})
|
|
|
|
|
|
|
|
modifiersCloseBtn.addEventListener("click", (e) => {
|
|
|
|
hideModifierContainer()
|
|
|
|
})
|
|
|
|
|
|
|
|
// prevents the modifier panel closing at the same time as the settings overlay
|
|
|
|
new MutationObserver(() => {
|
2023-06-27 00:00:27 +02:00
|
|
|
const isActive = modifierSettingsDialog.open
|
2023-06-19 16:24:31 +02:00
|
|
|
|
|
|
|
if (!isActive) {
|
|
|
|
modifierPanelFreezed = true
|
|
|
|
|
|
|
|
setTimeout(() => modifierPanelFreezed = false, 25)
|
|
|
|
}
|
2023-06-27 00:00:27 +02:00
|
|
|
}).observe(modifierSettingsDialog, { attributes: true })
|
|
|
|
|
|
|
|
modifierSettingsCloseBtn.addEventListener("click", (e) => {
|
|
|
|
modifierSettingsDialog.close()
|
|
|
|
})
|
|
|
|
|
2023-06-28 19:11:37 +02:00
|
|
|
modalDialogCloseOnBackdropClick(modifierSettingsDialog)
|
2023-06-28 22:12:32 +02:00
|
|
|
makeDialogDraggable(modifierSettingsDialog)
|
2023-06-27 00:00:27 +02:00
|
|
|
|