aboutsummaryrefslogtreecommitdiff
path: root/src/fields/URLField.ts
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2020-05-20 22:18:13 -0700
committerStanley Yip <stanley_yip@brown.edu>2020-05-20 22:18:13 -0700
commit1113da5f2db22bd2b2b457b1f5b183d7f1f2e68d (patch)
treea559fa400fedb87799cba4f85451460f649c46dd /src/fields/URLField.ts
parent4109fea6787608022c8f5c147fa4fb9ad26e92eb (diff)
parent45386f6950e5ae8390486900a430061bfe9e4846 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r--src/fields/URLField.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/fields/URLField.ts b/src/fields/URLField.ts
new file mode 100644
index 000000000..fb71160ca
--- /dev/null
+++ b/src/fields/URLField.ts
@@ -0,0 +1,53 @@
+import { Deserializable } from "../client/util/SerializationHelper";
+import { serializable, custom } from "serializr";
+import { ObjectField } from "./ObjectField";
+import { ToScriptString, ToString, Copy } from "./FieldSymbols";
+import { Scripting, scriptingGlobal } from "../client/util/Scripting";
+
+function url() {
+ return custom(
+ function (value: URL) {
+ return value.href;
+ },
+ function (jsonValue: string) {
+ return new URL(jsonValue);
+ }
+ );
+}
+
+export abstract class URLField extends ObjectField {
+ @serializable(url())
+ readonly url: URL;
+
+ constructor(url: string);
+ constructor(url: URL);
+ constructor(url: URL | string) {
+ super();
+ if (typeof url === "string") {
+ url = new URL(url);
+ }
+ this.url = url;
+ }
+
+ [ToScriptString]() {
+ return `new ${this.constructor.name}("${this.url.href}")`;
+ }
+ [ToString]() {
+ return this.url.href;
+ }
+
+ [Copy](): this {
+ return new (this.constructor as any)(this.url);
+ }
+}
+
+export const nullAudio = "https://actions.google.com/sounds/v1/alarms/beep_short.ogg";
+
+@scriptingGlobal @Deserializable("audio") export class AudioField extends URLField { }
+@scriptingGlobal @Deserializable("image") export class ImageField extends URLField { }
+@scriptingGlobal @Deserializable("video") export class VideoField extends URLField { }
+@scriptingGlobal @Deserializable("pdf") export class PdfField extends URLField { }
+@scriptingGlobal @Deserializable("web") export class WebField extends URLField { }
+@scriptingGlobal @Deserializable("youtube") export class YoutubeField extends URLField { }
+@scriptingGlobal @Deserializable("webcam") export class WebCamField extends URLField { }
+