Skip to content

Commit

Permalink
js: use functions + error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 16, 2021
1 parent 5777908 commit ebad7f7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions inst/assets/js/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
}

// IMAGE
document.addEventListener("click", function(e) {
var el = e.target;
function capureImage(event) {
var el = event.target;
if (!elOrParentHasClass(el, "btn-capture-screenshot")) {
return;
}
Expand Down Expand Up @@ -67,7 +67,6 @@
options.style.width = node.offsetWidth + "px";
options.style.height = node.offsetHeight + "px";
}

domtoimage
.toBlob(node, options)
.then(function(blob) {
Expand All @@ -77,11 +76,19 @@
.catch(function(error) {
console.error("Capture: oops, something went wrong!", error);
});
});
}
function capureImage_(event) {
try {
capureImage(event);
} catch (error) {
console.error(error);
}
}
document.addEventListener("click", capureImage_);

// PDF
document.addEventListener("click", function(e) {
var el = e.target;
function capturePDF(event) {
var el = event.target;
if (!elOrParentHasClass(el, "btn-capture-screenshot-pdf")) {
return;
}
Expand Down Expand Up @@ -148,7 +155,15 @@
.catch(function(error) {
console.error("Capture: oops, something went wrong!", error);
});
});
}
function capturePDF_(event) {
try {
capturePDF(event);
} catch (error) {
console.error(error);
}
}
document.addEventListener("click", capturePDF_);

// LOOKBOOK
var count = 1;
Expand Down

0 comments on commit ebad7f7

Please sign in to comment.