PluginProbe
Code Snippets / 3.6.6
Code Snippets v3.6.6
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 / services / manage / cloud.ts

cloud.ts in Code Snippets 3.6.6, at js/services/manage/cloud.ts

46 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import Prism from 'prismjs'
2 import 'prismjs/components/prism-clike'
3 import 'prismjs/components/prism-javascript'
4 import 'prismjs/components/prism-css'
5 import 'prismjs/components/prism-php'
6 import 'prismjs/components/prism-markup'
7 import 'prismjs/plugins/keep-markup/prism-keep-markup'
8
9 /**
10 * Handle clicks on snippet preview button.
11 */
12 export const handleShowCloudPreview = () => {
13 const previewButtons = document.querySelectorAll('.cloud-snippet-preview')
14
15 previewButtons.forEach(button => {
16 button.addEventListener('click', () => {
17 const snippetId = button.getAttribute('data-snippet')
18 const snippetLanguage = button.getAttribute('data-lang')
19
20 const snippetCodeInput = <HTMLInputElement | null> document.getElementById(`cloud-snippet-code-${snippetId}`)
21 const snippetCodeModalTag = document.getElementById('snippet-code-thickbox')
22
23 if (!snippetCodeModalTag || !snippetCodeInput) {
24 return
25 }
26
27 snippetCodeModalTag.classList.remove(...snippetCodeModalTag.classList)
28 snippetCodeModalTag.classList.add(`language-${snippetLanguage}`)
29 snippetCodeModalTag.textContent = snippetCodeInput.value
30
31 if ('markup' === snippetLanguage) {
32 snippetCodeModalTag.innerHTML = `<xmp>${snippetCodeInput.value}</xmp>`
33 }
34
35 if ('php' === snippetLanguage) {
36 // Check if there is an opening php tag if not add it.
37 if (!snippetCodeInput.value.startsWith('<?php')) {
38 snippetCodeModalTag.textContent = `<?php\n${snippetCodeInput.value}`
39 }
40 }
41
42 Prism.highlightElement(snippetCodeModalTag)
43 })
44 })
45 }
46