Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-treadway committed Jan 23, 2020
1 parent 5530124 commit afdf00c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/legacy/core_plugins/kibana/common/field_formats/types/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ const URL_TYPES = [
];
const DEFAULT_URL_TYPE = 'a';

export function createUrlFormat() {
export function createUrlFormat(context: any) {
class UrlFormat extends FieldFormat {
static basePath = undefined;
static id = 'url';
static title = 'Url';
static fieldType = [
Expand Down Expand Up @@ -140,6 +141,10 @@ export function createUrlFormat() {
const url = escape(this.formatUrl(rawValue));
const label = escape(this.formatLabel(rawValue, url));

if (!parsedUrl) {
parsedUrl = UrlFormat.defaultParsedUrl;
}

switch (this.param('type')) {
case 'audio':
return `<audio controls preload="none" src="${url}">`;
Expand Down Expand Up @@ -201,5 +206,24 @@ export function createUrlFormat() {
};
}

async function initializeDefaultParsedUrl() {
if (UrlFormat.defaultParsedUrl !== undefined) {
return;
}

try {
const platform = await import('ui/new_platform');
UrlFormat.defaultParsedUrl = {
origin: global.window.location.origin,
pathname: global.window.location.pathname,
basePath: platform.npSetup.core.http.basePath.get(),
};
} catch (err) {
UrlFormat.defaultParsedUrl = null;
}
}

initializeDefaultParsedUrl();

return UrlFormat;
}

0 comments on commit afdf00c

Please sign in to comment.