PluginProbe
Code Snippets / 3.2.1
Code Snippets v3.2.1
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / js / edit / shortcode.ts

shortcode.ts in Code Snippets 3.2.1, at js/edit/shortcode.ts

43 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const updateShortcode = (options: HTMLCollectionOf<HTMLInputElement>) => {
2 const isNetworkAdmin = -1 !== document.body.className.indexOf('network-admin')
3
4 const snippetIdInput = document.querySelector<HTMLInputElement>('input[name=snippet_id]')
5 const snippetId = snippetIdInput ? parseInt(snippetIdInput.value, 10) : 0
6
7 let shortcode = '[code_snippet'
8
9 if (snippetId) {
10 shortcode += ` id=${snippetId}`
11 }
12
13 if (isNetworkAdmin) {
14 shortcode += ' network=true'
15 }
16
17 for (const option of options) {
18 if (option.checked) {
19 shortcode += ` ${option.value}=true`
20 }
21 }
22
23 shortcode += ']'
24
25 const scopes = document.querySelector('.html-scopes-list')
26 if (scopes) {
27 const shortcodeScope = scopes.querySelector('.shortcode-tag')
28 if (shortcodeScope) {
29 shortcodeScope.textContent = shortcode
30 }
31 }
32 }
33
34 export const handleContentShortcodeOptions = () => {
35 const options = document.querySelector('.html-shortcode-options')?.getElementsByTagName('input')
36
37 if (options) {
38 for (const option of options) {
39 option.addEventListener('change', () => updateShortcode(options))
40 }
41 }
42 }
43