|
Server IP : 168.119.101.163 / Your IP : 216.73.217.54 Web Server : Apache/2 System : Linux web02.webzuiver.nl 4.18.0-553.126.2.lve.el8.x86_64 #1 SMP Thu May 28 14:12:30 UTC 2026 x86_64 User : equine ( 1027) PHP Version : 8.1.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF Directory (0755) : /home/equine/public_html/wp-content/plugins/code-snippets/js/services/settings/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
import '../../editor'
const parseSelect = (select: HTMLSelectElement) => select.options[select.selectedIndex].value
const parseCheckbox = (checkbox: HTMLInputElement) => checkbox.checked
const parseNumber = (input: HTMLInputElement) => parseInt(input.value, 10)
const initialiseCodeMirror = () => {
const { codeEditor } = window.wp
const textarea = document.getElementById('code_snippets_editor_preview')
if (textarea) {
window.code_snippets_editor_preview = codeEditor.initialize(textarea)
return window.code_snippets_editor_preview.codemirror
}
console.error('Could not initialise CodeMirror on textarea.', textarea)
return undefined
}
export const handleEditorPreviewUpdates = () => {
const editor = initialiseCodeMirror()
const editorSettings = window.code_snippets_editor_settings
for (const setting of editorSettings) {
const element = document.querySelector(`[name="code_snippets_settings[editor][${setting.name}]"]`)
element?.addEventListener('change', () => {
const opt = setting.codemirror
const value = (() => {
switch (setting.type) {
case 'select':
return parseSelect(<HTMLSelectElement> element)
case 'checkbox':
return parseCheckbox(<HTMLInputElement> element)
case 'number':
return parseNumber(<HTMLInputElement> element)
default:
return null
}
})()
if (null !== value) {
if ('font_size' === setting.name) {
const codeElement = document.querySelector('.CodeMirror-code')
if (codeElement && codeElement instanceof HTMLElement) {
codeElement.style.fontSize = `${value}px`
}
} else {
editor?.setOption(opt, value)
}
}
})
}
}