diff options
| author | RblSb <msrblsb@gmail.com> | 2021-08-01 14:33:27 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-08-01 14:33:27 +0300 |
| commit | b8827aa6df5c58fb5655c8519477ea93694617f3 (patch) | |
| tree | cf67b50990a2864dd8ffe9b094b24241aae48ef3 /src/client/Utils.hx | |
| parent | 530bee28a0baa653e2be73cba525bd38d5e04b5e (diff) | |
Way to change video src on client
see #27
Diffstat (limited to 'src/client/Utils.hx')
| -rw-r--r-- | src/client/Utils.hx | 25 |
1 files changed, 25 insertions, 0 deletions
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(); + } } |
