aboutsummaryrefslogtreecommitdiff
path: root/src/fields/URLField.ts
diff options
context:
space:
mode:
authormehekj <mehek.jethani@gmail.com>2021-09-12 12:32:49 -0400
committermehekj <mehek.jethani@gmail.com>2021-09-12 12:32:49 -0400
commitd71bc56628c2193b537b92a186785eaffa3a1eef (patch)
tree0e346527d01ef4d32a28cf9738323c6f49656dfb /src/fields/URLField.ts
parent23db5275a9477d5894e76a2ad6f1795fb0f99b71 (diff)
parent9ac6931dabac40a7e530d144c1d1123548de373f (diff)
Merge branch 'master' into temporalmedia-mehek
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r--src/fields/URLField.ts15
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;
}