programmingfonts/modules/fontsize.js

49 lines
949 B
JavaScript
Raw Normal View History

2023-07-04 23:18:24 +02:00
import { Cookies } from './cookies.js'
2023-07-05 16:42:30 +02:00
export class Fontsize {
2023-07-04 23:18:24 +02:00
el = document.getElementById('size')
init () {
2023-07-05 16:42:30 +02:00
if (Cookies.get('size')) {
this.el.value = Cookies.get('size')
}
2023-07-04 23:18:24 +02:00
this.el.onchange = () => {
this.set()
}
this.set()
}
up () {
const sizeEl = this.el
sizeEl.value = Number(sizeEl.value) + 1
sizeEl.onchange()
}
down () {
const sizeEl = this.el
sizeEl.value = Number(sizeEl.value) - 1
sizeEl.onchange()
}
set () {
const size = this.el.value
document.querySelector('.CodeMirror').style.fontSize = `${size}px`
Cookies.set('size', size)
window.CMeditor.refresh()
}
forceSize (px) {
this.el.value = px
document.querySelector('.CodeMirror').style.fontSize = `${px}px`
window.CMeditor.refresh()
}
reset () {
if (Cookies.get('size')) {
this.forceSize(Cookies.get('size'))
} else {
this.forceSize('16')
}
}
}