-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
65 lines (62 loc) · 2.64 KB
/
demo.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Popup Share Modal | CodingNepal</title>
<link rel="stylesheet" href="demo.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v3.0.6/css/line.css">
</head>
<body>
<button class="view-modal">View Modal</button>
<div class="popup">
<header>
<span>Share Modal</span>
<div class="close"><i class="uil uil-times"></i></div>
</header>
<div class="content">
<p>Share this link via</p>
<ul class="icons">
<a href="https://www.facebook.com/sharer/sharer.php?u=example.com/share-link" target="_blank"><i class="fab fa-facebook-f"></i></a> <!-- Update the URL -->
<a href="https://twitter.com/intent/tweet?url=example.com/share-link&text=Check%20this%20out!" target="_blank"><i class="fab fa-twitter"></i></a> <!-- Update the URL -->
<a href="https://www.instagram.com/" target="_blank"><i class="fab fa-instagram"></i></a> <!-- Instagram does not have direct URL sharing, use the profile link -->
<a href="https://api.whatsapp.com/send?text=example.com/share-link" target="_blank"><i class="fab fa-whatsapp"></i></a> <!-- Update the URL -->
<a href="https://t.me/share/url?url=example.com/share-link&text=Check%20this%20out!" target="_blank"><i class="fab fa-telegram-plane"></i></a> <!-- Update the URL -->
</ul>
<p>Or copy link</p>
<div class="field">
<i class="url-icon uil uil-link"></i>
<input type="text" readonly value="example.com/share-link"> <!-- Update the link -->
<button>Copy</button>
</div>
</div>
</div>
<script>
const viewBtn = document.querySelector(".view-modal"),
popup = document.querySelector(".popup"),
close = popup.querySelector(".close"),
field = popup.querySelector(".field"),
input = field.querySelector("input"),
copy = field.querySelector("button");
viewBtn.onclick = ()=>{
popup.classList.toggle("show");
}
close.onclick = ()=>{
viewBtn.click();
}
copy.onclick = ()=>{
input.select(); //select input value
if(document.execCommand("copy")){ //if the selected text copy
field.classList.add("active");
copy.innerText = "Copied";
setTimeout(()=>{
window.getSelection().removeAllRanges(); //remove selection from document
field.classList.remove("active");
copy.innerText = "Copy";
}, 3000);
}
}
</script>
</body>
</html>