Skip to content

Commit 386a2fb

Browse files
author
Basu Jindal
committed
add option to paste image
1 parent ecc73a0 commit 386a2fb

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,15 @@ Move to `/blogs/` when ready to publish.
100100

101101
## To Do
102102

103-
- [ ] Add like and comment option to blogs similar to thoughts but allow anonymous or github login
103+
- [ ] Move logout button to the bottom
104+
- [ ] Login at blog return no blog selected nad login is not successful
105+
- [ ] Update comments UI
104106
- [ ] Visit count for all pages (blogs, thoughts, diffchecker, photos) on login just visible to basujindal
107+
- [ ] Display the blog posts and like and views in admin portal
108+
- [ ] Show full preview
109+
- [ ] Make blog like not anon?
110+
- [ ] Check how multiple images are posted
111+
- [ ] Split large files into smaller, eespcially thoughts.js and any files greater than 500 lines
105112
- [ ] Keep deleted posts and edit history for thoughts just in database
106-
- [ ] No need to display exact time on hover on post in thoughts, just date is good
107-
113+
- [x] Add like and comment option to blogs similar to thoughts but allow anonymous or github login
114+
- [x] No need to display exact time on hover on post in thoughts, just date is good

js/thoughts.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@
159159
imageInput.addEventListener('change', handleImageSelect);
160160
}
161161

162+
if (composeTextarea) {
163+
composeTextarea.addEventListener('paste', handlePaste);
164+
}
165+
162166
if (lightbox) {
163167
lightbox.addEventListener('click', (e) => {
164168
if (e.target === lightbox || e.target.classList.contains('image-lightbox-close')) {
@@ -973,8 +977,34 @@
973977
// Handle image selection
974978
function handleImageSelect(e) {
975979
const files = Array.from(e.target.files);
976-
const MAX_FILE_SIZE = 20 * 1024 * 1024;
980+
processImageFiles(files);
981+
e.target.value = '';
982+
}
977983

984+
// Handle paste event for images
985+
function handlePaste(e) {
986+
const items = e.clipboardData?.items;
987+
if (!items) return;
988+
989+
const files = [];
990+
for (const item of items) {
991+
if (item.type.startsWith('image/')) {
992+
const file = item.getAsFile();
993+
if (file) {
994+
files.push(file);
995+
}
996+
}
997+
}
998+
999+
if (files.length > 0) {
1000+
e.preventDefault();
1001+
processImageFiles(files);
1002+
}
1003+
}
1004+
1005+
// Process image files (shared by file input and paste)
1006+
function processImageFiles(files) {
1007+
const MAX_FILE_SIZE = 20 * 1024 * 1024;
9781008
const remaining = 4 - selectedImages.length;
9791009
const newFiles = files.slice(0, remaining);
9801010

@@ -994,7 +1024,6 @@
9941024
});
9951025

9961026
updateSubmitButton();
997-
e.target.value = '';
9981027
}
9991028

10001029
// Add image preview

thoughts-api

0 commit comments

Comments
 (0)