UNPKG

locize

Version:

This package adds the incontext editor to your i18next setup.

38 lines (35 loc) 1.77 kB
'use strict'; var postMessage = require('./postMessage.js'); var popup = require('../ui/elements/popup.js'); function handler(payload) { var containerStyle = payload.containerStyle; if (containerStyle) { var popup$1 = document.getElementById(popup.popupId); if (!popup$1) 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$1.style.height, ")"); popup$1.style.setProperty('top', "calc(".concat(popup$1.style.top, " - ").concat(diff, ")")); popup$1.style.setProperty('height', containerStyle.height); } if (containerStyle.width) { var _diff = "calc(".concat(containerStyle.width, " - ").concat(popup$1.style.width, ")"); popup$1.style.setProperty('left', "calc(".concat(popup$1.style.left, " - ").concat(_diff, ")")); popup$1.style.setProperty('width', containerStyle.width); } if (storedPos && storedPos.top && storedPos.top < window.innerHeight - containerStyle.height.replace('px', '')) { popup$1.style.setProperty('top', storedPos.top + 'px'); } if (storedPos && storedPos.left && storedPos.left < window.innerWidth - containerStyle.width.replace('px', '')) { popup$1.style.setProperty('left', storedPos.left + 'px'); } } } postMessage.api.addHandler('requestPopupChanges', handler);