Show a "copied!" tooltip after successfull URL copy

This commit is contained in:
Martin Filser 2021-11-18 18:39:46 +01:00
parent ed53065a09
commit 4bfa727e9e
5 changed files with 46 additions and 6 deletions

View file

@ -22,6 +22,7 @@ template(name="cardDetails")
title="{{_ 'copy-card-link-to-clipboard'}}" title="{{_ 'copy-card-link-to-clipboard'}}"
href="{{ originRelativeUrl }}" href="{{ originRelativeUrl }}"
) )
span.copied-tooltip {{_ 'copied'}}
else else
unless isPopup unless isPopup
a.fa.fa-times-thin.close-card-details.js-close-card-details(title="{{_ 'close-card'}}") a.fa.fa-times-thin.close-card-details.js-close-card-details(title="{{_ 'close-card'}}")
@ -33,6 +34,7 @@ template(name="cardDetails")
title="{{_ 'copy-card-link-to-clipboard'}}" title="{{_ 'copy-card-link-to-clipboard'}}"
href="{{ originRelativeUrl }}" href="{{ originRelativeUrl }}"
) )
span.copied-tooltip {{_ 'copied'}}
h2.card-details-title.js-card-title( h2.card-details-title.js-card-title(
class="{{#if canModifyCard}}js-open-inlined-form is-editable{{/if}}") class="{{#if canModifyCard}}js-open-inlined-form is-editable{{/if}}")
+viewer +viewer
@ -798,6 +800,7 @@ template(name="cardMorePopup")
i.fa.colorful(class="{{#if board.isPublic}}fa-globe{{else}}fa-lock{{/if}}") i.fa.colorful(class="{{#if board.isPublic}}fa-globe{{else}}fa-lock{{/if}}")
input.inline-input(type="text" id="cardURL" readonly value="{{ originRelativeUrl }}" autofocus="autofocus") input.inline-input(type="text" id="cardURL" readonly value="{{ originRelativeUrl }}" autofocus="autofocus")
button.js-copy-card-link-to-clipboard(class="btn" id="clipboard") {{_ 'copy-card-link-to-clipboard'}} button.js-copy-card-link-to-clipboard(class="btn" id="clipboard") {{_ 'copy-card-link-to-clipboard'}}
.copied-tooltip {{_ 'copied'}}
span.clearfix span.clearfix
br br
h2 {{_ 'change-card-parent'}} h2 {{_ 'change-card-parent'}}

View file

@ -325,7 +325,14 @@ BlazeComponent.extendComponent({
}, },
'click .js-copy-link'(event) { 'click .js-copy-link'(event) {
event.preventDefault(); event.preventDefault();
Utils.copyTextToClipboard(event.target.href); const promise = Utils.copyTextToClipboard(event.target.href);
if (promise) {
promise.then(() => {
const $tooltip = this.$('span.copied-tooltip');
$tooltip.css('display', 'inline');
setTimeout(() => $tooltip.css('display', 'none'), 1000);
});
}
}, },
'click .js-open-card-details-menu': Popup.open('cardDetailsActions'), 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
'submit .js-card-description'(event) { 'submit .js-card-description'(event) {
@ -1068,7 +1075,14 @@ BlazeComponent.extendComponent({
return [ return [
{ {
'click .js-copy-card-link-to-clipboard'(event) { 'click .js-copy-card-link-to-clipboard'(event) {
Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value); const promise = Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value);
if (promise) {
promise.then(() => {
const $tooltip = this.$('.copied-tooltip');
$tooltip.css('display', 'inline');
setTimeout(() => $tooltip.css('display', 'none'), 1000);
});
}
}, },
'click .js-delete': Popup.afterConfirm('cardDelete', function () { 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
Popup.close(); Popup.close();

View file

@ -118,7 +118,8 @@ avatar-radius = 50%
.card-copy-button, .card-copy-button,
.card-copy-mobile-button, .card-copy-mobile-button,
.close-card-details-mobile-web, .close-card-details-mobile-web,
.card-details-menu-mobile-web .card-details-menu-mobile-web,
.copied-tooltip
float: right float: right
.close-card-details, .close-card-details,
@ -187,6 +188,14 @@ avatar-radius = 50%
border-radius: 3px border-radius: 3px
padding: 0px 5px padding: 0px 5px
.copied-tooltip
display: none
margin-right: 10px
padding: 10px;
background-color: #000000df;
color: #fff;
border-radius: 5px;
.card-description textarea .card-description textarea
min-height: 100px min-height: 100px
@ -233,6 +242,13 @@ avatar-radius = 50%
.activities .activities
padding-top: 10px padding-top: 10px
.pop-over
.copied-tooltip
display: none
padding: 0px 10px;
background-color: #000000df;
color: #fff;
border-radius: 5px;
@media screen and (min-width: 801px) @media screen and (min-width: 801px)
.card-details-maximized .card-details-maximized
padding: 0 padding: 0

View file

@ -481,6 +481,9 @@ Utils = {
try { try {
document.execCommand('copy'); document.execCommand('copy');
return Promise.resolve(true);
} catch (e) {
return Promise.reject(false);
} finally { } finally {
document.body.removeChild(textArea); document.body.removeChild(textArea);
} }
@ -489,16 +492,19 @@ Utils = {
/** copy the text to the clipboard /** copy the text to the clipboard
* @see https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript/30810322#30810322 * @see https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript/30810322#30810322
* @param string copy this text to the clipboard * @param string copy this text to the clipboard
* @return Promise
*/ */
copyTextToClipboard(text) { copyTextToClipboard(text) {
let ret;
if (navigator.clipboard) { if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(function() { ret = navigator.clipboard.writeText(text).then(function() {
}, function(err) { }, function(err) {
console.error('Async: Could not copy text: ', err); console.error('Async: Could not copy text: ', err);
}); });
} else { } else {
fallbackCopyTextToClipboard(text); ret = Utils.fallbackCopyTextToClipboard(text);
} }
return ret;
}, },
}; };

View file

@ -1122,5 +1122,6 @@
"to-create-organizations-contact-admin": "To create organizations, please contact administrator.", "to-create-organizations-contact-admin": "To create organizations, please contact administrator.",
"custom-legal-notice-link-url": "Custom legal notice page URL", "custom-legal-notice-link-url": "Custom legal notice page URL",
"acceptance_of_our_legalNotice": "By continuing, you accept our", "acceptance_of_our_legalNotice": "By continuing, you accept our",
"legalNotice": "legal notice" "legalNotice": "legal notice",
"copied": "copied!"
} }