PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.6.0
Code Block Pro – Beautiful Syntax Highlighting v1.6.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / front / front.js

front.js in Code Block Pro – Beautiful Syntax Highlighting 1.6.0, at src/front/front.js

44 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import copy from 'copy-to-clipboard';
2
3 // Handle copy button
4 addEventListener('DOMContentLoaded', () => {
5 const buttons = Array.from(
6 document.querySelectorAll('.code-block-pro-copy-button'),
7 );
8 buttons.forEach((button) => {
9 // Setting it to block here lets users deactivate the plugin safely
10 button.style.display = 'block';
11 button.addEventListener('click', (event) => {
12 const b = event.target?.closest('span');
13 copy(b?.dataset?.code ?? '', {
14 format: 'text/plain',
15 });
16 b.classList.add('copying');
17 setTimeout(() => {
18 b.classList.remove('copying');
19 }, 2000);
20 });
21 });
22 });
23
24 // Handle font loading
25 addEventListener('DOMContentLoaded', () => {
26 if (!window.codeBlockPro?.pluginUrl) return;
27 const fontsToLoad = new Set(
28 Array.from(
29 document.querySelectorAll('[data-code-block-pro-font-family]') ??
30 [],
31 )
32 .map((f) => f.dataset.codeBlockProFontFamily)
33 .filter(Boolean),
34 );
35 [...fontsToLoad].forEach(async (fontName) => {
36 const font = new FontFace(
37 fontName,
38 `url(${window.codeBlockPro.pluginUrl}/build/fonts/${fontName}.woff2)`,
39 );
40 await font.load();
41 document.fonts.add(font);
42 });
43 });
44