index.js (1828B)
1 import {notify} from '~/lib/notifications'; 2 3 function openPopupWindow(url, width, uniqName = null) { 4 var left, top, height, 5 screenLeft = screen.availLeft || 0, 6 bordersWidth = 8; 7 // if browser window is in the right half of screen, place new window on left half 8 if (window.screenX - screenLeft - bordersWidth * 1.5 > width) { 9 left = window.screenX - width - bordersWidth * 1.5; 10 // if browser window is in the left half of screen, place new window on right half 11 } else if (window.screenX + window.outerWidth + width + bordersWidth * 1.5 < screenLeft + screen.availWidth) { 12 left = window.screenX + window.outerWidth + bordersWidth; 13 // if screen is small or browser window occupies whole screen, place new window on top of current window 14 } else { 15 left = window.screenX + window.outerWidth / 2 - width / 2; 16 if (left < 0) { 17 left = 0; 18 } 19 } 20 top = window.screenY; 21 height = window.innerHeight; 22 var features = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top; 23 features += ',resizable,scrollbars'; 24 var newWindow = window.open(url, uniqName, features); 25 if (!newWindow || newWindow.closed) { 26 notify('Всплывающее окно заблокировано браузером.\n' + 27 'Для полноценной работы сайта необходимо разрешить всплывающие окна в настройках браузера для сайта.\n\n' + 28 'Pop-up window was blocked by the browser.\n' + 29 'If you want to use the full functionality of this site, ' + 30 'turn off blocking pop-ups in the browser settings for this site.'); 31 } else { 32 newWindow.focus(); 33 } 34 } 35 36 export {openPopupWindow};