Original Project

This commit is contained in:
Florian Zumpe
2026-06-16 09:17:23 +02:00
commit e607876d37
229 changed files with 41422 additions and 0 deletions
+810
View File
File diff suppressed because one or more lines are too long
Executable
+39
View File
@@ -0,0 +1,39 @@
// From: https://developer.mozilla.org/de/docs/AJAX/Einf%C3%BChrung
var ajax = function(target, callback) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
return false;
}
http_request.onreadystatechange = gotResponse;
http_request.open('GET', target, true);
http_request.send(null);
function gotResponse() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if(callback != null) callback(http_request.responseText);
} else {
alert('Bei dem Request ist ein Problem aufgetreten.');
}
}
}
}
Executable
+6
View File
@@ -0,0 +1,6 @@
var scriptSettings = {
debug: true,
showDump: true,
showConsole: false,
}
Executable
+55
View File
@@ -0,0 +1,55 @@
/****************************************************************************************************************
* CLASS console: helper to make console-object available if not present *
* implemented as singleton-object *
* *
* methods: debug(args: variable number and type of arguments):void - dump parameters to console *
* *
* remarks: creates a css-styled div fixed on bottom of visible screen, if console-object is created *
****************************************************************************************************************/
if (!console)
{
console = {
create: function() {
$('body').append($('<div id="console"></div>'));
$('head').append($([
'<style type="text/css">',
' #console {',
' position: fixed;',
' bottom: 0;',
' left: 0;',
' right: 0;',
' z-index: 9998;',
' height: 12em;',
' line-height: 1.2em;',
' font-size: 0.8em;',
' background-color: rgb(220,220,220);',
' overflow-y: scroll;',
' }',
'</style>'
].join("\n")));
},
debug: function() {
var time = new Date();
$.each(arguments, function(key, data) {
$('#console').html(
$('#console').html()
+(
'('
+ ('0' + time.getHours()).substr(-2)
+ ':'
+ ('0' + time.getMinutes()).substr(-2)
+ ':'
+ ('0' + time.getSeconds()).substr(-2)
+ ') '
+ JSON.stringify(data)
+ ' ['
+ typeof(data)
+ ']'
).replace(/[\r\n]{1,1}/g, '<br />')
+'<br />'
).scrollTop($("#console").prop("scrollHeight"))
});
}
}
}
+57
View File
@@ -0,0 +1,57 @@
/****************************************************************************************************************
* CLASS DB: contains all data about routes and linked pois *
* *
* Events: body.databaseLoaded(database:DB) *
* *
* Returns: Array of routes in format *
* Object{ *
* id:Number, *
* name:String, *
* image:String, *
* languages:Array(String), *
* pois:Array(Object{ *
* lat:Number, *
* lon:Number, *
* desc:String, *
* range:Number, *
* audio:Number *
* } *
* } *
****************************************************************************************************************/
function DB() {
var that = this;
this._routes = []; // format: {id:0, name:'', image:'', languages:[], pois:[{lat:0, lon:0, desc:'', range:0, audio:0}]}
this._completeTracks = Array();
this._init = function() {
$('#database-loading').slideDown({duration: 500});
console.debug('loading database');
$.getJSON('database.php', {'get':'routes'}, function(data) {
console.debug('database: routes received');
data.forEach(function(track) {
//console.debug(id, track);
that._completeTracks[track.id] = false;
$.getJSON('database.php', {'get':'pois','id':track.id}, function(pois) {
console.debug(track.name, pois);
// console.debug('database: '+pois.length+' pois for '+track.name+' received');
track.pois = pois;
that._routes[track.id] = (track);
that._completeTracks[track.id] = true;
//console.debug('track done:', track);
if (that._completeTracks.reduce(function(prev, curr) { return (prev && curr); }, true)) { //tracks complete ?
$('#database-loading').slideUp({duration: 500});
console.debug('database loaded');
$('body').trigger('databaseLoaded', that);
}
});
});
});
}
this._init();
return this._routes;
}
+27
View File
@@ -0,0 +1,27 @@
// From: http://phpperformance.de/javascript-event-onload-und-die-bessere-alternative/
//create onDomReady Event
window.onDomReady = initReady;
// Initialize event depending on browser
function initReady(fn)
{
//W3C-compliant browser
if(document.addEventListener) {
document.addEventListener("DOMContentLoaded", fn, false);
}
//IE
else {
document.onreadystatechange = function(){readyState(fn)}
}
}
//IE execute function
function readyState(func)
{
// DOM is ready
if(document.readyState == "interactive" || document.readyState == "complete")
{
func();
}
}
+176
View File
@@ -0,0 +1,176 @@
/****************************************************************************************************************
* CLASS geoLocation: helper-class for fetching geolocation (among others latitude, longitude) *
* implemented as singleton-object *
* *
* methods: init(void):void --> initialize object and start fetching position *
* startWatcher(void):void --> starts intervalled position-watching (ran by init) *
* getPosFromServer(void):void --> fetch GPS-position from server (actually one fixed point) *
* distance(Object{lat:Number ,lon:Number} [,Object{lat:Number ,lon:Number}]):Number *
* └-> distance between two positions (or given and current one, if second one missing) *
* *
* events: body.geoLocationError:Object{ *
* error:Object{ *
* number:Number, *
* message:String *
* }, *
* position:Object{ *
* latitude:Number, *
* longitude:Number, *
* accuracy:Number, *
* timestamp:Number *
* } *
* } *
* body.geoLocationGot:Object{ *
* position:Object{ *
* latitude:Number, *
* longitude:Number, *
* accuracy:Number, *
* timestamp:Number *
* } *
* } *
****************************************************************************************************************/
var geoLocation = { // implement as singleton
latitude: null,
longitude: null,
accuracy: null,
timestamp: null,
_pwatcher: null,
_ptimer: null,
_disableWatcherAt: 50,
_config: {
enableHighAccuracy: true,
maximumAge: 10000, // 10 sec max cache lifetime (if geoposition cached)
timeout: 60000 // 60 sec timeout
},
// event listeners
_geoReady: function(position) {
console.debug('geolocation api present - activate watcher');
// this.startWatcher();
// this._gotLocation(position);
},
_geoError: function(error) {
console.debug('gelocation api not present or error');
this._handle_error(error);
},
_gotLocation: function(position) {
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
this.accuracy = position.coords.accuracy;
this.timestamp = position.timestamp;
if (this.accuracy <= this._disableWatcherAt) // disable with timeout, if accurate location found
{
console.debug('disable watcher for 60 seconds', this._pwatcher);
if (this._pwatcher !== null)
{
console.debug('watcher cleared');
navigator.geolocation.clearWatch(this._pwatcher);
this._pwatcher = null;
}
that = this;
this._ptimer = setTimeout(function() {that.startWatcher.apply(that, arguments);}, 60000);
}
console.debug('got Position: ' + this.latitude + ', ' + this.longitude + '(' + this.accuracy + 'm < ' + this._disableWatcherAt + ': ' + (this.accuracy <= this._disableWatcherAt) + ')');
$('body').trigger('geoLocationGot', {'position':{latitude: this.latitude, longitude: this.longitude, accuracy: this.accuracy, timestamp: this.timestamp}});
},
_handle_error: function(error) {
console.debug(error);
switch(error.code)
{
case error.PERMISSION_DENIED:
if (_pwatcher != 'null') navigator.geolocation.clearWatch(_pwatcher);
_pwatcher = 'null';
break;
case error.POSITION_UNAVAILABLE:
break;
case error.TIMEOUT:
break;
default:
break;
}
$('body').trigger('geoLocationError',{'error':error,'position':{latitude: this.latitude, longitude: this.longitude, accuracy: this.accuracy, timestamp: this.timestamp}});
},
init: function() {
var that = this;
if (navigator.geolocation) {
console.debug('test geolocation api');
navigator.geolocation.getCurrentPosition(
function() {that._geoReady.apply(that, arguments);},
function() {that._geoError.apply(that, arguments);},
this._config
);
}
},
startWatcher: function() {
console.debug('waiting for location');
that = this;
if (this._pwatcher !== null) navigator.geolocation.clearWatch(this._pwatcher);
clearTimeout(this._ptimer);
this._pwatcher = navigator.geolocation.watchPosition(
function() {that._gotLocation.apply(that, arguments);},
function() {that._handle_error.apply(that, arguments);},
this._config
);
console.debug('watcher started',this._pwatcher);
},
getPosFromServer: function() {
console.debug('get position from server');
that = this;
$.getJSON('shippos.php', function(data) {
console.debug('got server response: ',data);
that._gotLocation.call(that, data);
});
},
//haversine formula for distance between two positions in m (see http://www.movable-type.co.uk/scripts/latlong.html)
distance:function(c1,c2)
{
PI180=Math.PI / 180;
if(!c1) return false;
if(!c2){ c2={'latitude':this.latitude, 'longitude':this.longitude}; }
var dLat = (c2.latitude-c1.latitude) * PI180; // delta in rad
var dLon = (c2.longitude-c1.longitude) * PI180;
var lat1 = c1.latitude * PI180;
var lat2 = c2.latitude * PI180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return (6371000 * c); // earth-radius in m * 1000
}
}; // geoLocation
$(document).ready(function() {
$('body').on('geoLocationGot', function(e) {
$('#no-gps').slideUp({duration: 500});
});
$('body').on('geoLocationError',function(e) {
$('#no-gps').slideDown({duration: 500});
});
geoLocation.init();
});
Executable
+39
View File
@@ -0,0 +1,39 @@
/****************************************************************************************************************
* CLASS vibrate: helper-class for using vibration on mobiles *
* *
* methods: start(duration:Number or Array(Number)):void --> starts vibrating for given amount of ms *
* └-> may also be an array with format: [vibrate,pause,vibrate,pause...] in ms *
* *
* stop(void):void --> stops vibrating *
* *
* objects: patterns --> predefined vibration-patterns *
****************************************************************************************************************/
var vibrate = {
start: function(duration) {
if (duration==undefined || duration==null) duration = this.patterns.long;
duration = [duration].reduce(function(a, b) { return [].concat(a).concat(b); });
if (navigator.vibrate) {
navigator.vibrate(duration);
}
console.debug('vibrate:', duration);
},
stop: function() {
if (navigator.vibrate) {
console.debug('stop vibrating');
navigator.vibrate([]);
}
},
patterns: {
micro: 50,
mini: 100,
short: 200,
long: 2000,
alarm: [100,50,100],
poi: [2000,200,2000]
}
}