MCPcopy Create free account
hub / github.com/breck7/scroll / setLoadedDroppedFileHandler

Method setLoadedDroppedFileHandler

external/.scrollLibs.js:24211–24268  ·  view source on GitHub ↗
(callback, helpText = "")

Source from the content-addressed store, hash-verified

24209 document.activeElement.blur()
24210 }
24211 setLoadedDroppedFileHandler(callback, helpText = "") {
24212 const bodyStumpParticle = this.getBodyStumpParticle()
24213 const bodyShadow = bodyStumpParticle.getShadow()
24214 // Added the below to ensure dragging from the chrome downloads bar works
24215 // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar
24216 const handleChromeBug = event => {
24217 const originalEvent = event.originalEvent
24218 const effect = originalEvent.dataTransfer.effectAllowed
24219 originalEvent.dataTransfer.dropEffect = effect === "move" || effect === "linkMove" ? "move" : "copy"
24220 }
24221 const dragoverHandler = event => {
24222 handleChromeBug(event)
24223 event.preventDefault()
24224 event.stopPropagation()
24225 if (!bodyStumpParticle.stumpParticleHasClass("dragOver")) {
24226 bodyStumpParticle.insertChildParticle(`div ${helpText}
24227 id dragOverHelp`)
24228 bodyStumpParticle.addClassToStumpParticle("dragOver")
24229 // Add the help, and then hopefull we'll get a dragover event on the dragOverHelp, then
24230 // 50ms later, add the dragleave handler, and from now on drag leave will only happen on the help
24231 // div
24232 setTimeout(function () {
24233 bodyShadow.onShadowEvent(BrowserEvents.dragleave, dragleaveHandler)
24234 }, 50)
24235 }
24236 }
24237 const dragleaveHandler = event => {
24238 event.preventDefault()
24239 event.stopPropagation()
24240 bodyStumpParticle.removeClassFromStumpParticle("dragOver")
24241 bodyStumpParticle.findStumpParticleByChild("id dragOverHelp").removeStumpParticle()
24242 bodyShadow.offShadowEvent(BrowserEvents.dragleave, dragleaveHandler)
24243 }
24244 const dropHandler = async event => {
24245 event.preventDefault()
24246 event.stopPropagation()
24247 bodyStumpParticle.removeClassFromStumpParticle("dragOver")
24248 bodyStumpParticle.findStumpParticleByChild("id dragOverHelp").removeStumpParticle()
24249 const droppedItems = event.originalEvent.dataTransfer.items
24250 // NOTE: YOU NEED TO STAY IN THE "DROP" EVENT, OTHERWISE THE DATATRANSFERITEMS MUTATE
24251 // (BY DESIGN) https://bugs.chromium.org/p/chromium/issues/detail?id=137231
24252 // DO NOT ADD AN AWAIT IN THIS LOOP. IT WILL BREAK.
24253 const items = []
24254 for (let droppedItem of droppedItems) {
24255 const entry = droppedItem.webkitGetAsEntry()
24256 items.push(this._handleDroppedEntry(entry))
24257 }
24258 const results = await Promise.all(items)
24259 callback(results)
24260 }
24261 bodyShadow.onShadowEvent(BrowserEvents.dragover, dragoverHandler)
24262 bodyShadow.onShadowEvent(BrowserEvents.drop, dropHandler)
24263 // todo: why do we do this?
24264 bodyShadow.onShadowEvent(BrowserEvents.dragenter, function (event) {
24265 event.preventDefault()
24266 event.stopPropagation()
24267 })
24268 }

Callers

nothing calls this directly

Calls 3

getBodyStumpParticleMethod · 0.80
getShadowMethod · 0.80
onShadowEventMethod · 0.45

Tested by

no test coverage detected