Skip to content

Commit

Permalink
Support multi onload event (#5)
Browse files Browse the repository at this point in the history
* use addEventListener for multiple onload event

* 0.0.9
  • Loading branch information
kudoh authored May 19, 2022
1 parent 3ac9041 commit 8034547
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function initClipboardJS(options) {
throw minified.error;
}
return `<script>${minified.code}</script>
<script async src="https://cdn.jsdelivr.net/npm/clipboard@${options.clipboardJSVersion}/dist/clipboard.js">${minified.code}</script>`;
<script async src="https://cdn.jsdelivr.net/npm/clipboard@${options.clipboardJSVersion}/dist/clipboard.js"></script>`;
}

module.exports = {
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.idea
example/node_modules
example/_site
example/_site

*.iml
4 changes: 2 additions & 2 deletions init-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ function showTooltip(el, msg) {
}
}

window.onload = () => {
window.addEventListener('load', () => {
const clipboard = new ClipboardJS(''); // replaced by plugin
clipboard.on('success', (el) => showTooltip(el, 'Copied!'));
clipboard.on('error', (el) => showTooltip(el, 'Failed...'));
};
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eleventy-plugin-code-clipboard",
"version": "0.0.8",
"version": "0.0.9",
"description": "eleventy plugin to copy fence into clipboard",
"homepage": "https://github.com/mamezou-tech/eleventy-plugin-code-clipboard",
"main": ".eleventy.js",
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`clipboard.js initialization custom plugin config 1`] = `
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".test-button\\");o.on(\\"success\\",o=>showTooltip(o,\\"Success!!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failure!!\\"))};</script>
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\">function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".test-button\\");o.on(\\"success\\",o=>showTooltip(o,\\"Success!!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failure!!\\"))};</script>"
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.addEventListener(\\"load\\",()=>{const o=new ClipboardJS(\\".test-button\\");o.on(\\"success\\",o=>showTooltip(o,\\"Success!!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failure!!\\"))});</script>
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\"></script>"
`;
exports[`clipboard.js initialization default plugin config 1`] = `
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".code-copy\\");o.on(\\"success\\",o=>showTooltip(o,\\"Copied!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failed...\\"))};</script>
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\">function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.onload=()=>{const o=new ClipboardJS(\\".code-copy\\");o.on(\\"success\\",o=>showTooltip(o,\\"Copied!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failed...\\"))};</script>"
"<script>function showTooltip(o,e){o.trigger.className.includes(\\"tooltipped\\")||(o.trigger.children[0].className=\\"tooltipped tooltipped-s\\",o.trigger.children[0].ariaLabel=e)}window.addEventListener(\\"load\\",()=>{const o=new ClipboardJS(\\".code-copy\\");o.on(\\"success\\",o=>showTooltip(o,\\"Copied!\\")),o.on(\\"error\\",o=>showTooltip(o,\\"Failed...\\"))});</script>
<script async src=\\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.js\\"></script>"
`;
exports[`custom renderer custom renderer config 1`] = `
Expand Down

0 comments on commit 8034547

Please sign in to comment.