Adding event handlers for receiving files to upload
We can use the init()
method that we added in the last task to attach the event handlers that our widget will need to handle files being selected for upload. This may happen either when files are dropped onto the drop target, or when they are selected using the button.
Engage Thrusters
Directly after appending the new HTML elements to the container at the end of the init()
method in uploader.js
(but still within the init()
method), add the following code:
widget.el.on("click", "a.up-choose", function(e) { e.preventDefault(); widget.el.find("input[type='file']").click(); }); widget.el.on("drop change dragover", "article.up", function(e) { if (e.type === "dragover") { e.preventDefault(); e.stopPropagation(); return false; } else if (e.type === "drop") { e.preventDefault(); e.stopPropagation(); widget.files = e.originalEvent.dataTransfer.files; } else { widget...