MCPcopy Create free account
hub / github.com/arfct/itty-bitty / handleDrop

Function handleDrop

docs/edit.js:151–182  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

149}
150
151async function handleDrop(e) {
152 console.log("drop", e)
153 e.preventDefault();
154 if (e.dataTransfer.files) {
155 let file = e.dataTransfer.files[0];
156 let extension = file.name.split(".").pop();
157 let reader = new FileReader();
158 reader.addEventListener(
159 "load",
160 async function() {
161 var url = reader.result;
162 let durl = new bitty.DataURL(url);
163 if (durl.mediatype == "application/octet-stream") {
164 durl.mediatype = "application/" + extension;
165 }
166 console.log(durl.mediatype)
167 durl = await durl.compress(bitty.GZIP_MARKER);
168 let ratio = durl.href.length / url.length;
169 console.log(`Compressed from ${url.length} to ${durl.href.length} bytes (${Math.round(ratio * 100)}%)`);
170
171 if (ratio <= 0.95) url = durl.href;
172 importedFileData = url;
173 updateLink(url, {title:file.name}, true);
174 setFileName(file.name);
175
176 },
177 false
178 );
179 reader.readAsDataURL(file);
180 }
181 document.body.classList.remove("dragging");
182}
183
184// TODO Command+Shift+T for title (H1), Command+Shift+H for headline (H2), Command+Shift+B for body text (remove any of the above)
185function handleKey(e) {

Callers

nothing calls this directly

Calls 2

updateLinkFunction · 0.70
setFileNameFunction · 0.70

Tested by

no test coverage detected