Skip to content

Commit 26ebc46

Browse files
hanzhenfengMrCoder
authored andcommitted
Copy png to clipboard:
test for safari copy by button
1 parent 5a4d86c commit 26ebc46

File tree

1 file changed

+9
-55
lines changed

1 file changed

+9
-55
lines changed

src/components/ContentWrap.jsx

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -469,38 +469,6 @@ export default class ContentWrap extends Component {
469469
trackEvent('ui', 'copyPng');
470470
}
471471

472-
async copyPngClickHandlerBySafari1(e) {
473-
console.log(e);
474-
navigator.clipboard.write([
475-
new ClipboardItem({
476-
"image/png": new Promise(async resolve => {
477-
const response = await fetch("https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png");
478-
resolve(await response.blob());
479-
})
480-
})
481-
]).then(
482-
r => console.log("success", r),
483-
reason => console.log("failed", reason)
484-
);
485-
}
486-
487-
async copyPngClickHandlerBySafari2(e) {
488-
console.log(e);
489-
const mountingPoint = this.frame.contentWindow.document.getElementById('diagram');
490-
// eslint-disable-next-line
491-
const png = await mountingPoint.getElementsByClassName('frame')[0].parentElement.__vue__.toBlob();
492-
navigator.clipboard.write([
493-
new ClipboardItem({
494-
"image/png": new Promise(async resolve => {
495-
resolve(png);
496-
})
497-
})
498-
]).then(
499-
r => console.log("success", r),
500-
reason => console.log("failed", reason)
501-
);
502-
}
503-
504472
async copyPngClickHandlerBySafari3(e) {
505473
console.log(e);
506474
const mountingPoint = this.frame.contentWindow.document.getElementById('diagram');
@@ -516,23 +484,7 @@ export default class ContentWrap extends Component {
516484
r => console.log("success", r),
517485
reason => console.log("failed", reason)
518486
);
519-
}
520-
521-
async copyPngClickHandlerBySafari4(e) {
522-
console.log(e);
523-
const mountingPoint = this.frame.contentWindow.document.getElementById('diagram');
524-
// eslint-disable-next-line
525-
navigator.clipboard.write([
526-
new ClipboardItem({
527-
"image/png": new Promise(async resolve => {
528-
const png = await mountingPoint.getElementsByClassName('frame')[0].parentElement.__vue__.toBlob();
529-
resolve(await png);
530-
})
531-
})
532-
]).then(
533-
r => console.log("success", r),
534-
reason => console.log("failed", reason)
535-
);
487+
trackEvent('ui', 'copyPng');
536488
}
537489

538490
copyPngToClipboard(imageData) {
@@ -1142,16 +1094,18 @@ export default class ContentWrap extends Component {
11421094
</Button>
11431095
<Button
11441096
className="btn--dark button icon-button hint--rounded hint--bottom-left"
1145-
aria-label="Copy PNG on Clipboard"
1097+
aria-label="Copy PNG to Clipboard"
11461098
onClick={this.copyPngClickHandler.bind(this)}>
11471099
<span class="material-symbols-outlined">file_copy</span>
1100+
<span>Copy PNG File By Chrome</span>
1101+
</Button>
1102+
<Button
1103+
className="btn--dark button icon-button hint--rounded hint--bottom-left"
1104+
aria-label="Copy PNG to Clipboard"
1105+
onClick={this.copyPngClickHandlerBySafari3.bind(this)}>
1106+
<span class="material-symbols-outlined">file_copy</span>
11481107
<span>Copy PNG File</span>
11491108
</Button>
1150-
<a onClick={this.copyPngClickHandlerBySafari1.bind(this)}>test1</a>
1151-
<a onClick={this.copyPngClickHandlerBySafari2.bind(this)}>test2</a>
1152-
<a onClick={this.copyPngClickHandlerBySafari3.bind(this)}>test3</a>
1153-
<a onClick={this.copyPngClickHandlerBySafari4.bind(this)}>test4</a>
1154-
<a id="a-test">just-a</a>
11551109
</div>
11561110
</div>
11571111
)}

0 commit comments

Comments
 (0)