diff options
author | geireann <geireann.lindfield@gmail.com> | 2021-08-05 17:17:41 -0400 |
---|---|---|
committer | geireann <geireann.lindfield@gmail.com> | 2021-08-05 17:17:41 -0400 |
commit | 04ae1c712422036b3986675486ea9a1eddb25e36 (patch) | |
tree | 2cba3d0cf65a7f18d959620a3bd1d9a7e455bff5 /src/fields/URLField.ts | |
parent | 2ec093982c06965086326df73d365e1b54f6a2a2 (diff) | |
parent | b9d72dd3ed3b800ef9bd1f6695ac37e14d21f675 (diff) |
Merge branch 'master' into search-david
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r-- | src/fields/URLField.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/fields/URLField.ts b/src/fields/URLField.ts index fb71160ca..d96e8a70a 100644 --- a/src/fields/URLField.ts +++ b/src/fields/URLField.ts @@ -3,14 +3,17 @@ import { serializable, custom } from "serializr"; import { ObjectField } from "./ObjectField"; import { ToScriptString, ToString, Copy } from "./FieldSymbols"; import { Scripting, scriptingGlobal } from "../client/util/Scripting"; +import { Utils } from "../Utils"; function url() { return custom( function (value: URL) { - return value.href; + return value.origin === window.location.origin ? + value.pathname : + value.href; }, function (jsonValue: string) { - return new URL(jsonValue); + return new URL(jsonValue, window.location.origin); } ); } @@ -24,15 +27,21 @@ export abstract class URLField extends ObjectField { constructor(url: URL | string) { super(); if (typeof url === "string") { - url = new URL(url); + url = url.startsWith("http") ? new URL(url) : new URL(url, window.location.origin); } this.url = url; } [ToScriptString]() { + if (Utils.prepend(this.url.pathname) === this.url.href) { + return `new ${this.constructor.name}("${this.url.pathname}")`; + } return `new ${this.constructor.name}("${this.url.href}")`; } [ToString]() { + if (Utils.prepend(this.url.pathname) === this.url.href) { + return this.url.pathname; + } return this.url.href; } |