refractor: change var name

This commit is contained in:
Sped0n
2023-08-13 22:33:47 +08:00
parent c2f9627717
commit b1415b7f17
8 changed files with 34 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
import { type ImageData } from './utils' import { type ImageData } from './utils'
// fetch images info from JSON // fetch images info from JSON
const imageArrayElement = document.getElementById('images_array') as HTMLScriptElement const imageArrayElement = document.getElementById('images_info') as HTMLScriptElement
const rawImageArray = imageArrayElement.textContent as string const rawImagesInfo = imageArrayElement.textContent as string
export const imagesArray: ImageData[] = JSON.parse(rawImageArray).sort( export const imagesInfo: ImageData[] = JSON.parse(rawImagesInfo).sort(
(a: ImageData, b: ImageData) => { (a: ImageData, b: ImageData) => {
if (a.index < b.index) { if (a.index < b.index) {
return -1 return -1
@@ -11,4 +11,4 @@ export const imagesArray: ImageData[] = JSON.parse(rawImageArray).sort(
return 1 return 1
} }
) )
export const imagesArrayLen: number = imagesArray.length export const imagesLen: number = imagesInfo.length

View File

@@ -10,7 +10,7 @@ import {
} from './utils' } from './utils'
import { thresholdIndex, thresholdSensitivityArray } from './thresholdCtl' import { thresholdIndex, thresholdSensitivityArray } from './thresholdCtl'
import { imgIndexSpanUpdate } from './indexDisp' import { imgIndexSpanUpdate } from './indexDisp'
import { imagesArrayLen } from './dataFetch' import { imagesLen } from './dataFetch'
import { imagesDivNodes as images } from './elemGen' import { imagesDivNodes as images } from './elemGen'
// global index for "activated" // global index for "activated"
@@ -55,7 +55,7 @@ const activate = (index: number, mouseX: number, mouseY: number): void => {
trailingImageIndexes, trailingImageIndexes,
stackDepth, stackDepth,
images, images,
imagesArrayLen imagesLen
) )
// set img position // set img position
images[index].style.transform = mouseToTransform(mouseX, mouseY, true, true) images[index].style.transform = mouseToTransform(mouseX, mouseY, true, true)
@@ -81,10 +81,10 @@ export const handleOnMove = (e: MouseEvent): void => {
window.innerWidth / thresholdSensitivityArray[thresholdIndex] window.innerWidth / thresholdSensitivityArray[thresholdIndex]
) { ) {
// calculate the actual index // calculate the actual index
const imageIndex = calcImageIndex(globalIndex, imagesArrayLen) const imageIndex = calcImageIndex(globalIndex, imagesLen)
// show top image and change index // show top image and change index
activate(imageIndex, e.clientX, e.clientY) activate(imageIndex, e.clientX, e.clientY)
imgIndexSpanUpdate(imageIndex + 1, imagesArrayLen) imgIndexSpanUpdate(imageIndex + 1, imagesLen)
// self increment // self increment
globalIndexInc() globalIndexInc()
} }

View File

