minimalizacja js
This commit is contained in:
@@ -1,27 +1,45 @@
|
||||
(function () {
|
||||
const configs = (window.CROP_CONFIGS && Array.isArray(window.CROP_CONFIGS))
|
||||
? window.CROP_CONFIGS
|
||||
: (window.CROP_CONFIG ? [window.CROP_CONFIG] : []);
|
||||
|
||||
if (!configs.length) return;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const cropModal = document.getElementById("adminCropModal");
|
||||
const cropImage = document.getElementById("adminCropImage");
|
||||
const spinner = document.getElementById("adminCropLoading");
|
||||
const saveButton = document.getElementById("adminSaveCrop");
|
||||
configs.forEach((cfg) => initCropperSet(cfg));
|
||||
});
|
||||
|
||||
function initCropperSet(cfg) {
|
||||
const {
|
||||
modalId,
|
||||
imageId,
|
||||
spinnerId,
|
||||
saveBtnId,
|
||||
endpoint
|
||||
} = cfg || {};
|
||||
|
||||
const cropModal = document.getElementById(modalId);
|
||||
const cropImage = document.getElementById(imageId);
|
||||
const spinner = document.getElementById(spinnerId);
|
||||
const saveButton = document.getElementById(saveBtnId);
|
||||
|
||||
if (!cropModal || !cropImage || !spinner || !saveButton) return;
|
||||
|
||||
let cropper;
|
||||
let currentReceiptId;
|
||||
const currentEndpoint = "/admin/crop_receipt";
|
||||
const currentEndpoint = endpoint;
|
||||
|
||||
cropModal.addEventListener("shown.bs.modal", function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const baseSrc = button.getAttribute("data-img-src") || "";
|
||||
const ver = button.getAttribute("data-version") || Date.now();
|
||||
const baseSrc = button?.getAttribute("data-img-src") || "";
|
||||
const ver = button?.getAttribute("data-version") || Date.now();
|
||||
const sep = baseSrc.includes("?") ? "&" : "?";
|
||||
cropImage.src = baseSrc + sep + "cb=" + ver;
|
||||
|
||||
currentReceiptId = button.getAttribute("data-receipt-id");
|
||||
currentReceiptId = button?.getAttribute("data-receipt-id");
|
||||
|
||||
document.querySelectorAll('.cropper-container').forEach(e => e.remove());
|
||||
if (cropper) cropper.destroy();
|
||||
if (cropper && cropper.destroy) cropper.destroy();
|
||||
cropImage.onload = () => { cropper = cropUtils.initCropper(cropImage); };
|
||||
});
|
||||
|
||||
@@ -35,5 +53,5 @@
|
||||
spinner.classList.remove("d-none");
|
||||
cropUtils.handleCrop(currentEndpoint, currentReceiptId, cropper, spinner);
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
@@ -1,39 +0,0 @@
|
||||
(function () {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const cropModal = document.getElementById("userCropModal");
|
||||
const cropImage = document.getElementById("userCropImage");
|
||||
const spinner = document.getElementById("userCropLoading");
|
||||
const saveButton = document.getElementById("userSaveCrop");
|
||||
|
||||
if (!cropModal || !cropImage || !spinner || !saveButton) return;
|
||||
|
||||
let cropper;
|
||||
let currentReceiptId;
|
||||
const currentEndpoint = "/user_crop_receipt";
|
||||
|
||||
cropModal.addEventListener("shown.bs.modal", function (event) {
|
||||
const button = event.relatedTarget;
|
||||
const baseSrc = button.getAttribute("data-img-src") || "";
|
||||
const ver = button.getAttribute("data-version") || Date.now();
|
||||
const sep = baseSrc.includes("?") ? "&" : "?";
|
||||
cropImage.src = baseSrc + sep + "cb=" + ver;
|
||||
|
||||
currentReceiptId = button.getAttribute("data-receipt-id");
|
||||
|
||||
document.querySelectorAll('.cropper-container').forEach(e => e.remove());
|
||||
if (cropper) cropper.destroy();
|
||||
cropImage.onload = () => { cropper = cropUtils.initCropper(cropImage); };
|
||||
});
|
||||
|
||||
cropModal.addEventListener("hidden.bs.modal", function () {
|
||||
cropUtils.cleanUpCropper(cropImage, cropper);
|
||||
cropper = null;
|
||||
});
|
||||
|
||||
saveButton.addEventListener("click", function () {
|
||||
if (!cropper) return;
|
||||
spinner.classList.remove("d-none");
|
||||
cropUtils.handleCrop(currentEndpoint, currentReceiptId, cropper, spinner);
|
||||
});
|
||||
});
|
||||
})();
|
@@ -213,7 +213,16 @@
|
||||
</div>
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='admin_receipt_crop.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script>
|
||||
window.CROP_CONFIG = {
|
||||
modalId: "adminCropModal",
|
||||
imageId: "adminCropImage",
|
||||
spinnerId: "adminCropLoading",
|
||||
saveBtnId: "adminSaveCrop",
|
||||
endpoint: "/admin/crop_receipt"
|
||||
};
|
||||
</script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='receipt_crop.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='receipt_crop_logic.js') }}?v={{ APP_VERSION }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
@@ -244,8 +244,17 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
window.CROP_CONFIG = {
|
||||
modalId: "userCropModal",
|
||||
imageId: "userCropImage",
|
||||
spinnerId: "userCropLoading",
|
||||
saveBtnId: "userSaveCrop",
|
||||
endpoint: "/user_crop_receipt"
|
||||
};
|
||||
</script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='confirm_delete.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='user_receipt_crop.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='receipt_crop.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='receipt_crop_logic.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='select.js') }}?v={{ APP_VERSION }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='access_users.js') }}?v={{ APP_VERSION }}"></script>
|
||||
|
Reference in New Issue
Block a user