0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-11 07:41:19 +00:00

Eliminate jQuery usage in the login page

This commit is contained in:
Pēteris Caune 2022-06-08 09:46:51 +03:00
parent 51f7fe7332
commit ca392c07ce
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
3 changed files with 28 additions and 23 deletions

2
static/js/bootstrap-native.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,9 @@
$(function () {
window.addEventListener("DOMContentLoaded", function(e) {
var email = document.getElementById("signup-email");
var submitBtn = document.getElementById("signup-go");
function submitForm() {
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
var email = $("#signup-email").val();
submitBtn.disabled = true;
try {
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
@ -10,30 +11,33 @@ $(function () {
var tz = "UTC";
}
$("#signup-go").prop("disabled", true);
$.ajax({
url: base + "/accounts/signup/",
type: "post",
data: {"identity": email, "tz": tz},
success: function(data) {
$("#signup-result").html(data).show();
$("#signup-go").prop("disabled", false);
}
});
var payload = new FormData();
payload.append("identity", email.value);
payload.append("tz", tz);
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
fetch(base + "/accounts/signup/", {method: "POST", body: payload})
.then(response => response.text())
.then(function(text) {
var resultLine = document.getElementById("signup-result");
resultLine.innerHTML = text;
resultLine.style.display = "block";
submitBtn.disabled = false;
});
return false;
}
$("#signup-go").on("click", submitForm);
$("#signup-email").keypress(function (e) {
// Wire up the submit button and the Enter key
submitBtn.addEventListener("click", submitForm);
email.addEventListener("keyup", function(e) {
if (e.which == 13) {
return submitForm();
}
});
$("#signup-modal").on('shown.bs.modal', function () {
$("#signup-email").focus()
})
});
var modal = document.getElementById("signup-modal");
modal.addEventListener("shown.bs.modal", function() {
email.focus();
});
});

View file

@ -152,8 +152,7 @@
{% block scripts %}
{% compress js %}
<script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/bootstrap-native.min.js' %}"></script>
<script src="{% static 'js/signup.js' %}"></script>
{% endcompress %}
{% endblock %}