🔥 frontend: Remove jQuery, rewrite FAS lookup in vanilla JS
Bootstrap 5 does not require jQuery and the CKEditor 5 migration removed
the last jQuery-dependent inline script. The only remaining consumer was
`fas_details.js` (87 lines of jQuery AJAX and DOM manipulation for the
FAS username lookup).
Rewrote `fas_details.js` using vanilla JavaScript:
- `$.ajax()` → `fetch()` with Promise-based error handling
- `$('#id').val()` → `document.getElementById('id').value`
- `$('#el').after(...)` → `el.insertAdjacentHTML('afterend', ...)`
- `$().fadeIn().delay().fadeOut()` → `setTimeout` with `el.remove()`
- Added a `catch` handler for network errors (jQuery version silently
swallowed fetch failures)
Deleted `assets/js/vendor/jquery-3.3.1.min.js` (87 KB). Removed the
jQuery script tag from `base.html`. Changed both remaining script tags
to use `defer` (removed `async` from Bootstrap bundle — `async` can
cause race conditions with scripts that depend on Bootstrap JS).
Assisted-by: Claude Opus 4.6 (1M context)
Signed-off-by: Justin Wheeler <jwheel@fedoraproject.org>
This commit is contained in:
parent
3a0e6a840a
commit
6a98ddb9de
3 changed files with 77 additions and 83 deletions
|
|
@ -1,87 +1,84 @@
|
|||
$(function() {
|
||||
/*
|
||||
Place the button inside input field
|
||||
*/
|
||||
$("#id_fasid").after($("#search_fasid"));
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var fasidInput = document.getElementById('id_fasid');
|
||||
var searchBtn = document.getElementById('search_fasid');
|
||||
var nameInput = document.getElementById('id_recipient_name');
|
||||
var emailInput = document.getElementById('id_recipient_email');
|
||||
|
||||
/*
|
||||
Making the input fields clear when the page reloads
|
||||
*/
|
||||
$("#id_fasid").val("");
|
||||
$("#id_recipient_name").val("");
|
||||
$("#id_recipient_email").val("");
|
||||
if (!fasidInput || !searchBtn) return;
|
||||
|
||||
$("#search_fasid").click(function() {
|
||||
let fasid = $("#id_fasid").val();
|
||||
$("#server-error").remove();
|
||||
fasidInput.parentNode.appendChild(searchBtn);
|
||||
|
||||
if (!fasid) {
|
||||
console.log("!fasid");
|
||||
return;
|
||||
fasidInput.value = '';
|
||||
nameInput.value = '';
|
||||
emailInput.value = '';
|
||||
|
||||
function removeEl(id) {
|
||||
var el = document.getElementById(id);
|
||||
if (el) el.remove();
|
||||
}
|
||||
|
||||
function showTemporaryMessage(afterEl, id, text, delay) {
|
||||
removeEl(id);
|
||||
afterEl.insertAdjacentHTML('afterend',
|
||||
'<p class="error" id="' + id + '">' + text + '</p>');
|
||||
var msg = document.getElementById(id);
|
||||
setTimeout(function () { if (msg) msg.remove(); }, delay);
|
||||
}
|
||||
|
||||
searchBtn.addEventListener('click', function () {
|
||||
var fasid = fasidInput.value;
|
||||
removeEl('server-error');
|
||||
|
||||
if (!fasid) return;
|
||||
|
||||
nameInput.setAttribute('placeholder', '');
|
||||
nameInput.value = '';
|
||||
emailInput.value = '';
|
||||
fasidInput.disabled = true;
|
||||
removeEl('no-fas-id-error');
|
||||
removeEl('server-error');
|
||||
|
||||
var wrapper = document.getElementById('div_id_fasid');
|
||||
if (!document.getElementById('fas_username_check_message')) {
|
||||
wrapper.insertAdjacentHTML('afterend',
|
||||
'<p class="searching-text" id="fas_username_check_message">Searching for FAS Username...</p>');
|
||||
}
|
||||
$("#id_recipient_name").attr("placeholder", "");
|
||||
$("#id_recipient_name").val("");
|
||||
$("#id_recipient_email").val("");
|
||||
$("#id_fasid").prop("disabled", true);
|
||||
$("#no-fas-id-error").remove();
|
||||
$("#server-error").remove();
|
||||
if (!$('#fas_username_check_message').length) {
|
||||
$("#div_id_fasid").after(
|
||||
'<p class="searching-text" id="fas_username_check_message">Searching for FAS Username...</p>'
|
||||
);
|
||||
}
|
||||
|
||||
email = $.ajax({
|
||||
type: "GET",
|
||||
url: "/send/search?fasid=" + encodeURIComponent(fasid),
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
$(".error").remove();
|
||||
$(".searching-text").remove();
|
||||
$("#id_fasid").prop("disabled", false);
|
||||
if (data["privacy"]) {
|
||||
$("#id_recipient_name").attr(
|
||||
"placeholder",
|
||||
"Privacy is Set! Type Name Manually"
|
||||
);
|
||||
} else {
|
||||
$("#id_recipient_name").val(data["name"]);
|
||||
}
|
||||
|
||||
$("#id_recipient_email").val(data["email"]);
|
||||
},
|
||||
statusCode: {
|
||||
404: function(data) {
|
||||
console.log(data);
|
||||
$("#no-fas-id-error").remove();
|
||||
$("#id_fasid").prop("disabled", false);
|
||||
$(".searching-text").remove();
|
||||
$("#div_id_fasid").after(
|
||||
'<p class="error" id="no-fas-id-error">Sorry! No such FAS Username exist</p>'
|
||||
);
|
||||
$("#no-fas-id-error").fadeIn("slow", function() {
|
||||
$("#no-fas-id-error")
|
||||
.delay(2700)
|
||||
.fadeOut();
|
||||
});
|
||||
$("#id_fasid").val("");
|
||||
},
|
||||
500: function(data) {
|
||||
console.log(data);
|
||||
$("#id_fasid").val("");
|
||||
$("#server-error").remove();
|
||||
$(".searching-text").remove();
|
||||
$("#id_fasid").prop("disabled", false);
|
||||
$("#div_id_fasid").after(
|
||||
'<p class="error" id="server-error" >Internal Server Error Occured! Enter Name and Email manually!</p>'
|
||||
);
|
||||
$("#server-error").fadeIn("slow", function() {
|
||||
$("#server-error")
|
||||
.delay(3000)
|
||||
.fadeOut();
|
||||
fetch('/send/search?fasid=' + encodeURIComponent(fasid))
|
||||
.then(function (response) {
|
||||
document.querySelectorAll('.searching-text').forEach(function (el) { el.remove(); });
|
||||
fasidInput.disabled = false;
|
||||
|
||||
if (response.ok) {
|
||||
return response.json().then(function (data) {
|
||||
document.querySelectorAll('.error').forEach(function (el) { el.remove(); });
|
||||
if (data.privacy) {
|
||||
nameInput.setAttribute('placeholder', 'Privacy is Set! Type Name Manually');
|
||||
} else {
|
||||
nameInput.value = data.name;
|
||||
}
|
||||
emailInput.value = data.email;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
fasidInput.value = '';
|
||||
showTemporaryMessage(wrapper, 'no-fas-id-error',
|
||||
'Sorry! No such FAS Username exist', 3500);
|
||||
return;
|
||||
}
|
||||
|
||||
fasidInput.value = '';
|
||||
showTemporaryMessage(wrapper, 'server-error',
|
||||
'Internal Server Error Occured! Enter Name and Email manually!', 4000);
|
||||
})
|
||||
.catch(function () {
|
||||
document.querySelectorAll('.searching-text').forEach(function (el) { el.remove(); });
|
||||
fasidInput.disabled = false;
|
||||
fasidInput.value = '';
|
||||
showTemporaryMessage(
|
||||
document.getElementById('div_id_fasid'), 'server-error',
|
||||
'Network error! Enter Name and Email manually!', 4000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
2
assets/js/vendor/jquery-3.3.1.min.js
vendored
2
assets/js/vendor/jquery-3.3.1.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -10,9 +10,8 @@
|
|||
<link href="{% static 'css/fedora-theme.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'css/custom.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'images/favicon.ico' %}" rel="icon" type="image/x-icon">
|
||||
<script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}" async defer></script>
|
||||
<script src="{% static 'js/vendor/jquery-3.3.1.min.js' %}"></script>
|
||||
<script src="{% static 'js/fas_details.js' %}" type="text/javascript"></script>
|
||||
<script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}" defer></script>
|
||||
<script src="{% static 'js/fas_details.js' %}" defer></script>
|
||||
{% block extra_head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue