-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to paste images into the website (#27)
* Create imagepaste.ts Like DragDrop but allows you to paste an image * Update avatarcropper.ts Allow an image to be pasted with the ImagePasted class * Update imagepaste.ts * Renaming and slight modification Renamed the file for better consistency, also fixed a small mistake * Renaming a file
- Loading branch information
1 parent
7c4675d
commit 13b6c2a
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { hideElement } from "./util"; | ||
import { EventClass } from "./eventclass"; | ||
|
||
export class ImagePasted extends EventClass { | ||
private tempText: string = null; | ||
|
||
constructor(overlay: HTMLElement) { | ||
super(); | ||
|
||
let imgpasted = this; // Setting "imgpasted" to "this" so that we can use it in the onpaste and other events, since "this" would mean something else there. | ||
|
||
imgpasted.createEvent("imagepasted"); | ||
|
||
document.onpaste = function (e) { | ||
|
||
var files: FileList = (e.clipboardData).files; // Check to see if there are files in the clipboard data | ||
|
||
if (files.length) { // If there are files, paste the first file. | ||
let file: File = files[0]; | ||
if (!file?.type.includes("image")) return; // If it's not an image, return. | ||
imgpasted.emitEvent("imagepasted", files[0]) | ||
} | ||
|
||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
hideElement(overlay); | ||
overlay.innerText = imgpasted.tempText; | ||
overlay.style.zIndex = ""; | ||
imgpasted.tempText = null; | ||
|
||
}; | ||
} | ||
} |