aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/MobileView.hx
blob: 976958b51ae049384217c152854fcf73f509a325 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package client;

import js.Browser.document;
import client.Main.ge;

class MobileView {

	public static function init():Void {
		final mvbtn = ge("#mv_btn");
		mvbtn.onclick = e -> {
			final mobileView = toggleFullScreen();
			if (mobileView) {
				document.body.classList.add('mobile-view');
				mvbtn.classList.add('active');
				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('active');
				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;
	}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage