UNPKG

scrivito

Version:

Scrivito is a professional, yet easy to use SaaS Enterprise Content Management Service, built for digital agencies and medium to large businesses. It is completely maintenance-free, cost-effective, and has unprecedented performance and security.

40 lines (34 loc) 970 B
// @rewire import { uiAdapter } from 'scrivito_sdk/app_support/ui_adapter'; import { InternalError, assignLocation, currentOrigin, openWindow, replaceLocation, } from 'scrivito_sdk/common'; import { isOriginLocal } from './routing'; export function redirectToUrl(url: string): void { if (uiAdapter) changeLocation(url); else replaceLocation(url); } export function changeLocation(url: string): void { if (uiAdapter) { // change the location of the parent, to avoid CSP errors. uiAdapter.navigateToExternalUrl(url); } else { assignLocation(url); } } export function openInNewWindow(url: string): void { if (uiAdapter && isOriginLocal(url)) { uiAdapter.openInNewUiWindow(convertToAbsoluteLocalUrl(url)); } else { openWindow(url, '_blank'); } } function convertToAbsoluteLocalUrl(url: string) { const origin = currentOrigin(); if (origin === undefined) throw new InternalError(); return new URL(url, origin).href; }