1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/pages/unlock-page/unlock-page.util.js

18 lines
601 B
JavaScript
Raw Normal View History

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;
}