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.

41 lines (35 loc) 1.02 kB
// @rewire import * as URI from 'urijs'; 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(URI(url))) { uiAdapter.openInNewUiWindow(convertToAbsoluteLocalUrl(url)); } else { openWindow(url, '_blank'); } } function convertToAbsoluteLocalUrl(url: string) { const origin = currentOrigin(); if (origin === undefined) throw new InternalError(); return new URI(url).origin(origin).toString(); }