diff options
author | Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> | 2021-08-03 16:57:25 -0700 |
---|---|---|
committer | Aubrey-Li <63608597+Aubrey-Li@users.noreply.github.com> | 2021-08-03 16:57:25 -0700 |
commit | faa2449d0667507b5424984c0f1d70886d0cb025 (patch) | |
tree | 02a984b9b8fb2b8e3c4c93f102d9c4b700ff0fda /src/fields/URLField.ts | |
parent | f4b910cc51c7c6b9c794d1b59198d132af3580b7 (diff) | |
parent | 0e8aef275346b4ba3bc1bb91fda17a335c307bf1 (diff) |
Merge branch 'master' into trails-aubrey
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 48535edf0..4d3776a2c 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; } |