Move all js to a source file
This commit is contained in:
parent
3d498b4eae
commit
61d1655529
|
@ -0,0 +1,28 @@
|
|||
const MAX_BYTES = 1240; // 10KiB
|
||||
|
||||
function enableDragDropForPGPKeys(inputID) {
|
||||
function drop(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
let files = event.dataTransfer.files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
if(file.type !== 'text/plain'){
|
||||
toastr.warning(`File ${file.name} is not a public key file`);
|
||||
continue;
|
||||
}
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = onFileLoaded;
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileLoaded(event) {
|
||||
const initialData = event.currentTarget.result.substr(0, MAX_BYTES);
|
||||
$(inputID).val(initialData);
|
||||
}
|
||||
|
||||
const dropArea = $(inputID).get(0);
|
||||
dropArea.addEventListener("drop", drop, false);
|
||||
}
|
|
@ -51,7 +51,7 @@
|
|||
{% if not current_user.is_premium() %} disabled {% endif %}
|
||||
class="form-control" rows=10 id="pgp-public-key"
|
||||
placeholder="-----BEGIN PGP PUBLIC KEY BLOCK-----">{{ contact.pgp_public_key or "" }}</textarea>
|
||||
<div class="text-body p-2">You can drag and drop the pgp key into the text area</div>
|
||||
<div class="alert alert-info mt-2">You can drag and drop the pgp key file into the text area</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -73,36 +73,8 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{% if current_user.is_premium() %}
|
||||
<script src="/static/js/utils/drag-drop-into-text.js"></script>
|
||||
<script>
|
||||
const MAX_BYTES = 2048; // 2KiB
|
||||
|
||||
function drop(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
let files = event.dataTransfer.files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
console.log(file, file.name);
|
||||
if(file.type !== 'text/plain'){
|
||||
toastr.warning(`File ${file.name} is not a public key file`);
|
||||
continue;
|
||||
}
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = onFileLoaded;
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileLoaded(event) {
|
||||
const initialData = event.currentTarget.result.substr(0, MAX_BYTES);
|
||||
$('#pgp-public-key').val(initialData);
|
||||
console.log($('#pgp-public-key'));
|
||||
}
|
||||
|
||||
const dropArea = $("#pgp-public-key").get(0);
|
||||
dropArea.addEventListener("drop", drop, false);
|
||||
enableDragDropForPGPKeys('#pgp-public-key');
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
{% if not current_user.is_premium() %} disabled {% endif %}
|
||||
class="form-control" rows=10 id="pgp-public-key"
|
||||
placeholder="-----BEGIN PGP PUBLIC KEY BLOCK-----">{{ mailbox.pgp_public_key or "" }}</textarea>
|
||||
<div class="text-body p-2">You can drag and drop the pgp key into the text area</div>
|
||||
<div class="alert alert-info mt-2">You can drag and drop the pgp key file into the text area</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="form-name" value="pgp">
|
||||
|
@ -264,44 +264,12 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<oscript>
|
||||
<script src="/static/js/utils/drag-drop-into-text.js"></script>
|
||||
<script>
|
||||
$(".custom-switch-input").change(function (e) {
|
||||
$(this).closest("form").submit();
|
||||
});
|
||||
|
||||
enableDragDropForPGPKeys('#pgp-public-key');
|
||||
</script>
|
||||
|
||||
{% if current_user.is_premium() %}
|
||||
<script>
|
||||
const MAX_BYTES = 2048; // 2KiB
|
||||
|
||||
function drop(event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
let files = event.dataTransfer.files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
console.log(file, file.name);
|
||||
if(file.type !== 'text/plain'){
|
||||
toastr.warning(`File ${file.name} is not a public key file`);
|
||||
continue;
|
||||
}
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = onFileLoaded;
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileLoaded(event) {
|
||||
const initialData = event.currentTarget.result.substr(0, MAX_BYTES);
|
||||
$('#pgp-public-key').val(initialData);
|
||||
console.log($('#pgp-public-key'));
|
||||
}
|
||||
|
||||
const dropArea = $("#pgp-public-key").get(0);
|
||||
dropArea.addEventListener("drop", drop, false);
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue