diff options
author | anika-ahluwalia <anika.ahluwalia@gmail.com> | 2020-05-15 13:26:37 -0500 |
---|---|---|
committer | anika-ahluwalia <anika.ahluwalia@gmail.com> | 2020-05-15 13:26:37 -0500 |
commit | 4bca98333ada6536a1bf2ecf1681c5c17a3a1ae1 (patch) | |
tree | 7fc20099971de42756af3d238e2ea4f9a608cbd3 /src/fields/URLField.ts | |
parent | 0f54ef61653213bd1b26300cb7d14e3da71d1eea (diff) | |
parent | 98c7540fff67c232c1b04f2130ee624f9a70afbd (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into script_documents
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r-- | src/fields/URLField.ts | 53 |
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 { } + |