Refactor home.js into several files
This commit is contained in:
parent
0c3aad4f5f
commit
cfbfe0c227
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -174,7 +174,7 @@ function pingServer() {
|
||||
$.get(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
function onError(error) {
|
||||
$('#loading-error').text("Check your device's network and location settings, and ensure a clear view of the sky.");
|
||||
}
|
||||
@ -208,152 +208,3 @@ setInterval(pingServer, 5000);
|
||||
setTimeout(function () {
|
||||
onError();
|
||||
}, 15 * 1000);
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
@ -91,9 +91,36 @@ function scanCode() {
|
||||
}
|
||||
|
||||
function sortResults(array, prop, asc) {
|
||||
array = array.sort(function(a, b) {
|
||||
if (asc) return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
array = array.sort(function (a, b) {
|
||||
if (asc)
|
||||
return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else
|
||||
return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
120
platforms/android/assets/www/js/user.js
Normal file
120
platforms/android/assets/www/js/user.js
Normal file
@ -0,0 +1,120 @@
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
@ -54,4 +54,5 @@
|
||||
$('#namedisp').text(username);
|
||||
navigator.splashscreen.hide();
|
||||
</script>
|
||||
<script src="js/home.js"></script>
|
||||
<script src="js/location.js"></script>
|
||||
<script src="js/user.js"></script>
|
@ -1,3 +1,10 @@
|
||||
<div class="scrollable-box">
|
||||
|
||||
<div class="list-group" id="inventory-list">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function loadinventory() {
|
||||
|
||||
}
|
||||
</script>
|
@ -1,5 +1,8 @@
|
||||
<div class="scrollable-box">
|
||||
<div class='list-group'>
|
||||
<div class='list-group-item' onclick='openIntro()'>
|
||||
Show Introduction
|
||||
</div>
|
||||
<div class='list-group-item' onclick='openRules()'>
|
||||
Show Rules
|
||||
</div>
|
||||
@ -8,13 +11,13 @@
|
||||
</div>
|
||||
<div class='list-group-item'>
|
||||
<p>
|
||||
<span style='font-weight: bold;'>Third-Party Licenses</span>
|
||||
<span style='font-weight: bold;'>Cool Stuff We Stole</span>
|
||||
<br />
|
||||
Map tiles by Stamen Design (stamen.com), under CC BY 3.0 (creativecommons.org/licenses/by/3.0).
|
||||
<br />
|
||||
Map tile data by OpenStreetMap (openstreetmap.org), under CC BY-SA (creativecommons.org/licenses/by-sa/3.0).
|
||||
<br />
|
||||
Places from OpenStreetMap and contributers, licensed under the ODbL (opendatacommons.org/licenses/odbl). Email apis@netsyms.com for free access to our API.
|
||||
Places from OpenStreetMap and contributers, licensed under the ODbL (opendatacommons.org/licenses/odbl).
|
||||
<br />
|
||||
Map display is powered by Leaflet (leafletjs.com), copyright (c) 2010-2016, Vladimir Agafonkin and copyright (c) 2010-2011, CloudMade. BSD 2-clause license.
|
||||
<br />
|
||||
@ -23,6 +26,8 @@
|
||||
Weather data Powered by Forecast (forecast.io).
|
||||
<br />
|
||||
Geocache data from the OpenCaching.US OKAPI. Data licensed under the CC BY-NC-SA 2.5 (creativecommons.org/licenses/by-nc-sa/2.5).
|
||||
<br />
|
||||
If you're a developer, you might be interested in this: earth.apis.netsyms.net
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -174,7 +174,7 @@ function pingServer() {
|
||||
$.get(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
function onError(error) {
|
||||
$('#loading-error').text("Check your device's network and location settings, and ensure a clear view of the sky.");
|
||||
}
|
||||
@ -208,152 +208,3 @@ setInterval(pingServer, 5000);
|
||||
setTimeout(function () {
|
||||
onError();
|
||||
}, 15 * 1000);
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
@ -91,9 +91,36 @@ function scanCode() {
|
||||
}
|
||||
|
||||
function sortResults(array, prop, asc) {
|
||||
array = array.sort(function(a, b) {
|
||||
if (asc) return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
array = array.sort(function (a, b) {
|
||||
if (asc)
|
||||
return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else
|
||||
return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
120
platforms/browser/www/js/user.js
Normal file
120
platforms/browser/www/js/user.js
Normal file
@ -0,0 +1,120 @@
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
@ -54,4 +54,5 @@
|
||||
$('#namedisp').text(username);
|
||||
navigator.splashscreen.hide();
|
||||
</script>
|
||||
<script src="js/home.js"></script>
|
||||
<script src="js/location.js"></script>
|
||||
<script src="js/user.js"></script>
|
@ -1,3 +1,10 @@
|
||||
<div class="scrollable-box">
|
||||
|
||||
<div class="list-group" id="inventory-list">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function loadinventory() {
|
||||
|
||||
}
|
||||
</script>
|
@ -1,5 +1,8 @@
|
||||
<div class="scrollable-box">
|
||||
<div class='list-group'>
|
||||
<div class='list-group-item' onclick='openIntro()'>
|
||||
Show Introduction
|
||||
</div>
|
||||
<div class='list-group-item' onclick='openRules()'>
|
||||
Show Rules
|
||||
</div>
|
||||
@ -8,13 +11,13 @@
|
||||
</div>
|
||||
<div class='list-group-item'>
|
||||
<p>
|
||||
<span style='font-weight: bold;'>Third-Party Licenses</span>
|
||||
<span style='font-weight: bold;'>Cool Stuff We Stole</span>
|
||||
<br />
|
||||
Map tiles by Stamen Design (stamen.com), under CC BY 3.0 (creativecommons.org/licenses/by/3.0).
|
||||
<br />
|
||||
Map tile data by OpenStreetMap (openstreetmap.org), under CC BY-SA (creativecommons.org/licenses/by-sa/3.0).
|
||||
<br />
|
||||
Places from OpenStreetMap and contributers, licensed under the ODbL (opendatacommons.org/licenses/odbl). Email apis@netsyms.com for free access to our API.
|
||||
Places from OpenStreetMap and contributers, licensed under the ODbL (opendatacommons.org/licenses/odbl).
|
||||
<br />
|
||||
Map display is powered by Leaflet (leafletjs.com), copyright (c) 2010-2016, Vladimir Agafonkin and copyright (c) 2010-2011, CloudMade. BSD 2-clause license.
|
||||
<br />
|
||||
@ -23,6 +26,8 @@
|
||||
Weather data Powered by Forecast (forecast.io).
|
||||
<br />
|
||||
Geocache data from the OpenCaching.US OKAPI. Data licensed under the CC BY-NC-SA 2.5 (creativecommons.org/licenses/by-nc-sa/2.5).
|
||||
<br />
|
||||
If you're a developer, you might be interested in this: earth.apis.netsyms.net
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -174,7 +174,7 @@ function pingServer() {
|
||||
$.get(mkApiUrl('ping') + "?user=" + username + "&lat=" + latitude + "&long=" + longitude);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
function onError(error) {
|
||||
$('#loading-error').text("Check your device's network and location settings, and ensure a clear view of the sky.");
|
||||
}
|
||||
@ -208,152 +208,3 @@ setInterval(pingServer, 5000);
|
||||
setTimeout(function () {
|
||||
onError();
|
||||
}, 15 * 1000);
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
@ -91,9 +91,36 @@ function scanCode() {
|
||||
}
|
||||
|
||||
function sortResults(array, prop, asc) {
|
||||
array = array.sort(function(a, b) {
|
||||
if (asc) return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
array = array.sort(function (a, b) {
|
||||
if (asc)
|
||||
return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
|
||||
else
|
||||
return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Other things
|
||||
//////////////////////////////////////////////
|
||||
|
||||
function closeMain() {
|
||||
$('#overlay-main').slideDown(100, function () {
|
||||
$('#overlay-main').css('display', 'none');
|
||||
$('#main-content').html("");
|
||||
});
|
||||
}
|
||||
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
if ($('#overlay-main').css('display') !== 'none') {
|
||||
closeMain();
|
||||
} else if ($('#chatmsgs').css('display') !== 'none') {
|
||||
toggleChat();
|
||||
}
|
||||
}, false);
|
||||
// Show the rules
|
||||
if (localStorage.getItem("seenintro") !== 'yes') {
|
||||
openIntro();
|
||||
localStorage.setItem("seenintro", 'yes');
|
||||
}
|
120
www/js/user.js
Normal file
120
www/js/user.js
Normal file
@ -0,0 +1,120 @@
|
||||
//////////////////////////////////////////////
|
||||
// Profile, stats, and chat stuff
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
* Handles general server communication.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Syncs the user's stats with the server and calls refreshStats().
|
||||
*/
|
||||
function syncStats() {
|
||||
$.getJSON(mkApiUrl('getstats'), {
|
||||
user: username
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
maxenergy = data.stats.maxenergy;
|
||||
energy = data.stats.energy;
|
||||
level = data.stats.level;
|
||||
refreshStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current stats on the home screen.
|
||||
*/
|
||||
function refreshStats() {
|
||||
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
|
||||
$('#energybar').css('width', String(energypercent) + '%');
|
||||
}
|
||||
|
||||
function getChat() {
|
||||
if (lockGot) {
|
||||
$.getJSON(mkApiUrl('chat', 'cs'), {
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}, function (data) {
|
||||
data = sortResults(data, 'time', true);
|
||||
var content = "";
|
||||
data.forEach(function (msg) {
|
||||
content += "<span class='chat-username' onclick='openProfile(\"" + msg.username + "\");'>" + msg.username + "</span> " + msg.message + "<br />";
|
||||
});
|
||||
$('#chatmsgs').html(content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncStats();
|
||||
setInterval(function () {
|
||||
syncStats();
|
||||
}, 10 * 1000);
|
||||
setInterval(function () {
|
||||
getChat();
|
||||
}, 2000);
|
||||
// Send chat messages
|
||||
$("#chatsendform").submit(function (event) {
|
||||
message = $('#chatbox-input').val();
|
||||
if (message !== '') {
|
||||
$.post(mkApiUrl('chat', 'cs'), {
|
||||
user: username,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
msg: message
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#chatbox-input').val("");
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
function toggleChat() {
|
||||
if ($('#chatmsgs').css('display') === 'none') {
|
||||
openChat();
|
||||
} else {
|
||||
closeChat();
|
||||
}
|
||||
}
|
||||
|
||||
function closeChat() {
|
||||
$('#chatmsgs').css('display', 'none');
|
||||
$('#chatbox').css('height', 'auto');
|
||||
}
|
||||
|
||||
function openChat() {
|
||||
$('#chatbox').css('height', '50%');
|
||||
$('#chatmsgs').css('display', 'block');
|
||||
$("#chatmsgs").animate({scrollTop: $('#chatmsgs').prop("scrollHeight")}, 1000);
|
||||
}
|
||||
|
||||
function openProfile(user) {
|
||||
user = typeof user !== 'undefined' ? user : username;
|
||||
$('#main-content').load("screens/profile.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
loadProfile(user);
|
||||
});
|
||||
}
|
||||
|
||||
function openRules() {
|
||||
openmodal('rules', '#rules-modal');
|
||||
}
|
||||
|
||||
function openIntro() {
|
||||
openmodal('intro', '#intro-modal');
|
||||
}
|
||||
|
||||
function openMenu(topage) {
|
||||
topage = typeof topage !== 'undefined' ? topage : "";
|
||||
$('#main-content').load("screens/menu.html", null, function (x) {
|
||||
$('#overlay-main').css('display', 'block');
|
||||
if (topage !== '') {
|
||||
$('#' + topage + '-tab').tab('show');
|
||||
}
|
||||
});
|
||||
}
|
@ -54,4 +54,5 @@
|
||||
$('#namedisp').text(username);
|
||||
navigator.splashscreen.hide();
|
||||
</script>
|
||||
<script src="js/home.js"></script>
|
||||
<script src="js/location.js"></script>
|
||||
<script src="js/user.js"></script>
|
@ -1,3 +1,10 @@
|
||||
<div class="scrollable-box">
|
||||
|
||||
<div class="list-group" id="inventory-list">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function loadinventory() {
|
||||
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user