refactor
This commit is contained in:
parent
0f8af9b014
commit
e963a3e179
59
main.js
59
main.js
@ -308,7 +308,7 @@
|
|||||||
return ref
|
return ref
|
||||||
}
|
}
|
||||||
|
|
||||||
let makeCoordinatesLinks = (function() {
|
let makeCoordinatesLinks = (function () {
|
||||||
var executed = false
|
var executed = false
|
||||||
return function () {
|
return function () {
|
||||||
if (executed) return
|
if (executed) return
|
||||||
@ -443,7 +443,7 @@
|
|||||||
while (n--) {
|
while (n--) {
|
||||||
u8arr[n] = bstr.charCodeAt(n)
|
u8arr[n] = bstr.charCodeAt(n)
|
||||||
}
|
}
|
||||||
return new File([u8arr], filename, {type:mime})
|
return new File([u8arr], filename, { type: mime })
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHtmlElementByFileType(file) {
|
function getHtmlElementByFileType(file) {
|
||||||
@ -481,7 +481,7 @@
|
|||||||
function makeHandleFilesFunc() {
|
function makeHandleFilesFunc() {
|
||||||
let storedFiles = []
|
let storedFiles = []
|
||||||
|
|
||||||
return function() {
|
return function () {
|
||||||
let dt = new DataTransfer()
|
let dt = new DataTransfer()
|
||||||
|
|
||||||
if (storedFiles.length) {
|
if (storedFiles.length) {
|
||||||
@ -556,7 +556,7 @@
|
|||||||
displayedFile.src = e.target.result
|
displayedFile.src = e.target.result
|
||||||
downloadLink.setAttribute("href", displayedFile.src)
|
downloadLink.setAttribute("href", displayedFile.src)
|
||||||
|
|
||||||
storedFiles.push({data: displayedFile.src, name: file.name})
|
storedFiles.push({ data: displayedFile.src, name: file.name })
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(file)
|
reader.readAsDataURL(file)
|
||||||
}
|
}
|
||||||
@ -565,9 +565,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let prettifyFiles = (function() {
|
let prettifyFiles = (function () {
|
||||||
var executed = false
|
var executed = false
|
||||||
return function(insertedFileRows) {
|
return function (insertedFileRows) {
|
||||||
if (executed) return
|
if (executed) return
|
||||||
executed = true
|
executed = true
|
||||||
|
|
||||||
@ -666,7 +666,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function moveNewFilesOnVariantChange() {
|
function moveNewFilesOnVariantChange() {
|
||||||
document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function() {
|
document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function () {
|
||||||
let attachmentIndex = getAttachmentIndex(this)
|
let attachmentIndex = getAttachmentIndex(this)
|
||||||
|
|
||||||
let [from, to] = getContainersByVariant(this.value, attachmentIndex)
|
let [from, to] = getContainersByVariant(this.value, attachmentIndex)
|
||||||
@ -720,7 +720,7 @@
|
|||||||
alwaysPrettifyCheckbox.type = "checkbox"
|
alwaysPrettifyCheckbox.type = "checkbox"
|
||||||
alwaysPrettifyCheckbox.id = "always-prettify-" + index
|
alwaysPrettifyCheckbox.id = "always-prettify-" + index
|
||||||
alwaysPrettifyCheckbox.name = "always-prettify-" + index
|
alwaysPrettifyCheckbox.name = "always-prettify-" + index
|
||||||
alwaysPrettifyCheckbox.addEventListener("change", function() {
|
alwaysPrettifyCheckbox.addEventListener("change", function () {
|
||||||
let otherCheckboxes = document.querySelectorAll(`input[name^="always-prettify-"]`)
|
let otherCheckboxes = document.querySelectorAll(`input[name^="always-prettify-"]`)
|
||||||
for (let checkbox of otherCheckboxes) {
|
for (let checkbox of otherCheckboxes) {
|
||||||
if (checkbox.id !== this.id) {
|
if (checkbox.id !== this.id) {
|
||||||
@ -816,9 +816,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bindArrowsForGallery(leftButtonQuery, rightButtonQuery) {
|
function bindArrowsForGallery(leftButtonQuery, rightButtonQuery) {
|
||||||
document.addEventListener("keydown", function(e) {
|
document.addEventListener("keydown", function (e) {
|
||||||
if (!document.querySelector("dialog").open) return
|
if (!document.querySelector("dialog").open) return
|
||||||
switch(e.key) {
|
switch (e.key) {
|
||||||
case "ArrowLeft":
|
case "ArrowLeft":
|
||||||
$(leftButtonQuery).click()
|
$(leftButtonQuery).click()
|
||||||
break
|
break
|
||||||
@ -1835,7 +1835,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isAllPointsSouthOfLat(lat) {
|
function isAllPointsSouthOfLat(lat) {
|
||||||
map.eachLayer(function(layer) {
|
map.eachLayer(function (layer) {
|
||||||
if (layer instanceof L.Marker) {
|
if (layer instanceof L.Marker) {
|
||||||
let latLng = layer.getLatLng()
|
let latLng = layer.getLatLng()
|
||||||
if (latLng.lat > lat) {
|
if (latLng.lat > lat) {
|
||||||
@ -1859,7 +1859,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettifyRouteBuildPage() {
|
function changeColumnWidthForRouteBuildPage() {
|
||||||
let styles = `
|
let styles = `
|
||||||
#content table table {
|
#content table table {
|
||||||
td:nth-child(2) {
|
td:nth-child(2) {
|
||||||
@ -1884,11 +1884,22 @@
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
addStylesToHead(styles)
|
addStylesToHead(styles)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideDescriptionFromRouteBuildPage() {
|
||||||
document.querySelectorAll(`#content > form > table > tbody > tr:is(:nth-child(3), :nth-child(6)) `).forEach(el => el.remove())
|
document.querySelectorAll(`#content > form > table > tbody > tr:is(:nth-child(3), :nth-child(6)) `).forEach(el => el.remove())
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideStartRowFromRouteBuildPage() {
|
||||||
document.querySelector(`#content table table tr:nth-child(2) `).remove()
|
document.querySelector(`#content table table tr:nth-child(2) `).remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prettifyRouteBuildPage() {
|
||||||
|
changeColumnWidthForRouteBuildPage()
|
||||||
|
hideDescriptionFromRouteBuildPage()
|
||||||
|
hideStartRowFromRouteBuildPage()
|
||||||
|
}
|
||||||
|
|
||||||
function matchNumberFromSelect(select) {
|
function matchNumberFromSelect(select) {
|
||||||
return [...document.querySelector(select).options].reduce(
|
return [...document.querySelector(select).options].reduce(
|
||||||
(res, el) => ({ ...res, [el.textContent.match(/(?<=^\s*#)\d+/g)?.[0]]: el.value }),
|
(res, el) => ({ ...res, [el.textContent.match(/(?<=^\s*#)\d+/g)?.[0]]: el.value }),
|
||||||
@ -1904,13 +1915,7 @@
|
|||||||
document.querySelector(`${select} option:last-child`).scrollIntoView()
|
document.querySelector(`${select} option:last-child`).scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettifyRouteEditPage() {
|
function createPointsInpitForRouteEditPage() {
|
||||||
document.querySelectorAll(`textarea:is([name="track[comment_int]"], [name="track[comment_ext]"])`).forEach(el => {
|
|
||||||
el.rows = 1
|
|
||||||
})
|
|
||||||
|
|
||||||
document.querySelectorAll(`table tr:is(:nth-child(3), :nth-child(4), :nth-child(5))`).forEach(el => el.classList.add("hidden"))
|
|
||||||
|
|
||||||
let addPointsContainer = document.createElement("div")
|
let addPointsContainer = document.createElement("div")
|
||||||
|
|
||||||
let pointInput = document.createElement("input")
|
let pointInput = document.createElement("input")
|
||||||
@ -2001,6 +2006,16 @@
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prettifyRouteEditPage() {
|
||||||
|
document.querySelectorAll(`textarea:is([name="track[comment_int]"], [name="track[comment_ext]"])`).forEach(el => {
|
||||||
|
el.rows = 1
|
||||||
|
})
|
||||||
|
|
||||||
|
document.querySelectorAll(`table tr:is(:nth-child(3), :nth-child(4), :nth-child(5))`).forEach(el => el.classList.add("hidden"))
|
||||||
|
|
||||||
|
createPointsInpitForRouteEditPage()
|
||||||
|
}
|
||||||
|
|
||||||
function toggleStagePageRows(rows) {
|
function toggleStagePageRows(rows) {
|
||||||
let showIndex = [0, 3]
|
let showIndex = [0, 3]
|
||||||
let to = rows.findIndex(el => el.querySelector("th")?.textContent.trim() == "Бонусы")
|
let to = rows.findIndex(el => el.querySelector("th")?.textContent.trim() == "Бонусы")
|
||||||
@ -2011,7 +2026,7 @@
|
|||||||
toggleRows(rows, to, rows.length, 1, [])
|
toggleRows(rows, to, rows.length, 1, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettifyRouteStagesPage() {
|
function hideUselessRowsFromRouteStagesPage() {
|
||||||
let styles = `
|
let styles = `
|
||||||
tr.collapsed {
|
tr.collapsed {
|
||||||
display: block;
|
display: block;
|
||||||
@ -2143,7 +2158,7 @@
|
|||||||
alwaysEnableCheckbox.type = "checkbox"
|
alwaysEnableCheckbox.type = "checkbox"
|
||||||
alwaysEnableCheckbox.id = "always-enable"
|
alwaysEnableCheckbox.id = "always-enable"
|
||||||
alwaysEnableCheckbox.name = "always-enable"
|
alwaysEnableCheckbox.name = "always-enable"
|
||||||
alwaysEnableCheckbox.addEventListener("change", function() {
|
alwaysEnableCheckbox.addEventListener("change", function () {
|
||||||
if (this.checked)
|
if (this.checked)
|
||||||
removeDisabledPage()
|
removeDisabledPage()
|
||||||
else
|
else
|
||||||
@ -2190,7 +2205,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isRouteStagesPage()) {
|
if (isRouteStagesPage()) {
|
||||||
prettifyRouteStagesPage()
|
hideUselessRowsFromRouteStagesPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user