-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock.js
41 lines (37 loc) · 1.1 KB
/
block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
polarity.export = PolarityComponent.extend({
details: Ember.computed.alias('block.data.details'),
uniqueIdPrefix: '',
init() {
let array = new Uint32Array(5);
this.set('uniqueIdPrefix', window.crypto.getRandomValues(array).join(''));
this._super(...arguments);
},
actions: {
copyData: function () {
Ember.run.scheduleOnce(
'afterRender',
this,
this.copyElementToClipboard,
`email-container-${this.get('uniqueIdPrefix')}`
);
Ember.run.scheduleOnce('destroy', this, this.restoreCopyState);
}
},
copyElementToClipboard(element) {
window.getSelection().removeAllRanges();
let range = document.createRange();
range.selectNode(typeof element === 'string' ? document.getElementById(element) : element);
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
},
restoreCopyState() {
this.set('showCopyMessage', true);
setTimeout(() => {
if (!this.isDestroyed) {
this.set('showCopyMessage', false);
}
}, 2000);
}
});