DEV: Remove jquery from create-account modal (#16983)

This commit is contained in:
Isaac Janzen 2022-06-09 14:59:33 -05:00 committed by GitHub
parent 300f835703
commit 3ebfde5ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 20 deletions

View File

@ -21,6 +21,23 @@ export default Component.extend({
}
},
actionOnEnter(event) {
if (!this.disabled && event.key === "Enter") {
event.preventDefault();
event.stopPropagation();
this.action();
return false;
}
},
selectKitFocus(event) {
const target = document.getElementById(event.target.getAttribute("for"));
if (target?.classList.contains("select-kit")) {
event.preventDefault();
target.querySelector(".select-kit-header").click();
}
},
didInsertElement() {
this._super(...arguments);
@ -43,31 +60,15 @@ export default Component.extend({
}
}
$(this.element).on("keydown.discourse-create-account", (e) => {
if (!this.disabled && e.key === "Enter") {
e.preventDefault();
e.stopPropagation();
this.action();
return false;
}
});
$(this.element).on("click.dropdown-user-field-label", "[for]", (event) => {
const $element = $(event.target);
const $target = $(`#${$element.attr("for")}`);
if ($target.is(".select-kit")) {
event.preventDefault();
$target.find(".select-kit-header").trigger("click");
}
});
this.element.addEventListener("keydown", this.actionOnEnter);
this.element.addEventListener("click", this.selectKitFocus);
},
willDestroyElement() {
this._super(...arguments);
$(this.element).off("keydown.discourse-create-account");
$(this.element).off("click.dropdown-user-field-label");
this.element.removeEventListener("keydown", this.actionOnEnter);
this.element.removeEventListener("click", this.selectKitFocus);
let userTextFields = document.getElementsByClassName("user-fields")[0];