Skip to content

Commit

Permalink
Better logic for adding handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyg authored Jun 17, 2022
1 parent bde5a6c commit 2644af6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 7 deletions.
87 changes: 87 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "django-s3direct",
"version": "2.0.2",
"version": "2.0.3",
"description": "Add direct uploads to S3 functionality with a progress bar to file input fields.",
"directories": {
"example": "example"
Expand All @@ -12,6 +12,7 @@
"spark-md5": "^3.0.2"
},
"devDependencies": {
"buffer": "^6.0.3",
"parcel": "^2.6.0",
"prettier": "^2.7.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/css/bootstrap-progress.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Designed and built with all the love in the world @twitter by @mdo and @fat.
*/
.clearfix {
*zoom: 1;
/* *zoom: 1; */
}
.clearfix:before,
.clearfix:after {
Expand Down
18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ const removeUpload = (e) => {

const addHandlers = (el) => {
const url = el.querySelector(".file-url");
if (url.name.includes("__prefix__")) return false;

const input = el.querySelector(".file-input");
const remove = el.querySelector(".file-remove");
const status = url.value === "" ? "form" : "link";
Expand All @@ -275,10 +277,16 @@ const addHandlers = (el) => {
input.addEventListener("change", checkFileAndInitiateUpload, false);
};

const findAndAddHandlers = () => {
document
.querySelectorAll(".s3direct:not(.form-active, .link-active)")
.forEach(addHandlers);
};

document.addEventListener("DOMContentLoaded", (event) => {
const observer = new MutationObserver(function (m) {
[].forEach.call(document.querySelectorAll(".s3direct"), addHandlers);
});
const observer_config = { childList: true, subtree: true };
observer.observe(document.body, observer_config);
findAndAddHandlers();

const observer = new MutationObserver(() => findAndAddHandlers());

observer.observe(document.body, { childList: true, subtree: true });
});

0 comments on commit 2644af6

Please sign in to comment.