try to get submit button from parent modal if not in form
This commit is contained in:
parent
d0cf21dd3e
commit
b8db949ecc
|
@ -244,7 +244,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
function listen(form: HTMLFormElement) {
|
function listen(form: HTMLFormElement) {
|
||||||
form.removeEventListener('submit', formSubmitted, false);
|
form.removeEventListener('submit', formSubmitted, false);
|
||||||
form.addEventListener('submit', formSubmitted, false);
|
form.addEventListener('submit', formSubmitted, false);
|
||||||
const submitButton = getFormSubmitButton(form, logInButtonNames);
|
const submitButton = getSubmitButton(form, logInButtonNames);
|
||||||
if (submitButton != null) {
|
if (submitButton != null) {
|
||||||
submitButton.removeEventListener('click', formSubmitted, false);
|
submitButton.removeEventListener('click', formSubmitted, false);
|
||||||
submitButton.addEventListener('click', formSubmitted, false);
|
submitButton.addEventListener('click', formSubmitted, false);
|
||||||
|
@ -305,6 +305,15 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
let form: HTMLFormElement = null;
|
let form: HTMLFormElement = null;
|
||||||
if (e.type === 'click') {
|
if (e.type === 'click') {
|
||||||
form = (e.target as HTMLElement).closest('form');
|
form = (e.target as HTMLElement).closest('form');
|
||||||
|
if (form == null) {
|
||||||
|
const parentModal = (e.target as HTMLElement).closest('div.modal');
|
||||||
|
if (parentModal != null) {
|
||||||
|
const modalForms = parentModal.querySelectorAll('form');
|
||||||
|
if (modalForms.length === 1) {
|
||||||
|
form = modalForms[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
form = e.target as HTMLFormElement;
|
form = e.target as HTMLFormElement;
|
||||||
}
|
}
|
||||||
|
@ -349,7 +358,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
curPass = passwords[2];
|
curPass = passwords[2];
|
||||||
}
|
}
|
||||||
} else if (formData[i].passwordEls.length === 2 && passwords.length === 2) {
|
} else if (formData[i].passwordEls.length === 2 && passwords.length === 2) {
|
||||||
const buttonText = getButtonText(getFormSubmitButton(form, changePasswordButtonNames));
|
const buttonText = getButtonText(getSubmitButton(form, changePasswordButtonNames));
|
||||||
const matches = Array.from(changePasswordButtonContainsNames)
|
const matches = Array.from(changePasswordButtonContainsNames)
|
||||||
.filter((n) => buttonText.indexOf(n) > -1);
|
.filter((n) => buttonText.indexOf(n) > -1);
|
||||||
if (matches.length > 0) {
|
if (matches.length > 0) {
|
||||||
|
@ -374,8 +383,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormSubmitButton(form: HTMLFormElement, buttonNames: Set<string>) {
|
function getSubmitButton(wrappingEl: HTMLElement, buttonNames: Set<string>) {
|
||||||
let submitButton = form.querySelector('input[type="submit"], input[type="image"], ' +
|
if (wrappingEl == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let submitButton = wrappingEl.querySelector('input[type="submit"], input[type="image"], ' +
|
||||||
'button[type="submit"], button:not([type])') as HTMLElement;
|
'button[type="submit"], button:not([type])') as HTMLElement;
|
||||||
if (submitButton != null && submitButton.getAttribute('type') == null) {
|
if (submitButton != null && submitButton.getAttribute('type') == null) {
|
||||||
const buttonText = getButtonText(submitButton);
|
const buttonText = getButtonText(submitButton);
|
||||||
|
@ -384,7 +396,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (submitButton == null) {
|
if (submitButton == null) {
|
||||||
const possibleSubmitButtons = Array.from(form.querySelectorAll('a, span, button[type="button"], ' +
|
const possibleSubmitButtons = Array.from(wrappingEl.querySelectorAll('a, span, button[type="button"], ' +
|
||||||
'input[type="button"], button:not([type])')) as HTMLElement[];
|
'input[type="button"], button:not([type])')) as HTMLElement[];
|
||||||
possibleSubmitButtons.forEach((button) => {
|
possibleSubmitButtons.forEach((button) => {
|
||||||
if (submitButton != null || button == null || button.tagName == null) {
|
if (submitButton != null || button == null || button.tagName == null) {
|
||||||
|
@ -392,7 +404,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
}
|
}
|
||||||
const buttonText = getButtonText(button);
|
const buttonText = getButtonText(button);
|
||||||
if (buttonText != null) {
|
if (buttonText != null) {
|
||||||
if (button.tagName.toLowerCase() === 'button' && submitButton.getAttribute('type') == null &&
|
if (button.tagName.toLowerCase() === 'button' && button.getAttribute('type') == null &&
|
||||||
!cancelButtonNames.has(buttonText.trim().toLowerCase())) {
|
!cancelButtonNames.has(buttonText.trim().toLowerCase())) {
|
||||||
submitButton = button;
|
submitButton = button;
|
||||||
} else if (buttonNames.has(buttonText.trim().toLowerCase())) {
|
} else if (buttonNames.has(buttonText.trim().toLowerCase())) {
|
||||||
|
@ -401,6 +413,16 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (submitButton == null && wrappingEl.tagName.toLowerCase() === 'form') {
|
||||||
|
// Maybe it's in a modal?
|
||||||
|
const parentModal = wrappingEl.closest('div.modal') as HTMLElement;
|
||||||
|
if (parentModal != null) {
|
||||||
|
const modalForms = parentModal.querySelectorAll('form');
|
||||||
|
if (modalForms.length === 1) {
|
||||||
|
submitButton = getSubmitButton(parentModal, buttonNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return submitButton;
|
return submitButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue