Added copy on click to textarea in signup form embed modal

no issue
This commit is contained in:
Simon Backx 2023-06-02 16:31:30 +02:00
parent fc5af7e7f8
commit d4f82f8b88
2 changed files with 20 additions and 2 deletions

View File

@ -58,6 +58,7 @@
@class="gh-input gh-signup-form-embed-code-input"
@value={{this.generatedCode}}
readonly
{{on "mouseup" this.copyTextOnMouseUp}}
/>
<p>Copy and paste this HTML code somewhere inside the <code>&lt;body&gt;</code> tag of your site.</p>
</div>

View File

@ -137,14 +137,31 @@ export default class SignupFormEmbedModal extends Component {
return code;
}
@task
*copyText() {
doCopy() {
// Copy this.generatedCode tp the clipboard
const el = document.getElementById('gh-signup-form-embed-code-input');
el.select();
document.execCommand('copy');
}
/**
* Calling this task will make the button green, so avoid using if you don't want that
*/
@task
*copyText() {
// Copy this.generatedCode tp the clipboard
this.doCopy();
yield true;
return true;
}
@action
copyTextOnMouseUp() {
// Check if there is no current text selection anywhere on the page, otherwise skip copying
// This is so users can still select text manually without copying automatically
if (window.getSelection().toString() === '') {
this.doCopy();
}
}
}