Skip to content

Commit b4c3ea9

Browse files
committed
share feature done
1 parent d4c0ccb commit b4c3ea9

6 files changed

Lines changed: 48 additions & 24 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Edit Pad is an easy and clean Online text editor and note taking tool. Take note
1515
### Customizable
1616
- Theme can be customize as per your choice.
1717

18+
### Easy share
19+
- Share your content easily.
20+
1821
## Usages
1922
Use online here: https://editpad.shashi.dev
2023

src/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ a:visited {
198198
}
199199

200200
.tooltip .bottom {
201-
min-width: 250px;
201+
min-width: 280px;
202202
/*max-width:400px;*/
203203
top: 40px;
204204
left: 50%;

src/images/share.png

16.2 KB
Loading

src/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@
7676
🌓 Day/Night
7777
</button>
7878
<div id="tooltip" class="tooltip">
79-
<button id="share" class="header-button" onclick="share()">Share</button>
79+
<button id="share" class="header-button share-button" onclick="share()"><img width="12px" height="12px" src="images/share.png"></img> Share</button>
8080
<div id="bottom" class="bottom">
81-
<h3>Share a link of this snippet</h3>
81+
<h3>Share a link of this snippet [BETA]</h3>
8282
<input type="text" id="shareLink" class="input"></input>
83-
<div style="display: flex; justify-content: space-between;">
83+
<div class="share-div" style="display: flex; justify-content: space-between;">
8484
<button class="shareLinkButton" onclick="copyToClipboard()">
8585
Copy Link
8686
</button>
87-
<span id="copied" class="copied">Copied!</span>
87+
<span id="copied" class="copied">Copied!!!</span>
8888
</div>
8989

9090
<i></i>
@@ -203,6 +203,7 @@ <h3>Share a link of this snippet</h3>
203203

204204
document.getElementById("closeFullScreen").style.display = "none";
205205
setCleanRequired(1);
206+
setContent();
206207
getRandomQuote();
207208
checkDarkMode();
208209
printConsoleArt();

src/js/main.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,11 @@ function resizeText(multiplier) {
134134
document.getElementById("text").style.fontSize = parseFloat(document.getElementById("text").style.fontSize) + (multiplier * 0.2) + "em";
135135
}
136136

137-
function printConsoleArt() {
138-
const consoleStr = `
139-
███████ ██████  ██ ████████ ██████  █████  ██████ 
140-
██      ██   ██ ██    ██    ██   ██ ██   ██ ██   ██ 
141-
█████  ██  ██ ██  ██  ██████  ███████ ██  ██ 
142-
██     ██  ██ ██  ██  ██      ██   ██ ██  ██ 
143-
███████ ██████  ██  ██  ██  ██  ██ ██████  
144-
                                          
145-
146-
Github: https://github.com/shweshi/editpad
147-
`
148-
console.log(consoleStr);
149-
}
150-
151137
// Close the dropdown menu if the user clicks outside of it
152138
window.onclick = function (event) {
153-
if (event.target.matches('.font') || event.target.matches('.color-button')) {
139+
if (event.target.matches('.font') || event.target.matches('.color-button') || event.target.matches('.share-button') || event.target.matches('.bottom')
140+
|| event.target.matches('.input') || event.target.matches('.shareLinkButton') || event.target.matches('h3') || event.target.matches('.share-div')
141+
|| event.target.matches('.copied')) {
154142
event.stopPropagation();
155143
} else {
156144
if (!event.target.matches('.dropbtn')) {
@@ -163,6 +151,10 @@ window.onclick = function (event) {
163151
}
164152
}
165153
}
154+
155+
if (!event.target.matches('.share-button')) {
156+
document.getElementById('bottom').style.display = 'none';
157+
}
166158
}
167159
}
168160

@@ -171,7 +163,7 @@ function share() {
171163
if (tooltip.style.display != 'block') {
172164
tooltip.style.display = 'block';
173165
const input = document.getElementById('shareLink');
174-
input.value = 'https://editpad.org?content=' + getEncodedContent();
166+
input.value = 'https://editpad.shashi.dev?content=' + getEncodedContent();
175167
input.select();
176168
} else {
177169
tooltip.style.display = 'none';
@@ -180,11 +172,11 @@ function share() {
180172

181173
function getEncodedContent() {
182174
const content = document.getElementById("text").value;
183-
return btoa(content);
175+
return window.btoa(content);
184176
}
185177

186178
function copyToClipboard() {
187-
const content = document.getElementById("text");
179+
const content = document.getElementById("shareLink");
188180

189181
content.select();
190182
content.setSelectionRange(0, 99999); /* For mobile devices */
@@ -196,4 +188,32 @@ function copyToClipboard() {
196188
} else {
197189
copied.style.display = 'none';
198190
}
191+
}
192+
193+
function setContent() {
194+
let params = (new URL(document.location)).searchParams;
195+
let content = params.get("content");
196+
if (content) {
197+
let textarea = document.querySelector('textarea')
198+
199+
text = window.atob(content);
200+
textarea.value = text;
201+
setCleanRequired(0);
202+
}
203+
}
204+
205+
function printConsoleArt() {
206+
const consoleStr = `
207+
███████ ██████  ██ ████████ ██████  █████  ██████ 
208+
██      ██   ██ ██    ██    ██   ██ ██   ██ ██   ██ 
209+
█████  ██  ██ ██  ██  ██████  ███████ ██  ██ 
210+
██     ██  ██ ██  ██  ██      ██   ██ ██  ██ 
211+
███████ ██████  ██  ██  ██  ██  ██ ██████  
212+
                                          
213+
214+
Github: https://github.com/shweshi/editpad
215+
216+
Version: 1.0.1
217+
`
218+
console.log(consoleStr);
199219
}

src/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var cacheName = 'editpad-v1';
1+
var cacheName = 'editpad-v2';
22
var filesToCache = [
33
'/',
44
'/index.html',

0 commit comments

Comments
 (0)