Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong preventDefault #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ <h2 id="basic-text">Basic text copy</h2>
</div>
</div>
<hr>
<div class="container">
<h2 id="copy-with-callback">Copy with callback</h2>
<textarea disabled class="code half">copyToClipboard("Copy with callback", { onCopy: noop })</textarea>
<div class="half">
<button data-test="init-copy-with-callback">Click to copy sample text</button>
</div>
</div>
<hr>
<div class="container">
<h2 id="multiline-text">Multiline text copy</h2>
<textarea disabled class="code half">
Expand Down Expand Up @@ -45,6 +53,18 @@ <h2 id="multiline-markup">Markup + text copy</h2>
.addEventListener('click', function () {
copyToClipboard("Hello, I'm new content from your clipboard")
});
(function() {
var container = document.querySelector('#copy-with-callback + textarea');
var noop = function noop() {
// do nothing
};
document.querySelector('#copy-with-callback ~ .half button')
.addEventListener('click', function () {
copyToClipboard(container.textContent, {
onCopy: noop,
})
})
})();
(function() {
var multilineContainer = document.querySelector('#multiline-text + textarea');
document.querySelector('#multiline-text ~ .half button')
Expand Down
2 changes: 1 addition & 1 deletion example/index.js

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

1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function copy(text, options) {
}
}
if (options.onCopy) {
e.preventDefault();
options.onCopy(e.clipboardData);
}
});
Expand Down
12 changes: 12 additions & 0 deletions tests/02_copy-with-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
module.exports = {
'Copy With Callback' : function (browser) {
browser
.page.helper().resetBuffer()
.url(browser.launchUrl)
.waitForElementVisible('[data-test="init-copy-with-callback"]', 1000)
.click('[data-test="init-copy-with-callback"]')
.assert.assertBuffer("copyToClipboard(\"Copy with callback\", { onCopy: noop })")
.end();
}
};