locize
Version:
This package adds the incontext editor to your i18next setup.
36 lines (34 loc) • 1.71 kB
JavaScript
import { api } from './postMessage.js';
import { popupId } from '../ui/elements/popup.js';
function handler(payload) {
var containerStyle = payload.containerStyle;
if (containerStyle) {
var popup = document.getElementById(popupId);
if (!popup) return;
var storedPos = window.localStorage.getItem('locize_popup_pos');
if (storedPos) storedPos = JSON.parse(storedPos);
var storedSize = window.localStorage.getItem('locize_popup_size');
if (storedSize) storedSize = JSON.parse(storedSize);
if (storedSize && storedSize.height && storedSize.width) {
containerStyle.height = storedSize.height + 'px';
containerStyle.width = storedSize.width + 'px';
}
if (containerStyle.height) {
var diff = "calc(".concat(containerStyle.height, " - ").concat(popup.style.height, ")");
popup.style.setProperty('top', "calc(".concat(popup.style.top, " - ").concat(diff, ")"));
popup.style.setProperty('height', containerStyle.height);
}
if (containerStyle.width) {
var _diff = "calc(".concat(containerStyle.width, " - ").concat(popup.style.width, ")");
popup.style.setProperty('left', "calc(".concat(popup.style.left, " - ").concat(_diff, ")"));
popup.style.setProperty('width', containerStyle.width);
}
if (storedPos && storedPos.top && storedPos.top < window.innerHeight - containerStyle.height.replace('px', '')) {
popup.style.setProperty('top', storedPos.top + 'px');
}
if (storedPos && storedPos.left && storedPos.left < window.innerWidth - containerStyle.width.replace('px', '')) {
popup.style.setProperty('left', storedPos.left + 'px');
}
}
}
api.addHandler('requestPopupChanges', handler);