-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontrols.js
153 lines (142 loc) · 3.53 KB
/
controls.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Conrols
* v0.4 - May 15, 2016
* Hirad Sab; GNU/GPL License
* http://hiradsab.com
*
* Collection of helper methods for UI manipulation, requirement checking,
* device recognition, and URL parsing.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 or later.
* http://www.gnu.org/licenses/
*/
/**
* Variable indicating nature of device
* @type {Boolean}
*/
var is_mobile = false;
/**
* True if WebGL is supported, false otherwise.
* @type {Boolean}
*/
var is_webgl;
/**
* Visual quality, parsed from URL ?quality parameter.
* Can accept values of "low", "high" and "ultra".
* @type {String}
*/
var quality = ""
/**
* String parsed from ?start URL parameter, indicating if
* experience should be started immediately on page load.
* @type {String}
*/
var start = "false";
/**
* Series of requirement checking and UI manipulation after
* loading of DOM content.
*/
$(document).ready(function(){
is_mobile = detect_mobile();
is_webgl = detect_webgl();
$(".regular-controls").hide();
$("#webgl-message").hide();
$("#vr-message").hide();
if (is_webgl[0]){
// WebGL is supported
if (is_mobile){
// Device is Mobile
$(".desktop-buttons").hide();
}
else {
// Device is not mobile
$(".mobile-buttons").hide();
if (navigator.getVRDisplays) {
// VR is supported
}
else {
// VR is not supported
$(".vr-button").hide();
$(".regular-button").text("Enter");
$("#vr-message").show();
}
}
}
else {
// WebGL is not supported
$("#webgl-message").show();
$("#webgl-error").text(is_webgl[1]);
$("#vr-message").hide();
$(".mobile-buttons").hide();
$(".desktop-buttons").hide();
}
url_parser();
});
/**
* Responsible for parsing URL parameters and setting the
* options appropriately
*/
function url_parser(){
try {
quality = url('?quality').replace(/\/$/, "");
}catch(e){};
if (is_mobile) {
quality = "high";
}
try {
start = url('?start').replace(/\/$/, "");
}catch(e){};
if (start == "true") {
load_regular();
}
history.replaceState("", "Eluded VR", "/");
}
/**
* Detects if user's device is mobile or not.
* @return {Boolean} [True if mobile, false otherwise]
*/
function detect_mobile() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)) {
return true;
} else {
return false;
}
};
/**
* Detects if user's device supports WebGL or not.
* @return {Array} [Boolean: True if enabled, String: Support Message]
*/
function detect_webgl()
{
if (!!window.WebGLRenderingContext) {
var canvas = document.createElement("canvas"),
names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"],
context = false;
for(var i=0;i<4;i++) {
try {
context = canvas.getContext(names[i]);
if (context && typeof context.getParameter == "function") {
return [true, "WebGL is supported and enabled."];
}
} catch(e) {}
}
return [false, "Error: WebGL is supported but disabled."];
}
return [false, "Error: WebGL is not supported."];
}
/**
* Hides the UI elements for WebGL canvas initialization.
*/
function hide_ui(){
$(".ui").hide();
$(".bg").hide();
$(".footer").hide();
}