1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00
metamask-extension/ui/pages/unlock-page/unlock-page.util.js
Michal 32a2411cf5
Remove textarea caret dep (#17105)
remove dependency for mascot head movement
2023-01-16 13:07:59 +00:00

18 lines
601 B
JavaScript

export function getCaretCoordinates(element, position) {
const div = document.createElement('div');
div.id = 'password-mirror-div';
document.body.appendChild(div);
const computed = window.getComputedStyle(element);
div.textContent = new Array(position + 1).join('•');
const span = document.createElement('span');
span.textContent = '•';
div.appendChild(span);
const coordinates = {
top: span.offsetTop + parseInt(computed.borderTopWidth, 10),
left: span.offsetLeft + parseInt(computed.borderLeftWidth, 10),
};
document.body.removeChild(div);
return coordinates;
}