diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 8c0c7d7a5..428884669 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -326,13 +326,9 @@ BlazeComponent.extendComponent({ 'click .js-copy-link'(event) { event.preventDefault(); const promise = Utils.copyTextToClipboard(event.target.href); - if (promise) { - promise.then(() => { - const $tooltip = this.$('span.copied-tooltip'); - $tooltip.show(100); - setTimeout(() => $tooltip.hide(100), 1000); - }); - } + + const $tooltip = this.$('.copied-tooltip'); + Utils.showCopied(promise, $tooltip); }, 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'), 'submit .js-card-description'(event) { @@ -1076,13 +1072,9 @@ BlazeComponent.extendComponent({ { 'click .js-copy-card-link-to-clipboard'(event) { const promise = Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value); - if (promise) { - promise.then(() => { - const $tooltip = this.$('.copied-tooltip'); - $tooltip.show(100); - setTimeout(() => $tooltip.hide(100), 1000); - }); - } + + const $tooltip = this.$('.copied-tooltip'); + Utils.showCopied(promise, $tooltip); }, 'click .js-delete': Popup.afterConfirm('cardDelete', function () { Popup.close(); diff --git a/client/components/main/editor.js b/client/components/main/editor.js index bfcf3240a..fec040a23 100644 --- a/client/components/main/editor.js +++ b/client/components/main/editor.js @@ -289,15 +289,9 @@ BlazeComponent.extendComponent({ 'click a.fa.fa-copy'(event) { const $editor = this.$('textarea.editor'); const promise = Utils.copyTextToClipboard($editor[0].value); - if (promise) { - promise.then(() => { - const $tooltip = this.$('.copied-tooltip'); - $tooltip.show(100); - setTimeout(() => $tooltip.hide(100), 1000); - }, (err) => { - console.error("error: ", err); - }); - } + + const $tooltip = this.$('.copied-tooltip'); + Utils.showCopied(promise, $tooltip); }, } ] diff --git a/client/lib/utils.js b/client/lib/utils.js index 4bf1ccc20..eb53a6a4c 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -506,6 +506,21 @@ Utils = { } return ret; }, + + /** show the "copied!" message + * @param promise the promise of Utils.copyTextToClipboard + * @param $tooltip jQuery tooltip element + */ + showCopied(promise, $tooltip) { + if (promise) { + promise.then(() => { + $tooltip.show(100); + setTimeout(() => $tooltip.hide(100), 1000); + }, (err) => { + console.error("error: ", err); + }); + } + }, }; // A simple tracker dependency that we invalidate every time the window is