@@ -1,4 +1,4 @@
import { imagesArray, imagesArrayLen } from './dataFetch' import { imagesInfo, imagesLen } from './dataFetch'
import { createImgElement } from './utils' import { createImgElement } from './utils'
// get components of overlay // get components of overlay
@@ -37,8 +37,8 @@ export const createDesktopElements = (): void => {
mainDiv.appendChild(createCursorDiv()) mainDiv.appendChild(createCursorDiv())
const imagesDiv: HTMLDivElement = document.createElement('div') const imagesDiv: HTMLDivElement = document.createElement('div')
imagesDiv.className = 'imagesDesktop' imagesDiv.className = 'imagesDesktop'
for (let i = 0; i < imagesArrayLen; i++) { for (let i = 0; i < imagesLen; i++) {
imagesDiv.appendChild(createImgElement(imagesArray[i])) imagesDiv.appendChild(createImgElement(imagesInfo[i]))
} }
mainDiv.appendChild(imagesDiv) mainDiv.appendChild(imagesDiv)
passDesktopElements() passDesktopElements()
@@ -47,8 +47,8 @@ export const createDesktopElements = (): void => {
export const createMobileElements = (): void => { export const createMobileElements = (): void => {
const imagesDiv: HTMLDivElement = document.createElement('div') const imagesDiv: HTMLDivElement = document.createElement('div')
imagesDiv.className = 'imagesMobile' imagesDiv.className = 'imagesMobile'
for (let i = 0; i < imagesArrayLen; i++) { for (let i = 0; i < imagesLen; i++) {
imagesDiv.appendChild(createImgElement(imagesArray[i])) imagesDiv.appendChild(createImgElement(imagesInfo[i]))
} }
mainDiv.appendChild(imagesDiv) mainDiv.appendChild(imagesDiv)
passMobileElements() passMobileElements()

View File

@@ -1,4 +1,4 @@
import { imagesArray, imagesArrayLen } from './dataFetch' import { imagesInfo, imagesLen } from './dataFetch'
import { preloadImage, calcImageIndex } from './utils' import { preloadImage, calcImageIndex } from './utils'
let lastIndex: number = 0 let lastIndex: number = 0
@@ -6,13 +6,13 @@ let lastIndex: number = 0
export const preloader = (index: number): void => { export const preloader = (index: number): void => {
if (lastIndex === index) { if (lastIndex === index) {
for (let i: number = -2; i <= 1; i++) for (let i: number = -2; i <= 1; i++)
preloadImage(imagesArray[calcImageIndex(index + i, imagesArrayLen)].url) preloadImage(imagesInfo[calcImageIndex(index + i, imagesLen)].url)
} else if (lastIndex > index) { } else if (lastIndex > index) {
for (let i: number = 1; i <= 3; i++) for (let i: number = 1; i <= 3; i++)
preloadImage(imagesArray[calcImageIndex(index - i, imagesArrayLen)].url) preloadImage(imagesInfo[calcImageIndex(index - i, imagesLen)].url)
} else { } else {
for (let i: number = 1; i <= 3; i++) for (let i: number = 1; i <= 3; i++)
preloadImage(imagesArray[calcImageIndex(index + i, imagesArrayLen)].url) preloadImage(imagesInfo[calcImageIndex(index + i, imagesLen)].url)
} }
lastIndex = index lastIndex = index
} }

View File

@@ -2,7 +2,7 @@ import { createDesktopElements, createMobileElements } from './elemGen'
import { imgIndexSpanUpdate } from './indexDisp' import { imgIndexSpanUpdate } from './indexDisp'
import { trackMouseInit } from './desktop' import { trackMouseInit } from './desktop'
import { thresholdCtlInit } from './thresholdCtl' import { thresholdCtlInit } from './thresholdCtl'
import { imagesArrayLen } from './dataFetch' import { imagesLen } from './dataFetch'
import { vwRefreshInit } from './overlay' import { vwRefreshInit } from './overlay'
import { preloader } from './imageCache' import { preloader } from './imageCache'
import { getDeviceType } from './utils' import { getDeviceType } from './utils'
@@ -12,7 +12,7 @@ const desktopInit = (): void => {
createDesktopElements() createDesktopElements()
preloader(0) preloader(0)
vwRefreshInit() vwRefreshInit()
imgIndexSpanUpdate(0, imagesArrayLen) imgIndexSpanUpdate(0, imagesLen)
thresholdCtlInit() thresholdCtlInit()
trackMouseInit() trackMouseInit()
} }
@@ -20,7 +20,7 @@ const desktopInit = (): void => {
const mobileInit = (): void => { const mobileInit = (): void => {
createMobileElements() createMobileElements()
vwRefreshInit() vwRefreshInit()
imgIndexSpanUpdate(0, imagesArrayLen) imgIndexSpanUpdate(0, imagesLen)
renderImages() renderImages()
console.log('mobile') console.log('mobile')
} }

View File

@@ -1,5 +1,5 @@
import { imagesDivNodes as images } from './elemGen' import { imagesDivNodes as images } from './elemGen'
import { imagesArrayLen } from './dataFetch' import { imagesLen } from './dataFetch'
export const renderImages = (): void => { export const renderImages = (): void => {
images.forEach((img: HTMLImageElement, idx: number): void => { images.forEach((img: HTMLImageElement, idx: number): void => {
@@ -11,7 +11,7 @@ export const renderImages = (): void => {
randomY = 68 randomY = 68
} else if (idx === 1) { } else if (idx === 1) {
randomY = 44 randomY = 44
} else if (idx === imagesArrayLen - 1) { } else if (idx === imagesLen - 1) {
randomY = 100 randomY = 100
} else { } else {
randomY = Math.floor(Math.random() * 51) + 2 randomY = Math.floor(Math.random() * 51) + 2

View File

@@ -11,7 +11,7 @@ import {
stackDepth, stackDepth,
addEnterOverlayEL addEnterOverlayEL
} from './desktop' } from './desktop'
import { imagesArrayLen } from './dataFetch' import { imagesLen } from './dataFetch'
import { imgIndexSpanUpdate } from './indexDisp' import { imgIndexSpanUpdate } from './indexDisp'
import { overlayCursor, cursorInnerContent, imagesDivNodes as images } from './elemGen' import { overlayCursor, cursorInnerContent, imagesDivNodes as images } from './elemGen'
@@ -61,7 +61,7 @@ async function handleCloseClick(): Promise<void> {
// prepare animation // prepare animation
for (let i: number = 0; i < indexesNum; i++) { for (let i: number = 0; i < indexesNum; i++) {
// get element from index and store the index // get element from index and store the index
const index: number = calcImageIndex(globalIndex - i, imagesArrayLen) const index: number = calcImageIndex(globalIndex - i, imagesLen)
const e: HTMLImageElement = images[index] const e: HTMLImageElement = images[index]
trailingImageIndexes.unshift(index) trailingImageIndexes.unshift(index)
// set z index for the image element // set z index for the image element
@@ -88,10 +88,10 @@ async function handleCloseClick(): Promise<void> {
// halt the function while animation is running // halt the function while animation is running
await delay(1200 + stackDepth * 100 + 100) await delay(1200 + stackDepth * 100 + 100)
// add back enter overlay event listener to top image // add back enter overlay event listener to top image
addEnterOverlayEL(images[calcImageIndex(globalIndex, imagesArrayLen)]) addEnterOverlayEL(images[calcImageIndex(globalIndex, imagesLen)])
// clear unused status and transition delay // clear unused status and transition delay
for (let i: number = 0; i < indexesNum; i++) { for (let i: number = 0; i < indexesNum; i++) {
const index: number = calcImageIndex(globalIndex - i, imagesArrayLen) const index: number = calcImageIndex(globalIndex - i, imagesLen)
images[index].dataset.status = 'null' images[index].dataset.status = 'null'
images[index].style.transitionDelay = '' images[index].style.transitionDelay = ''
} }
@@ -105,10 +105,10 @@ async function handleCloseClick(): Promise<void> {
const handleSideClick = (CLD: boolean): void => { const handleSideClick = (CLD: boolean): void => {
// get last displayed image's index // get last displayed image's index
const imgIndex: number = calcImageIndex(globalIndex, imagesArrayLen) const imgIndex: number = calcImageIndex(globalIndex, imagesLen)
// change global index and get current displayed image's index // change global index and get current displayed image's index
CLD ? globalIndexInc() : globalIndexDec() CLD ? globalIndexInc() : globalIndexDec()
const currImgIndex: number = calcImageIndex(globalIndex, imagesArrayLen) const currImgIndex: number = calcImageIndex(globalIndex, imagesLen)
// store current displayed image's index // store current displayed image's index
CLD CLD
? pushIndex( ? pushIndex(
@@ -116,7 +116,7 @@ const handleSideClick = (CLD: boolean): void => {
trailingImageIndexes, trailingImageIndexes,
stackDepth, stackDepth,
images, images,
imagesArrayLen, imagesLen,
false, false,
false false
) )
@@ -125,7 +125,7 @@ const handleSideClick = (CLD: boolean): void => {
trailingImageIndexes, trailingImageIndexes,
stackDepth, stackDepth,
images, images,
imagesArrayLen, imagesLen,
true, true,
false false
) )
@@ -138,7 +138,7 @@ const handleSideClick = (CLD: boolean): void => {
// process complete, show the image // process complete, show the image
images[currImgIndex].style.visibility = 'visible' images[currImgIndex].style.visibility = 'visible'
// change index display // change index display
imgIndexSpanUpdate(currImgIndex + 1, imagesArrayLen) imgIndexSpanUpdate(currImgIndex + 1, imagesLen)
} }
// change text and position of overlay cursor // change text and position of overlay cursor
@@ -195,9 +195,9 @@ export const vwRefreshInit = (): void => {
} }
// recenter image (only in overlay) // recenter image (only in overlay)
if ( if (
images[calcImageIndex(globalIndex, imagesArrayLen)].dataset.status === 'overlay' images[calcImageIndex(globalIndex, imagesLen)].dataset.status === 'overlay'
) )
center(images[calcImageIndex(globalIndex, imagesArrayLen)]) center(images[calcImageIndex(globalIndex, imagesLen)])
}, },
{ passive: true } { passive: true }
) )

View File

@@ -33,7 +33,7 @@
"pColor" (string $pColor) "pColor" (string $pColor)
"sColor" (string $sColor)) }} "sColor" (string $sColor)) }}
{{ end }} {{ end }}
<script id="images_array" type="application/json">{{ $.Scratch.Get "img" | jsonify | safeJS }}</script> <script id="images_info" type="application/json">{{ $.Scratch.Get "img" | jsonify | safeJS }}</script>
{{ end }} {{ end }}
</div> </div>
<footer> <footer>