38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
// This file will contain the JavaScript logic for the SSO login button.
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const ssoLoginBtn = document.getElementById('sso-login-btn');
|
|
|
|
if (ssoLoginBtn) {
|
|
ssoLoginBtn.addEventListener('click', () => {
|
|
// ssoSettings.ssoUrl will be passed from WordPress using wp_localize_script
|
|
if (typeof ssoSettings === 'undefined' || !ssoSettings.ssoUrl) {
|
|
alert('SSO URL is not configured.');
|
|
return;
|
|
}
|
|
|
|
const ssoUrl = ssoSettings.ssoUrl;
|
|
|
|
const popupWidth = 600;
|
|
const popupHeight = 800;
|
|
const screenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
|
|
const screenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
|
|
const screenWidth = window.innerWidth || document.documentElement.clientWidth || screen.width;
|
|
const screenHeight = window.innerHeight || document.documentElement.clientHeight || screen.height;
|
|
const left = ((screenWidth / 2) - (popupWidth / 2)) + screenLeft;
|
|
const top = ((screenHeight / 2) - (popupHeight / 2)) + screenTop;
|
|
|
|
const popup = window.open(
|
|
ssoUrl,
|
|
'sso-login-popup',
|
|
`width=${popupWidth},height=${popupHeight},left=${left},top=${top}`
|
|
);
|
|
|
|
if (popup) {
|
|
popup.focus();
|
|
} else {
|
|
alert('Popup blocked. Please allow popups for this site.');
|
|
}
|
|
});
|
|
}
|
|
});
|