From 76a8203176132684b61be30b9d9ad4d2f29c39be Mon Sep 17 00:00:00 2001 From: filmaj Date: Sat, 13 Feb 2010 18:58:45 -0800 Subject: [PATCH] Fixed small contacts and accelerometer object instantiation bugs. Added a bit more delay to PhoneGap constructor, 1ms caused issues sometimes I *think*. --- framework/assets/js/accelerometer.js | 3 ++- framework/assets/js/contact.js | 15 +++++++++++++-- framework/assets/js/geolocation.js | 1 + framework/assets/js/phonegap.js.base | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/framework/assets/js/accelerometer.js b/framework/assets/js/accelerometer.js index d0b40a6b..f6820157 100644 --- a/framework/assets/js/accelerometer.js +++ b/framework/assets/js/accelerometer.js @@ -3,10 +3,11 @@ function Acceleration(x, y, z) this.x = x; this.y = y; this.z = z; + this.timestamp = new Date().getTime(); } // Need to define these for android -_accel = {} +_accel = {}; _accel.x = 0; _accel.y = 0; _accel.z = 0; diff --git a/framework/assets/js/contact.js b/framework/assets/js/contact.js index 402b21cf..30e26a6d 100644 --- a/framework/assets/js/contact.js +++ b/framework/assets/js/contact.js @@ -1,5 +1,5 @@ var Contact = function(){ - this.name = null; + this.name = new ContactName(); this.emails = []; this.phones = []; } @@ -37,7 +37,18 @@ Contacts.prototype.find = function(obj, win, fail) { if(obj.name != null) { - ContactHook.search(name, "", ""); + // Build up the search term that we'll use in SQL, based on the structure/contents of the contact object passed into find. + var searchTerm = ''; + if (obj.name.givenName && obj.name.givenName.length > 0) { + searchTerm = obj.name.givenName.split(' ').join('%'); + } + if (obj.name.familyName && obj.name.familyName.length > 0) { + searchTerm += obj.name.familyName.split(' ').join('%'); + } + if (!obj.name.familyName && !obj.name.givenName && obj.name.formatted) { + searchTerm = obj.name.formatted; + } + ContactHook.search(searchTerm, "", ""); } this.win = win; this.fail = fail; diff --git a/framework/assets/js/geolocation.js b/framework/assets/js/geolocation.js index b9b4ac68..df942251 100644 --- a/framework/assets/js/geolocation.js +++ b/framework/assets/js/geolocation.js @@ -89,6 +89,7 @@ Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, { coords = new Coordinates(lat, lng, alt, altacc, head, vel); loc = new Position(coords, stamp); + this.lastPosition = loc; this.global_success(loc); } } diff --git a/framework/assets/js/phonegap.js.base b/framework/assets/js/phonegap.js.base index a3310882..d971b939 100644 --- a/framework/assets/js/phonegap.js.base +++ b/framework/assets/js/phonegap.js.base @@ -72,7 +72,7 @@ PhoneGap.addConstructor = function(func) { e.initEvent('deviceready'); document.dispatchEvent(e); } - }, 1); + }, 5); })();