From 2fa13de5fa2327d2206bd4f420f264079e4c476c Mon Sep 17 00:00:00 2001
From: edbrz9 <ed@brz9.devd>
Date: Sat, 31 Dec 2022 21:31:15 +0100
Subject: [PATCH] copyme component added to js

---
 assets/js/ed.brz9.js | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/assets/js/ed.brz9.js b/assets/js/ed.brz9.js
index 202a9b9..eb22eaa 100644
--- a/assets/js/ed.brz9.js
+++ b/assets/js/ed.brz9.js
@@ -1,4 +1,36 @@
-
+Vue.component('copyme', {
+  template: `
+    <section class="copyme-containter" v-on:click="copyToClipboard">
+      <span class="copypopup" v-bind:class="{ 'success': isCopied}" ref="element">Copied!</span>
+      <section class="copyme" ref="copyThis">
+        <slot></slot>
+      </section>
+    </section>
+  `,
+  data() {
+    return {
+      isCopied: false
+    }
+  },
+  methods : {
+    copyToClipboard() {
+      const textToCopy = this.$refs.copyThis;
+      const range = document.createRange();
+      range.selectNode(textToCopy);
+      window.getSelection().removeAllRanges();
+      window.getSelection().addRange(range);
+      document.execCommand('copy');
+      window.getSelection().removeAllRanges();
+      this.copyDone();     
+    },
+    copyDone(){
+      this.isCopied = true;
+      this.$refs.element.addEventListener('animationend', () => {
+        this.isCopied = false;
+      });
+    }
+  }
+})
 
 Vue.component('ppbut' ,{
   template : `