-
Notifications
You must be signed in to change notification settings - Fork 1
/
sukeySettings.js
126 lines (119 loc) · 3.99 KB
/
sukeySettings.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
var canVibrate;
var canUseCompass;
var canUseCamera;
var canUseGeo;
var canUseAjax;
var canUseNativeMap = false;
var SukeyServer = "http://sukey.org/phoneapi";
var URLZoneFromPoint= SukeyServer + "/getZoneFromPoint.php?";
var URLColorWheel = SukeyServer + "/getcolorwheeldata.php?";
var URLVote = SukeyServer + "/vote.php";
var URLTicker= SukeyServer + "/sukey-1.2.php";
var URLReport = SukeyServer + "/report.php";
var URLKML = SukeyServer + "/mapview.kml";
var colorset = {'r':'#ff0000', 'g':'#00ff00', 'a':'#ffaa21'};
function showSettings(){
$('#red').css('background',colorset['r']);
$('#red').val(colorset['r']);
$('#amber').css('background',colorset['a']);
$('#amber').val(colorset['a']);
$('#green').css('background',colorset['g']);
$('#green').val(colorset['g']);
$('#usecamera').attr('checked', canUseCamera);
$('#usecompass').attr('checked', canUseCompass);
$('#usegps').attr('checked', canUseGeo);
$('#usevibrate').attr('checked', canVibrate);
$('#server').val(SukeyServer);
if ($('#about').is( ":visible")){ closeAbout();}
if ($('#reportdiv').is( ":visible")){ $('#reportdiv').hide(); }
$('#settingsdiv').css('zIndex','1006');
$('#settingsdiv').fadeIn();
}
function showcolor(id){
$('#'+id).css('background',$('#'+id).val());
}
function saveSettings(){
writestring = '';
colorset['r'] = $('#red').val();
writestring += "Red=" + colorset['r'] + "\n";
colorset['a'] = $('#amber').val();
writestring += "Amber=" + colorset['a'] + "\n";
colorset['g'] = $('#green').val();
writestring += "Green=" + colorset['g'] + "\n";
canUseCamera = $('#usecamera').attr('checked');
writestring += "camera=" + canUseCamera + "\n";
canUseCompass = $('#usecompass').attr('checked');
writestring += "compass=" + canUseCompass + "\n";
canUseGeo = $('#usegps').attr('checked');
writestring += "gps=" + canUseGeo + "\n";
canVibrate = $('#usevibrate').attr('checked');
writestring += "vibrate=" + canVibrate + "\n";
SukeyServer = $('#server').val();
writestring += "server=" + SukeyServer + "\n";
setPaths();
writeSettings(writestring);
$('#settingsdiv').fadeOut();
initialise();
}
function cancelSettings(){
$('#settingsdiv').fadeOut();
}
function setPaths() {
URLZoneFromPoint= SukeyServer + "/getZoneFromPoint.php?";
URLColorWheel = SukeyServer + "/getcolorwheeldata.php?";
URLTicker= SukeyServer + "/sukey-1.2.php";
URLReport = SukeyServer + "/report.php";
URLVote = SukeyServer + "/vote.php";
URLKML = SukeyServer + "/mapview.kml";
}
function readSettings(){
var paths = navigator.fileMgr.getRootPaths();
var reader = new FileReader();
reader.onload = gotFile;
reader.onerror = readFailure;
reader.readAsText(paths[0] + "sukeySettings.txt");
}
function writeSettings(writeString){
var paths = navigator.fileMgr.getRootPaths();
var writer = new FileWriter(paths[0] + "sukeySettings.txt");
//writer.onwrite = writeSuccess;
writer.onerror = writeFailure;
writer.write(writeString);
}
function writeSuccess(){
//alert("File written");
}
function writeFailure(){
alert("File NOT written");
}
function gotFile(evt) {
var lines = evt.target.result.split("\n");
for (i=0; i< lines.length; i++){
line = lines[i].split('=');
//alert (line[0] + ','+ line[1]);
switch (line[0]){
case "Red":
colorset['r'] = line[1];break;
case "Amber":
colorset['a'] = line[1];break;
case "Green":
colorset['g'] = line[1];break;
case "camera":
canUseCamera = (line[1] ==="true");break;
case "compass":
canUseCompass = (line[1] ==="true");break;
case "gps":
canUseGeo = (line[1] ==="true");break;
case "vibrate":
canVibrate = (line[1] ==="true");break;
case "server":
SukeyServer = line[1];break;
default:
break;
}
}
setPaths();
}
function readFailure(evt){
//alert("Couldn't read stored configuration - using defaults");
}