-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a123e61
commit 3afa8d5
Showing
6 changed files
with
182 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
$(function () { | ||
if (imagekitEnabled) { | ||
const markdownToggle = $("#id_markdown"); | ||
const description = $("#description"); | ||
const descriptionParent = description.parent(); | ||
|
||
descriptionParent.css({ | ||
"position": "relative", | ||
}) | ||
|
||
const upload_overlay = $("<div>").css({ | ||
"display": "none", | ||
"position": "absolute", | ||
"top": 0, | ||
"left": 0, | ||
"width": "92%", | ||
"height": "100%", | ||
"background-color": "rgba(0, 0, 0, 0.2)", | ||
"z-index": 1000, | ||
"text-align": "center", | ||
"border": "10px dashed #000", | ||
"padding": "100px 20px 0px 20px", | ||
"font-size": "250%", | ||
"box-sizing": "border-box", | ||
}).text("Drop to embed").appendTo(descriptionParent); | ||
|
||
descriptionParent.on({ | ||
"dragover": function (e) { | ||
console.log("dragover"); | ||
e.preventDefault(); | ||
}, | ||
"dragenter": function (e) { | ||
console.log("dragenter"); | ||
var dt = e.originalEvent.dataTransfer; | ||
if (dt.types.includes("Files")) { | ||
upload_overlay.stop().fadeIn(150); | ||
} | ||
}, | ||
"drop": function (e) { | ||
console.log("drop"); | ||
var dt = e.originalEvent.dataTransfer; | ||
e.preventDefault(); | ||
if (dt && dt.files.length) { | ||
console.log(dt.files); | ||
if (dt.files.length != 1) { | ||
alert("Please only upload one file at a time."); | ||
return; | ||
} | ||
|
||
console.log(imagekitToken); | ||
|
||
imagekit.upload({ | ||
file: dt.files[0], | ||
fileName: dt.files[0].name, | ||
tags: ["tin"], | ||
token: imagekitToken, | ||
signature: imagekitSignature, | ||
expire: imagekitExpire, | ||
}).then(result => { | ||
console.log(result); | ||
}).then(error => { | ||
console.log(error); | ||
}) | ||
} | ||
upload_overlay.stop().fadeOut(150); | ||
}, | ||
}); | ||
|
||
upload_overlay.on("dragleave", function () { | ||
upload_overlay.stop().fadeOut(150); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" | ||
integrity="sha512-AIOTidJAcHBH2G/oZv9viEGXRqDNmfdPVPYOYKGy3fti0xIplnlgMHUGfuNRzC6FkzIo0iIxgFnr9RikFxK+sw==" | ||
crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/imagekit.min.js"></script> | ||
<script src="{% static 'js/markdown-image-dragdrop.js' %}"></script> | ||
<script type="text/javascript"> | ||
$(document).ready(function () { | ||
$("#id_due").datetimepicker({ | ||
|
@@ -31,6 +33,24 @@ | |
}); | ||
} | ||
}); | ||
|
||
const imagekitEnabled = {{ imagekit_enabled|yesno:"true,false" }}; | ||
let imagekit = null; | ||
let imagekitToken = null; | ||
let imagekitSignature = null; | ||
let imagekitExpire = null; | ||
if (imagekitEnabled) { | ||
imagekit = new ImageKit({ | ||
publicKey: "{{ imagekit_public_key }}", | ||
urlEndpoint: "{{ imagekit_url }}", | ||
}); | ||
|
||
imagekitToken = "{{ imagekit_auth.token }}"; | ||
imagekitSignature = "{{ imagekit_auth.signature }}"; | ||
imagekitExpire = "{{ imagekit_auth.expire }}"; | ||
} | ||
|
||
console.log(imagekit); | ||
</script> | ||
{% endblock %} | ||
|
||
|