diff options
| author | RblSb <msrblsb@gmail.com> | 2020-02-13 16:28:18 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-02-15 19:45:40 +0300 |
| commit | 07d1955cefc093ffb12002902ed45e963030746e (patch) | |
| tree | 8833eca2dc2ef07891aa8eb66daf7ad90f2ab0ce /src/client/MobileView.hx | |
Initial commit
Diffstat (limited to 'src/client/MobileView.hx')
| -rw-r--r-- | src/client/MobileView.hx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/client/MobileView.hx b/src/client/MobileView.hx new file mode 100644 index 0000000..558df61 --- /dev/null +++ b/src/client/MobileView.hx @@ -0,0 +1,52 @@ +package client; + +import js.html.InputElement; +import js.Browser.document; +import client.Main.ge; + +class MobileView { + + public static function init():Void { + final mvbtn:InputElement = cast ge("#mv_btn"); + mvbtn.onclick = (e) -> { + final mobile_view = toggleFullScreen(); + if (mobile_view) { + document.body.classList.add('mobile-view'); + mvbtn.classList.add('label-success'); + final vwrap = ge("#videowrap"); + if (vwrap.children[0] == ge("currenttitle")) { + vwrap.appendChild(vwrap.children[0]); + } + } else { + document.body.classList.remove('mobile-view'); + mvbtn.classList.remove('label-success'); + final vwrap = ge("videowrap"); + if (vwrap.children[0] != ge("currenttitle")) { + vwrap.insertBefore(vwrap.children[1],vwrap.children[0]); + } + } + } + } + + static function toggleFullScreen():Bool { + var state = true; + final doc:Dynamic = document; + if (document.fullscreenElement == null && + doc.mozFullScreenElement == null && + doc.webkitFullscreenElement == null) { + if (document.documentElement.requestFullscreen != null) { + document.documentElement.requestFullscreen(); + } else if (doc.documentElement.mozRequestFullScreen != null) { + doc.documentElement.mozRequestFullScreen(); + } else if (doc.documentElement.webkitRequestFullscreen != null) { + doc.documentElement.webkitRequestFullscreen(untyped Element.ALLOW_KEYBOARD_INPUT); + } else state = false; + } else { + if (doc.cancelFullScreen != null) doc.cancelFullScreen(); + else if (doc.mozCancelFullScreen != null) doc.mozCancelFullScreen(); + else if (doc.webkitCancelFullScreen != null) doc.webkitCancelFullScreen(); + state = false; + } + return state; + } +} |
