Fix Username Icon position on Apple login page (#1590)

Fix Username Icon position on Apple login page
This commit is contained in:
Sami Vänttinen 2022-04-05 08:10:56 +03:00 committed by GitHub
parent b67f05328c
commit adeb6add9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -175,3 +175,18 @@ kpxcSites.popupExceptionFound = function(combinations) {
return false;
};
/**
* Handles a few exceptions for certain sites where Username Icon is not placed properly.
* @param {number} left Absolute left position of the icon
* @param {number} top Absolute top position of the icon
* @param {number} iconSize Size of the icon
* @returns {array} New left and top values as an Array
*/
kpxcSites.iconOffset = function(left, top, iconSize) {
if (document.location.hostname.includes('idmsa.apple.com')) {
return [ left - (iconSize + 10), top + 3 ];
}
return undefined;
};

View file

@ -123,13 +123,20 @@ kpxcUI.setIconPosition = function(icon, field, rtl = false, segmented = false) {
const size = Number(icon.getAttribute('size'));
const offset = kpxcUI.calculateIconOffset(field, size);
let left = kpxcUI.bodyStyle.position.toLowerCase() === 'relative' ? rect.left - kpxcUI.bodyRect.left : rect.left;
const top = kpxcUI.bodyStyle.position.toLowerCase() === 'relative' ? rect.top - kpxcUI.bodyRect.top : rect.top;
let top = kpxcUI.bodyStyle.position.toLowerCase() === 'relative' ? rect.top - kpxcUI.bodyRect.top : rect.top;
// Add more space for the icon to show it at the right side of the field if TOTP fields are segmented
if (segmented) {
left += size + 10;
}
// Adjusts the icon offset for certain sites
const iconOffset = kpxcSites.iconOffset(left, top, size);
if (iconOffset) {
left = iconOffset[0];
top = iconOffset[1];
}
const scrollTop = document.scrollingElement ? document.scrollingElement.scrollTop : 0;
const scrollLeft = document.scrollingElement ? document.scrollingElement.scrollLeft : 0;
icon.style.top = Pixels(top + scrollTop + offset + 1);