From a3463a6ac1086edeb1cf91f94565fd42fc566455 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 5 Sep 2019 16:16:52 +0530 Subject: [PATCH] :sparkles: Added native share feature --- pages/index.vue | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index ef56a3974..08d3e66a5 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -690,14 +690,24 @@ } }, copyRequest() { - this.$refs.copyRequest.innerHTML = this.copiedButton + 'Copied'; - var dummy = document.createElement('input'); - document.body.appendChild(dummy); - dummy.value = window.location.href; - dummy.select(); - document.execCommand('copy'); - document.body.removeChild(dummy); - setTimeout(() => this.$refs.copyRequest.innerHTML = this.copyButton + 'Share URL', 1500) + if (navigator.share) { + navigator.share({ + title: document.title, + url: window.location.href + }).then(() => { + // console.log('Thanks for sharing!'); + }) + .catch(console.error); + } else { + this.$refs.copyRequest.innerHTML = this.copiedButton + 'Copied'; + var dummy = document.createElement('input'); + document.body.appendChild(dummy); + dummy.value = window.location.href; + dummy.select(); + document.execCommand('copy'); + document.body.removeChild(dummy); + setTimeout(() => this.$refs.copyRequest.innerHTML = this.copyButton + 'Share URL', 1500) + } }, copyRequestCode() { this.$refs.copyRequestCode.innerHTML = this.copiedButton + 'Copied';