diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/Buttons.hx | 24 | ||||
| -rw-r--r-- | src/client/JsApi.hx | 2 | ||||
| -rw-r--r-- | src/client/Utils.hx | 25 |
3 files changed, 47 insertions, 4 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index 7df6486..86a7d82 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -255,9 +255,27 @@ class Buttons { final removeBtn = ge("#removeVideoBtn"); removeBtn.onclick = e -> { - final has = main.toggleVideoElement(); - if (has || main.isListEmpty()) removeBtn.innerText = Lang.get("removeVideo"); - else removeBtn.innerText = Lang.get("addVideo"); + final hasVideo = main.toggleVideoElement(); + if (hasVideo || main.isListEmpty()) { + removeBtn.innerText = Lang.get("removeVideo"); + } else { + removeBtn.innerText = Lang.get("addVideo"); + } + } + final setVideoUrlBtn = ge("#setVideoUrlBtn"); + setVideoUrlBtn.onclick = e -> { + final src = window.prompt(Lang.get("setVideoUrlPrompt")); + if (src.trim() == "") { // reset to default url + main.refreshPlayer(); + return; + } + JsApi.setVideoSrc(src); + } + final selectLocalVideoBtn = ge("#selectLocalVideoBtn"); + selectLocalVideoBtn.onclick = e -> { + Utils.browseFileUrl((url:String, name:String) -> { + JsApi.setVideoSrc(url); + }); } } diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index 4d98478..d9e6f02 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -104,7 +104,7 @@ class JsApi { } @:expose - static function setVideoSrc(src:String):Void { + public static function setVideoSrc(src:String):Void { player.changeVideoSrc(src); } diff --git a/src/client/Utils.hx b/src/client/Utils.hx index de6b16c..232ca02 100644 --- a/src/client/Utils.hx +++ b/src/client/Utils.hx @@ -3,6 +3,7 @@ package client; import js.Browser.document; import js.Browser.window; import js.html.Element; +import js.html.URL; class Utils { public static function isTouch():Bool { @@ -87,4 +88,28 @@ class Utils { document.body.removeChild(textarea); } } + + public static function browseFileUrl( + onFileLoad:(url:String, name:String) -> Void, + isBinary = true, + revoke = false + ):Void { + final input = document.createElement("input"); + input.style.visibility = "hidden"; + input.setAttribute("type", "file"); + input.id = "browse"; + input.onclick = function(e) { + e.cancelBubble = true; + e.stopPropagation(); + } + input.onchange = function() { + final file:Dynamic = (input : Dynamic).files[0]; + final url = URL.createObjectURL(file); + onFileLoad(url, file.name); + document.body.removeChild(input); + if (revoke) URL.revokeObjectURL(url); + } + document.body.appendChild(input); + input.click(); + } } |
