adjust #hotkey-info position dynamically

This commit is contained in:
tophf 2017-12-08 23:16:59 +03:00
parent ae9d33cf37
commit 9b4f76d776

View File

@ -17,6 +17,8 @@ var hotkeys = (() => {
initHotkeyInfo();
});
window.addEventListener('resize', adjustInfoPosition);
return {setState};
function setState(newState = !enabled) {
@ -138,11 +140,15 @@ var hotkeys = (() => {
delete container.dataset.active;
document.body.style.height = '';
container.title = title;
window.addEventListener('resize', adjustInfoPosition);
}
function open() {
window.removeEventListener('resize', adjustInfoPosition);
debounce.unregister(adjustInfoPosition);
title = container.title;
container.title = '';
container.style = '';
container.dataset.active = true;
if (!container.firstElementChild) {
buildElement();
@ -184,4 +190,19 @@ var hotkeys = (() => {
});
}
}
function adjustInfoPosition(debounced) {
const container = $('#hotkey-info');
if (debounced !== true) {
debounce(adjustInfoPosition, 100, true);
return;
}
const style = container.style;
if (installed.scrollHeight > installed.clientHeight) {
const entryRight = installed.firstElementChild.getBoundingClientRect().right;
style.setProperty('right', window.innerWidth - entryRight + 'px', 'important');
}
const installedBottom = installed.getBoundingClientRect().bottom + window.scrollY;
style.setProperty('bottom', window.innerHeight - installedBottom + 'px', 'important');
}
})();