| 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 |
|