fb: {},
winwidth: 0,
winheight: 0,
+ touchtimer: null,
+ longtouch: false,
init: function(event_cb) {
// width and height auf io and map window
- ui.height=$(document).height();
- ui.width=$(document).width();
+ var bw=1;
+ ui.height=$(window).height();
+ ui.width=$(window).width();
cl("init: width="+ui.width+", height="+ui.height);
ui.winwidth=(ui.width-1)/2;
ui.winheight=ui.height;
ui.winheight=(ui.height-1)/2;
}
cl("init: winwidth="+ui.winwidth+", winheight="+ui.winheight);
- $('#io').css('width',ui.winwidth);
- $('#io').css('height',ui.winheight);
- $('#map').css('width',ui.winwidth);
- $('#map').css('height',ui.winheight);
+ $('#io').css('width',ui.winwidth-2*bw);
+ $('#io').css('height',ui.winheight-2*bw);
+ $('#io').css('border',bw+"px solid black");
+ $('#map').css('width',ui.winwidth-2*bw);
+ $('#map').css('height',ui.winheight-2*bw);
+ $('#map').css('border',bw+"px solid black");
// io events (navigation)
$('.ionavbtn').click(function(event) {
ui.nav_event(event);
});
// io events (ctrl, info and settings windows)
$('.fwbtn').click(function(event) {
- event_cb(event,'switch');
+ event_cb(event,'click');
});
$('.hwbtn').click(function(event) {
- event_cb(event,'switch');
+ event_cb(event,'click');
});
$('.twbtn').click(function(event) {
- event_cb(event,'switch');
+ event_cb(event,'click');
+ });
+ // click and long click events
+ $('.longclickbtn').mouseup(function(event) {
+ clearTimeout(ui.touchtimer);
+ if(!ui.longtouch) {
+ event_cb(event,'click');
+ ui.longclick($(this).attr('data-id'),false);
+ }
+ return false;
+ });
+ $('.longclickbtn').mousedown(function(event) {
+ ui.longtouch=false;
+ ui.touchtimer=setTimeout(function() {
+ ui.longtouch=true;
+ var did=$(event.target).attr('data-id');
+ ui.longclick(Number(did),true);
+ event_cb(event,'longclick');
+ },500);
+ return false;
});
},
+ longclick: function(did,long) {
+ var str="click event: "+did;
+ if(long)
+ str="long"+str;
+ cl(str);
+ },
draw: function() {
ui.draw_io();
ui.draw_map();
$(id).html(txt);
}
$(trg).css('background-color',col);
- }
+ },
+
}
var geo = {
else {
cb(geo.loc,'unsupported');
}
+ },
+ loc2ll: function(loc) {
+ var ll={};
+ if('coords' in loc) {
+ ll[0]=loc.coords.latitude;
+ ll[1]=loc.coords.longitue;
+ }
+ else if('latitude' in loc) {
+ ll[0]=loc.latitude;
+ ll[0]=loc.longitude;
+ }
+ else {
+ return loc;
+ }
+ return ll;
}
};
init: function() {
document.addEventListener('deviceready',this.startup,false);
window.addEventListener('orientationchange',function() {
- alert("gp: orientational change detected");
+ alert("change in orientation detected, rotating ...");
ui.init();
ui.draw();
});
dbcallback: function() {
// stored location
idb.get_store_items('geo',function(item) {
- var str='('+item[1].coords[0].toFixed(3)+','+
- item[1].coords[1].toFixed(3)+')';
- var str='Store location '+str;
+ var str="Update locion";
+ if(!item[1].update) {
+ var ll=geo.loc2ll(geo.loc);
+ str="Stored location<br>"+
+ ll[0].toFixed(3)+","+ll[1].toFixed(3)+")";
+ }
ui.draw_content('ioctrlstore',str);
+ ui.set_switch('ioctrlstore',item[1].update);
gp.status.geo.coords=item[1].coords;
},0,-1);
// map settings
idb.get_store_items('geo',function(it) {
if(item[1].stored)
map.set_mark(item[1].coords,'stored');
- var str='Display stored location'+
- '<br>('+it[1].coords[0].toFixed(3)+','+
- it[1].coords[1].toFixed(3)+')';
- ui.draw_content('ioctrldiss',str);
},0,-1);
ui.set_switch('ioctrldiss',item[1].stored);
gp.status.map.stored=item[1].stored;
},0,-1);
},
geocallback: function(loc,msg,code) {
- var str="Display current location<br>(";
if(msg!='success') {
- str+="<";
+ var str='geocallback error: ';
switch(code) {
case 0:
str+="unknown error";
str+="timed out";
break;
}
- str+=">";
}
else {
- var latlng=L.latLng(loc.coords.latitude,
- loc.coords.longitude);
- str+=latlng[0].toFixed(3)+','+latlng[1].toFixed(3);
- if(gp.status.map.current) {
- map.set_mark(latlng,'current');
- }
+ if(gp.status.map.current)
+ map.set_mark(loc,'current');
if(gp.status.map.recenter)
- map.showpos(latlng);
- else
- map.showpos(gp.status.geo.coords);
+ map.showpos(loc);
}
- str+=")";
- ui.draw_content('ioctrldisc',str);
},
event_action: function(event,type) {
- if(type=="switch")
- gp.switch_event(event.target.id);
- if(type=="button")
- gp.button_event(event.target.id);
+ if(type=="click") {
+ switch(event.target.id) {
+ case 'whatsoever':
+ gp.button_event(event.target.id);
+ break;
+ default:
+ gp.switch_event(event.target.id);
+ break;
+ }
+ }
+ if(type=="longclick") {
+ cl("going to do some longclick action ...");
+ }
},
switch_event: function(id) {
cl("event from id "+id);
switch(id) {
case 'ioctrlstore':
idb.get_store_items('geo',function(item) {
- item[1].coords=geo.loc;
+ var str="Update location";
+ if(item[1].update) {
+ nstat=false;
+ item[1].coords=geo.loc;
+ var ll=geo.loc2ll(geo.loc);
+ str="Stored location<br>("+
+ ll[0].toFixed(3)+","+
+ ll[1].toFixed(3)+")";
+ }
+ item[1].update=nstat;
idb.update_store_item('geo',1,item[1],
function() {
gp.status.geo.coords=item[1].coords;
- var str='Stored location ('+
- item[1].coords[0].toFixed(3)+
- ','+
- item[1].coords[1].toFixed(3)+
- ')';
- ui.draw_content('ioctrlstore',str);
+ ui.draw_content(id,str);
+ ui.set_switch(id,nstat);
var loc=geo.loc
if(!gp.status.map.recenter)
loc=item[1].coords;
};
$(document).ready(function() {
- //if(Modernizr.hasEvent('deviceready')) {
if('cordova' in window) {
- alert("via init");
gp.init();
}
else {
- alert("via startup");
gp.startup();
}
});