X-Git-Url: https://hackdaworld.org/gitweb/?p=outofuni%2Fglowingpatrol.git;a=blobdiff_plain;f=app%2Fwww%2Fjs%2Findex.js;fp=app%2Fwww%2Fjs%2Findex.js;h=332cd2c4bfeb3f36b22f31efee95dd44de2a645f;hp=1d4e69119d51779b1396274ed3f978d85693dc37;hb=373bf2f818f5ffc388c67f4e5bfafc478c5b56d4;hpb=c20b271b77e0b605105f28bd1c9664fdb6212bcd diff --git a/app/www/js/index.js b/app/www/js/index.js index 1d4e691..332cd2c 100644 --- a/app/www/js/index.js +++ b/app/www/js/index.js @@ -30,10 +30,13 @@ var ui = { 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; @@ -42,25 +45,52 @@ var ui = { 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(); @@ -115,7 +145,8 @@ var ui = { $(id).html(txt); } $(trg).css('background-color',col); - } + }, + } var geo = { @@ -141,6 +172,21 @@ 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; } }; @@ -217,7 +263,7 @@ var gp = { 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(); }); @@ -247,10 +293,14 @@ var gp = { 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
"+ + 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 @@ -268,10 +318,6 @@ var gp = { idb.get_store_items('geo',function(it) { if(item[1].stored) map.set_mark(item[1].coords,'stored'); - var str='Display stored location'+ - '
('+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; @@ -280,9 +326,8 @@ var gp = { },0,-1); }, geocallback: function(loc,msg,code) { - var str="Display current location
("; if(msg!='success') { - str+="<"; + var str='geocallback error: '; switch(code) { case 0: str+="unknown error"; @@ -297,28 +342,28 @@ var gp = { 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); @@ -326,16 +371,21 @@ var gp = { 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
("+ + 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; @@ -432,13 +482,10 @@ var gp = { }; $(document).ready(function() { - //if(Modernizr.hasEvent('deviceready')) { if('cordova' in window) { - alert("via init"); gp.init(); } else { - alert("via startup"); gp.startup(); } });