mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-17 19:49:30 -07:00
* feat: refactor condition for checking `site.Params.bundled` - Add default condition for checking if `site.Params.bundled` is true or false * refactor: update info page content * chore: update site description * refactor: refactor variable assignments and return statement in menu template - Change the variable assignment from `.DirName` to `.Identifier` in the file `layouts/_default/single.json` - Change the variable assignments in the file `layouts/partials/function/currentMenuItem.html`: - From `$dirName := ""` to `$identifier := ""` - From `$id := -1` to `$title := ""` and `$weight := -1` - From `$dirName = .Identifier` to `$identifier = .Identifier`, `$title = .Title`, and `$weight = .Weight` - Change the return statement in the file `layouts/partials/function/currentMenuItem.html` from `(dict "DirName" $dirName "ID" $id)` to `(dict "Identifier" $identifier "Title" $title "Weight" $weight)` * feat: update nav links structure for current link styling - Remove javascript code related to setting current link style and title - Update nav links to use updated HTML structure for current link styling * feat: update page titles and meta tags in layout files - Update the `baseof.html` layout to include the current page title in the `<title>` tag - Add OpenGraph meta tags for the page title and description in `meta.html` layout
84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
import { decThreshold, incThreshold, state } from './state'
|
|
import { expand } from './utils'
|
|
|
|
/**
|
|
* variables
|
|
*/
|
|
|
|
// threshold div
|
|
const thresholdDiv = document
|
|
.getElementsByClassName('threshold')
|
|
.item(0) as HTMLDivElement
|
|
|
|
// threshold nums span
|
|
const thresholdDispNums = Array.from(
|
|
thresholdDiv.getElementsByClassName('num')
|
|
) as HTMLSpanElement[]
|
|
|
|
// threshold buttons
|
|
const decButton = thresholdDiv
|
|
.getElementsByClassName('dec')
|
|
.item(0) as HTMLButtonElement
|
|
const incButton = thresholdDiv
|
|
.getElementsByClassName('inc')
|
|
.item(0) as HTMLButtonElement
|
|
|
|
// index div
|
|
const indexDiv = document.getElementsByClassName('index').item(0) as HTMLDivElement
|
|
|
|
// index nums span
|
|
const indexDispNums = Array.from(
|
|
indexDiv.getElementsByClassName('num')
|
|
) as HTMLSpanElement[]
|
|
|
|
/**
|
|
* init
|
|
*/
|
|
|
|
export function initNav(): void {
|
|
const s = state.get()
|
|
// init threshold text
|
|
updateThresholdText(expand(s.threshold))
|
|
// init index text
|
|
updateIndexText(expand(s.index + 1), expand(s.length))
|
|
// add watcher for updating nav text
|
|
state.addWatcher((o) => {
|
|
updateIndexText(expand(o.index + 1), expand(o.length))
|
|
updateThresholdText(expand(o.threshold))
|
|
})
|
|
|
|
// event listeners
|
|
decButton.addEventListener(
|
|
'click',
|
|
() => {
|
|
decThreshold()
|
|
},
|
|
{ passive: true }
|
|
)
|
|
incButton.addEventListener(
|
|
'click',
|
|
() => {
|
|
incThreshold()
|
|
},
|
|
{ passive: true }
|
|
)
|
|
}
|
|
|
|
// helper
|
|
|
|
export function updateThresholdText(thresholdValue: string): void {
|
|
thresholdDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
|
e.innerText = thresholdValue[i]
|
|
})
|
|
}
|
|
|
|
export function updateIndexText(indexValue: string, indexLength: string): void {
|
|
indexDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
|
if (i < 4) {
|
|
e.innerText = indexValue[i]
|
|
} else {
|
|
e.innerText = indexLength[i - 4]
|
|
}
|
|
})
|
|
}
|