mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-16 08:56:46 +02:00
Added logout overwritte logic for espocrm
This commit is contained in:
parent
dc437c7621
commit
b9b08feadd
@ -14,9 +14,16 @@
|
|||||||
return str && /(?:^|\W)log\s*out(?:\W|$)|logout/i.test(str);
|
return str && /(?:^|\W)log\s*out(?:\W|$)|logout/i.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasLogoutAttribute(el) {
|
/**
|
||||||
for (const attr of el.attributes) {
|
* Returns true if any attribute name or value on the given element
|
||||||
if (/logout/i.test(attr.name) || /\/logout/i.test(attr.value)) {
|
* contains the substring "logout" (case-insensitive).
|
||||||
|
*
|
||||||
|
* @param {Element} element – The DOM element to inspect.
|
||||||
|
* @returns {boolean} – True if "logout" appears in any attribute name or value.
|
||||||
|
*/
|
||||||
|
function containsLogoutAttribute(element) {
|
||||||
|
for (const attribute of element.attributes) {
|
||||||
|
if (/logout/i.test(attribute.name) || /logout/i.test(attribute.value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,23 +50,41 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function overrideLogout(el) {
|
/**
|
||||||
|
* Apply logout redirect behavior to a matching element:
|
||||||
|
* – Installs a capturing click‐handler to force navigation to logoutUrl
|
||||||
|
* – Always sets href/formaction/action to logoutUrl
|
||||||
|
* – Marks the element as patched to avoid double‐binding
|
||||||
|
*
|
||||||
|
* @param {Element} el – The element to override (e.g. <a>, <button>, <form>, <input>)
|
||||||
|
* @param {string} logoutUrl – The full logout URL including redirect params
|
||||||
|
*/
|
||||||
|
function overrideLogout(el, logoutUrl) {
|
||||||
|
// avoid patching the same element twice
|
||||||
if (el.dataset._logoutHandled) return;
|
if (el.dataset._logoutHandled) return;
|
||||||
el.dataset._logoutHandled = "true";
|
el.dataset._logoutHandled = "true";
|
||||||
el.style.cursor = 'pointer';
|
|
||||||
el.addEventListener('click', function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
window.location.href = logoutUrl;
|
|
||||||
});
|
|
||||||
|
|
||||||
const tagName = el.tagName.toLowerCase();
|
// show pointer cursor
|
||||||
if (tagName === 'a' && el.hasAttribute('href') && /\/logout/i.test(el.getAttribute('href'))) {
|
el.style.cursor = 'pointer';
|
||||||
|
|
||||||
|
// capture‐phase listener so it fires before any framework handlers
|
||||||
|
el.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = logoutUrl;
|
||||||
|
}, { capture: true });
|
||||||
|
|
||||||
|
const tag = el.tagName.toLowerCase();
|
||||||
|
|
||||||
|
// always set the link target on <a>
|
||||||
|
if (tag === 'a') {
|
||||||
el.setAttribute('href', logoutUrl);
|
el.setAttribute('href', logoutUrl);
|
||||||
}
|
}
|
||||||
if ((tagName === 'button' || tagName === 'input') && el.hasAttribute('formaction') && /\/logout/i.test(el.getAttribute('formaction'))) {
|
// always set the formaction on <button> or <input>
|
||||||
|
else if ((tag === 'button' || tag === 'input') && el.hasAttribute('formaction')) {
|
||||||
el.setAttribute('formaction', logoutUrl);
|
el.setAttribute('formaction', logoutUrl);
|
||||||
}
|
}
|
||||||
if (tagName === 'form' && el.hasAttribute('action') && /\/logout/i.test(el.getAttribute('action'))) {
|
// always set the form action on <form>
|
||||||
|
else if (tag === 'form') {
|
||||||
el.setAttribute('action', logoutUrl);
|
el.setAttribute('action', logoutUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,10 +99,10 @@
|
|||||||
matchesLogout(el.id) ||
|
matchesLogout(el.id) ||
|
||||||
matchesLogout(el.className) ||
|
matchesLogout(el.className) ||
|
||||||
matchesLogout(el.innerText) ||
|
matchesLogout(el.innerText) ||
|
||||||
hasLogoutAttribute(el) ||
|
containsLogoutAttribute(el) ||
|
||||||
matchesTechnicalIndicators(el)
|
matchesTechnicalIndicators(el)
|
||||||
) {
|
) {
|
||||||
overrideLogout(el);
|
overrideLogout(el, logoutUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
initLogoutPatch(
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
initLogoutPatch(
|
||||||
'{{ oidc.client.logout_url }}',
|
'{{ oidc.client.logout_url }}',
|
||||||
'{{ WEB_PROTOCOL }}',
|
'{{ WEB_PROTOCOL }}',
|
||||||
'{{ primary_domain }}'
|
'{{ primary_domain }}'
|
||||||
);
|
);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user