cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-plugin-contacts git commit: CB-10636 Add JSHint for plugins
Date Mon, 29 Feb 2016 08:47:48 GMT
Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master df9f936f0 -> ca62fa78f


CB-10636 Add JSHint for plugins

Fixed contacts.spec.5


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/ca62fa78
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/ca62fa78
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/ca62fa78

Branch: refs/heads/master
Commit: ca62fa78fcdb2fc0ad1d357788aaf3a365eae7ca
Parents: df9f936
Author: daserge <v-seshak@microsoft.com>
Authored: Thu Feb 25 21:18:28 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Fri Feb 26 09:44:27 2016 +0300

----------------------------------------------------------------------
 .gitignore                       |  2 +-
 .jshintrc                        | 24 ++++++++++++
 .travis.yml                      |  4 ++
 README.md                        |  2 +
 package.json                     |  9 ++++-
 src/blackberry10/contactUtils.js |  4 +-
 src/blackberry10/index.js        | 47 +++++++---------------
 src/firefoxos/ContactsProxy.js   | 69 +++++++++++++++++----------------
 src/windows/ContactProxy.js      | 21 ++++++----
 src/windows8/ContactProxy.js     | 73 ++++++++++++++++++++---------------
 tests/tests.js                   | 52 ++++++++++++-------------
 www/contacts.js                  |  8 ++--
 12 files changed, 176 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 52b558e..6964ea0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@ Thumbs.db
 *.swp
 *.user
 
-
+node_modules
 
 
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..fcd540a
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,24 @@
+{
+    "browser": true
+  , "devel": true
+  , "bitwise": true
+  , "undef": true
+  , "trailing": true
+  , "quotmark": false
+  , "indent": 4
+  , "unused": "vars"
+  , "latedef": "nofunc"
+  , "globals": {
+        "module": false,
+        "exports": false,
+        "require": false,
+        "cordova": true,
+        "ContactFindOptions": true,
+        "ContactError": true,
+        "Contact": true,
+        "ContactName": true,
+        "ContactField": true,
+        "ContactAddress": true,
+        "ContactOrganization": true
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b9af4c5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+sudo: false
+node_js:
+  - "4.2"

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 77e8c88..7095c1f 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@
 #         under the License.
 -->
 
+[![Build Status](https://travis-ci.org/apache/cordova-plugin-contacts.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-contacts)
+
 # cordova-plugin-contacts
 
 This plugin defines a global `navigator.contacts` object, which provides access to the device
contacts database.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 11853a9..79622d1 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,13 @@
     "cordova-windows8",
     "cordova-windows"
   ],
+  "scripts": {
+    "test": "npm run jshint",
+    "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint
src && node node_modules/jshint/bin/jshint tests"
+  },
   "author": "Apache Software Foundation",
-  "license": "Apache-2.0"
+  "license": "Apache-2.0",
+  "devDependencies": {
+    "jshint": "^2.6.0"
+  }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/src/blackberry10/contactUtils.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/contactUtils.js b/src/blackberry10/contactUtils.js
index e1f7d67..9f41590 100644
--- a/src/blackberry10/contactUtils.js
+++ b/src/blackberry10/contactUtils.js
@@ -18,7 +18,9 @@
  * under the License.
  *
 */
- 
+
+/* global ContactPickerOptions */
+
 var self,
     ContactFindOptions = require("./ContactFindOptions"),
     ContactError = require("./ContactError"),

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 09a4bd2..6ab5465 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -13,27 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+/* global PluginResult, JNEXT, escape */
+
 var pimContacts,
-    contactUtils = require("./contactUtils"),
-    contactConsts = require("./contactConsts"),
     ContactError = require("./ContactError"),
     ContactName = require("./ContactName"),
-    ContactFindOptions = require("./ContactFindOptions"),
-    noop = function () {};
-
-function getAccountFilters(options) {
-    if (options.includeAccounts) {
-        options.includeAccounts = options.includeAccounts.map(function (acct) {
-            return acct.id.toString();
-        });
-    }
-
-    if (options.excludeAccounts) {
-        options.excludeAccounts = options.excludeAccounts.map(function (acct) {
-            return acct.id.toString();
-        });
-    }
-}
+    ContactFindOptions = require("./ContactFindOptions");
 
 function populateSearchFields(fields) {
     var i,
@@ -58,21 +44,21 @@ function populateSearchFields(fields) {
             searchFieldsObject[ContactFindOptions.SEARCH_FIELD_PHONE] = true;
         } else if (fields[i] === "emails") {
             searchFieldsObject[ContactFindOptions.SEARCH_FIELD_EMAIL] = true;
-        } else if (field === "addresses") {
+        } else if (fields[i] === "addresses") {
             // not supported by Cascades
-        } else if (field === "ims") {
+        } else if (fields[i] === "ims") {
             // not supported by Cascades
-        } else if (field === "organizations") {
+        } else if (fields[i] === "organizations") {
             searchFieldsObject[ContactFindOptions.SEARCH_FIELD_ORGANIZATION_NAME] = true;
-        } else if (field === "birthday") {
+        } else if (fields[i] === "birthday") {
             // not supported by Cascades
-        } else if (field === "note") {
+        } else if (fields[i] === "note") {
             // not supported by Cascades
-        } else if (field === "photos") {
+        } else if (fields[i] === "photos") {
             // not supported by Cascades
-        } else if (field === "categories") {
+        } else if (fields[i] === "categories") {
             // not supported by Cascades
-        } else if (field === "urls") {
+        } else if (fields[i] === "urls") {
             // not supported by Cascades
         }
     }
@@ -98,8 +84,7 @@ function convertBirthday(birthday) {
 }
 
 function processJnextSaveData(result, JnextData) {
-    var data = JnextData,
-        birthdayInfo;
+    var data = JnextData;
 
     if (data._success === true) {
         data.birthday = convertBirthday(data.birthday);
@@ -124,8 +109,7 @@ function processJnextFindData(eventId, eventHandler, JnextData) {
         i,
         l,
         more = false,
-        resultsObject = {},
-        birthdayInfo;
+        resultsObject = {};
 
     if (data.contacts) {
         for (i = 0, l = data.contacts.length; i < l; i++) {
@@ -192,7 +176,6 @@ module.exports = {
     save: function (successCb, failCb, args, env) {
         var attributes = {},
             result = new PluginResult(args, env),
-            key,
             nativeEmails = [];
 
         attributes = JSON.parse(decodeURIComponent(args[0]));
@@ -286,7 +269,7 @@ JNEXT.PimContacts = function ()
         }
 
         JNEXT.invoke(self.m_id, "find " + JSON.stringify(jnextArgs));
-    }
+    };
 
     self.getContact = function (args) {
         return JSON.parse(JNEXT.invoke(self.m_id, "getContact " + JSON.stringify(args)));

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 6be8d8c..d2328c3 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -19,6 +19,8 @@
  *
 */ 
 
+/* global mozContact */
+
 // Cordova contact definition: 
 // http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html#Contact
 // FxOS contact definition:
@@ -27,7 +29,6 @@
 
 var Contact = require('./Contact');
 var ContactField = require('./ContactField');
-var ContactAddress = require('./ContactAddress');
 var ContactName = require('./ContactName');
 
 // XXX: a hack to check if id is "empty". Cordova inserts a
@@ -46,13 +47,13 @@ function updateFromCordova(contact, fromContact) {
     function exportContactFieldArray(contactFieldArray, key) {
         if (!key) {
             key = 'value';
-        }                 
+        }
         var arr = [];
         for (var i=0; i < contactFieldArray.length; i++) {
             arr.push(contactFieldArray[i][key]);
-        };                                       
+        }
         return arr;
-    }              
+    }
 
     function exportAddress(addresses) {
         // TODO: check moz address format
@@ -66,15 +67,15 @@ function updateFromCordova(contact, fromContact) {
                 } else if (key == 'type') {
                     addr[key] = [addresses[i][key]];
                 } else if (key == 'country') {
-                    addr['countryName'] = addresses[i][key];
+                    addr.countryName = addresses[i][key];
                 } else {
-                    addr[key] = addresses[i][key];    
+                    addr[key] = addresses[i][key];
                 }
-            } 
+            }
             arr.push(addr);
-        }                                 
+        }
         return arr;
-    } 
+    }
 
     function exportContactField(data) {
         var contactFields = [];
@@ -99,17 +100,17 @@ function updateFromCordova(contact, fromContact) {
                       ['middleName', 'additionalName']];
     var baseArrayFields = [['displayName', 'name'], ['nickname']];
     var baseStringFields = [];
-    var j = 0; while(field = nameFields[j++]) {
+    var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line
       if (fromContact.name[field[0]]) {
         contact[field[1] || field[0]] = fromContact.name[field[0]].split(' ');
       }
     }
-    j = 0; while(field = baseArrayFields[j++]) {
+    j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line
       if (fromContact[field[0]]) {
         contact[field[1] || field[0]] = fromContact[field[0]].split(' ');
       }
     }
-    j = 0; while(field = baseStringFields[j++]) {
+    j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line
       if (fromContact[field[0]]) {
         contact[field[1] || field[0]] = fromContact[field[0]];
       }
@@ -118,7 +119,7 @@ function updateFromCordova(contact, fromContact) {
       contact.bday = new Date(fromContact.birthday);
     }
     if (fromContact.emails) {
-        var emails = exportContactField(fromContact.emails)
+        var emails = exportContactField(fromContact.emails);
         contact.email = emails;
     }
     if (fromContact.categories) {
@@ -172,17 +173,17 @@ Contact.prototype.updateFromMozilla = function(moz) {
             var addr = {};
             for (var key in addresses[i]) {
                 if (key == 'countryName') {
-                    addr['country'] = addresses[i][key];
+                    addr.country = addresses[i][key];
                 } else if (key == 'type') {
                     addr[key] = addresses[i][key].join(' ');
                 } else {
-                    addr[key] = addresses[i][key];    
+                    addr[key] = addresses[i][key];
                 }
-            } 
+            }
             arr.push(addr);
         }
         return arr;
-    } 
+    }
 
     function createOrganizations(orgs, jobs) {
         orgs = (orgs) ? orgs : [];
@@ -221,18 +222,18 @@ Contact.prototype.updateFromMozilla = function(moz) {
     var baseArrayFields = [['name', 'displayName'], 'nickname', ['note']];
     var baseStringFields = [];
     var name = new ContactName();
-    var j = 0; while(field = nameFields[j++]) {
+    var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line
         if (moz[field[0]]) {
             name[field[1] || field[0]] = moz[field[0]].join(' ');
         }
     }
     this.name = name;
-    j = 0; while(field = baseArrayFields[j++]) {
+    j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line
         if (moz[field[0]]) {
             this[field[1] || field[0]] = moz[field[0]].join(' ');
         }
     }
-    j = 0; while(field = baseStringFields[j++]) {
+    j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line
         if (moz[field[0]]) {
             this[field[1] || field[0]] = moz[field[0]];
         }
@@ -276,7 +277,7 @@ Contact.prototype.updateFromMozilla = function(moz) {
         // genderIdentity
         // key
     */
-}
+};
 
 
 function createMozillaFromCordova(successCB, errorCB, contact) {
@@ -323,26 +324,28 @@ function saveContacts(successCB, errorCB, contacts) {
             var contact = createCordovaFromMozilla(moz);
             // call callback
             successCB(contact);
-        }
+        };
     }
     var i=0;
     var contact;
-    while(contact = contacts[i++]){
-        var moz = createMozillaFromCordova(function(moz) {
-          var request = navigator.mozContacts.save(moz);
-          // success and/or fail will be called every time a contact is saved
-          request.onsuccess = makeSaveSuccessCB(moz);
-          request.onerror = errorCB;                
+    /*jshint -W083 */
+    while(contact = contacts[i++]) { // jshint ignore:line
+        createMozillaFromCordova(function(moz) {
+            var request = navigator.mozContacts.save(moz);
+            // success and/or fail will be called every time a contact is saved
+            request.onsuccess = makeSaveSuccessCB(moz);
+            request.onerror = errorCB;
         }, function() {}, contact);
     }
-}   
+    /*jshint +W083 */
+}
 
 
 // API provides a list of ids to be removed
 function remove(successCB, errorCB, ids) {
-    var i=0;
-    var id;
-    for (var i=0; i < ids.length; i++){
+    var i;
+    /*jshint -W083 */
+    for (i = 0; i < ids.length; i++){
         // throw an error if no id provided
         if (!_hasId(ids[i])) {
             console.error('FFOS: Attempt to remove unsaved contact');
@@ -365,6 +368,7 @@ function remove(successCB, errorCB, ids) {
         };
         search.onerror = errorCB;
     }
+    /*jshint +W083 */
 }
 
 
@@ -445,7 +449,6 @@ function search(successCB, errorCB, params) {
     request.onsuccess = function() {
         var contacts = [];
         var mozContacts = request.result;
-        var moz = mozContacts[0];
         for (var i=0; i < mozContacts.length; i++) {
             contacts.push(createCordovaFromMozilla(mozContacts[i]));
         }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/src/windows/ContactProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/ContactProxy.js b/src/windows/ContactProxy.js
index 61f1d7a..1aed318 100644
--- a/src/windows/ContactProxy.js
+++ b/src/windows/ContactProxy.js
@@ -19,6 +19,8 @@
  * 
  */
 
+/* global Windows, WinJS */
+
 var ContactField = require('./ContactField'),
     ContactAddress = require('./ContactAddress'),
     ContactOrganization = require('./ContactOrganization'),
@@ -48,7 +50,8 @@ function convertToContact(windowsContact) {
     // phoneNumbers
     contact.phoneNumbers = [];
     var phoneSource = windowsContact.phoneNumbers || windowsContact.phones;
-    for (var i = 0; i < phoneSource.size; i++) {
+    var i;
+    for (i = 0; i < phoneSource.size; i++) {
         var rawPhone = phoneSource[i];
         var phone = new ContactField(rawPhone.category || rawPhone.kind, rawPhone.value ||
rawPhone.number);
         contact.phoneNumbers.push(phone);
@@ -57,7 +60,7 @@ function convertToContact(windowsContact) {
     // emails
     contact.emails = [];
     var emailSource = windowsContact.emails;
-    for (var i = 0; i < emailSource.size; i++) {
+    for (i = 0; i < emailSource.size; i++) {
         var rawEmail = emailSource[i];
         var email = new ContactField(rawEmail.category || rawEmail.kind, rawEmail.value ||
rawEmail.address);
         contact.emails.push(email);
@@ -66,7 +69,7 @@ function convertToContact(windowsContact) {
     // addressres
     contact.addresses = [];
     var addressSource = windowsContact.locations || windowsContact.addresses;
-    for (var i = 0; i < addressSource.size; i++) {
+    for (i = 0; i < addressSource.size; i++) {
         var rawAddress = addressSource[i];
         var address = new ContactAddress(
             null,
@@ -83,7 +86,7 @@ function convertToContact(windowsContact) {
     // ims
     contact.ims = [];
     var imSource = windowsContact.instantMessages || windowsContact.connectedServiceAccounts;
-    for (var i = 0; i < imSource.size; i++) {
+    for (i = 0; i < imSource.size; i++) {
         var rawIm = imSource[i];
         var im = new ContactField(rawIm.category || rawIm.serviceName, rawIm.userName ||
rawIm.id);
         contact.ims.push(im);
@@ -274,7 +277,9 @@ module.exports = {
             // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.phone.personalinformation.aspx
     
             //We don't need to create Error object here since it will be created at navigator.contacts.find()
method
-            fail && fail(ContactError.NOT_SUPPORTED_ERROR);
+            if (fail) {
+                fail(ContactError.NOT_SUPPORTED_ERROR);
+            }
             return;
         }
         
@@ -307,7 +312,9 @@ module.exports = {
             // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.phone.personalinformation.aspx
     
             //We don't need to create Error object here since it will be created at navigator.contacts.find()
method
-            fail && fail(ContactError.NOT_SUPPORTED_ERROR);
+            if (fail) {
+                fail(ContactError.NOT_SUPPORTED_ERROR);
+            }
             return;
         }
         
@@ -380,7 +387,7 @@ module.exports = {
         // searchFields is not supported yet due to WP8.1 API limitations.
         // findContactsAsync(String) method will attempt to match the name, email address,
or phone number of a contact. 
         // see http://msdn.microsoft.com/en-us/library/windows/apps/dn624861.aspx for details
-        var searchFields = options[0],
+        var searchFields = options[0], // jshint ignore:line
             searchOptions = options[1],
             searchFilter = searchOptions.filter,
             searchMultiple = searchOptions && searchOptions.multiple;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/src/windows8/ContactProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/ContactProxy.js b/src/windows8/ContactProxy.js
index c67e771..d802549 100644
--- a/src/windows8/ContactProxy.js
+++ b/src/windows8/ContactProxy.js
@@ -19,6 +19,8 @@
  * 
  */
 
+/* global Windows */
+
 var ContactField = require('./ContactField'),
     ContactAddress = require('./ContactAddress'),
     ContactName = require('./ContactName'),
@@ -27,6 +29,7 @@ var ContactField = require('./ContactField'),
 
 function convertToContact(windowsContact) {
     var contact = new Contact();
+    var i;
 
     // displayName & nickname
     contact.displayName = windowsContact.name;
@@ -37,21 +40,21 @@ function convertToContact(windowsContact) {
 
     // phoneNumbers
     contact.phoneNumbers = [];
-    for (var i = 0; i < windowsContact.phoneNumbers.size; i++) {
+    for (i = 0; i < windowsContact.phoneNumbers.size; i++) {
         var phone = new ContactField(windowsContact.phoneNumbers[i].category, windowsContact.phoneNumbers[i].value);
         contact.phoneNumbers.push(phone);
     }
 
     // emails
     contact.emails = [];
-    for (var i = 0; i < windowsContact.emails.size; i++) {
+    for (i = 0; i < windowsContact.emails.size; i++) {
         var email = new ContactField(windowsContact.emails[i].category, windowsContact.emails[i].value);
         contact.emails.push(email);
     }
 
     // addressres
     contact.addresses = [];
-    for (var i = 0; i < windowsContact.locations.size; i++) {
+    for (i = 0; i < windowsContact.locations.size; i++) {
         var address = new ContactAddress(null, windowsContact.locations[i].category,
             windowsContact.locations[i].unstructuredAddress, windowsContact.locations[i].street,
             null, windowsContact.locations[i].region, windowsContact.locations[i].postalCode,
@@ -61,18 +64,33 @@ function convertToContact(windowsContact) {
 
     // ims
     contact.ims = [];
-    for (var i = 0; i < windowsContact.instantMessages.size; i++) {
+    for (i = 0; i < windowsContact.instantMessages.size; i++) {
         var im = new ContactField(windowsContact.instantMessages[i].category, windowsContact.instantMessages[i].userName);
         contact.ims.push(im);
     }
 
     return contact;
-};
+}
 
 module.exports = {
     pickContact: function(win, fail, args) {
-
         var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
+
+        function success(con) {
+            // if contact was not picked
+            if (!con) {
+                if (fail) {
+                    setTimeout(function() {
+                        fail(new Error("User did not pick a contact."));
+                    }, 0);
+                }
+                return;
+            }
+
+            // send em back
+            win(convertToContact(con));
+        }
+
         picker.selectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.contacts;
// select entire contact
 
         // pickContactAsync is available on Windows 8.1 or later, instead of
@@ -82,40 +100,31 @@ module.exports = {
         if (picker.pickContactAsync) {
             // TODO: 8.1 has better contact support via the 'Contact' object
         } else {
-
-            function success(con) {
-                // if contact was not picked
-                if (!con) {
-                    fail && setTimeout(function() {
-                        fail(new Error("User did not pick a contact."));
-                    }, 0);
-                    return;
-                }
-
-                // send em back
-                win(convertToContact(con));
-
-            }
-
             picker.pickSingleContactAsync().done(success, fail);
         }
     },
 
     save:function(win,fail,args){
-        console && console.error && console.error("Error : Windows 8 does
not support creating/saving contacts");
-        fail && setTimeout(function () {
-            fail(new Error("Contact create/save not supported on Windows 8"));
-        }, 0);
+        if (console && console.error) {
+            console.error("Error : Windows 8 does not support creating/saving contacts");
+        }
+        if (fail) {
+            setTimeout(function () {
+                fail(new Error("Contact create/save not supported on Windows 8"));
+            }, 0);
+        }
     },
 
     search: function(win, fail, args) {
-        console && console.error && console.error("Error : Windows 8 does
not support searching contacts");
-        fail && setTimeout(function() {
-            fail(new Error("Contact search not supported on Windows 8"));
-        }, 0);
+        if (console && console.error) {
+            console.error("Error : Windows 8 does not support searching contacts");
+        }
+        if (fail) {
+            setTimeout(function() {
+                fail(new Error("Contact search not supported on Windows 8"));
+            }, 0);
+        }
     }
-
-
-}
+};
 
 require("cordova/exec/proxy").add("Contacts", module.exports);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 376e5a9..8d3ac51 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,6 +19,9 @@
  *
 */
 
+/* jshint jasmine: true */
+/* global WinJS */
+
 exports.defineAutoTests = function() {
     // global to store a contact so it doesn't have to be created or retrieved multiple times
     // all of the setup/teardown test methods can reference the following variables to make
sure to do the right cleanup
@@ -59,12 +62,12 @@ exports.defineAutoTests = function() {
             contacts.forEach(function(contact) {
                 removes.push(contact);
             });
-            if (removes.length == 0) {
+            if (removes.length === 0) {
                 done();
                 return;
             }
 
-            var nextToRemove = undefined;
+            var nextToRemove;
             if (removes.length > 0) {
                 nextToRemove = removes.shift();
             }
@@ -150,7 +153,9 @@ exports.defineAutoTests = function() {
                 obj.multiple = true;
 
                 expect(function() {
-                    navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"],
null, fail.bind(null, done), obj);
+                    navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"],
null, function (err) {
+                        expect(err).toBeUndefined();
+                    }, obj);
                 }).toThrow();
             });
 
@@ -450,16 +455,7 @@ exports.defineAutoTests = function() {
 
                 var saveFail = fail.bind(null, done);
 
-                var saveSuccess = function(obj) {
-                    gContactObj = obj;
-                    gContactObj.emails[1].value = "";
-                    bDay = new Date(1975, 5, 4);
-                    gContactObj.birthday = bDay;
-                    gContactObj.note = noteText;
-                    gContactObj.save(updateSuccess, saveFail);
-                };
-
-                var updateSuccess = function(obj) {
+                function updateSuccess(obj) {
                     expect(obj).toBeDefined();
                     expect(obj.id).toBe(gContactObj.id);
                     expect(obj.note).toBe(noteText);
@@ -467,6 +463,15 @@ exports.defineAutoTests = function() {
                     expect(obj.emails.length).toBe(1);
                     expect(obj.emails[0].value).toBe('here@there.com');
                     done();
+                }
+
+                var saveSuccess = function(obj) {
+                    gContactObj = obj;
+                    gContactObj.emails[1].value = "";
+                    bDay = new Date(1975, 5, 4);
+                    gContactObj.birthday = bDay;
+                    gContactObj.note = noteText;
+                    gContactObj.save(updateSuccess, saveFail);
                 };
 
                 navigator.contacts
@@ -647,7 +652,7 @@ exports.defineManualTests = function(contentEl, createActionButton) {
         obj.multiple = true;
         navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails", "urls",
"note"], function(contacts) {
             var s = "";
-            if (contacts.length == 0) {
+            if (contacts.length === 0) {
                 s = "No contacts found";
             } else {
                 s = "Number of contacts: " + contacts.length + "<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
@@ -658,7 +663,7 @@ exports.defineManualTests = function(contentEl, createActionButton) {
                     if (contact.phoneNumbers && contact.phoneNumbers.length >
0) {
                         s = s + contact.phoneNumbers[0].value;
                     }
-                    s = s + "</td><td>"
+                    s = s + "</td><td>";
                     if (contact.emails && contact.emails.length > 0) {
                         s = s + contact.emails[0].value;
                     }
@@ -761,7 +766,7 @@ exports.defineManualTests = function(contentEl, createActionButton) {
         obj.multiple = false;
 
         navigator.contacts.find(['displayName', 'name'], function(contacts) {
-            if (contacts.length == 0) {
+            if (contacts.length === 0) {
                 results.innerHTML = 'No contacts to update.';
                 return;
             }
@@ -782,7 +787,7 @@ exports.defineManualTests = function(contentEl, createActionButton) {
             } else {
                 results.innerHTML = 'Search failed: error ' + e.code;
             }
-        }, obj)
+        }, obj);
     }
 
     function removeTestContacts() {
@@ -796,12 +801,12 @@ exports.defineManualTests = function(contentEl, createActionButton)
{
             contacts.forEach(function(contact) {
                 removes.push(contact);
             });
-            if (removes.length == 0) {
+            if (removes.length === 0) {
                 results.innerHTML = "No contacts to remove";
                 return;
             }
 
-            var nextToRemove = undefined;
+            var nextToRemove;
             if (removes.length > 0) {
                 nextToRemove = removes.shift();
             }
@@ -834,15 +839,6 @@ exports.defineManualTests = function(contentEl, createActionButton) {
             }
         }, obj);
     }
-    
-    function nameMatches(contact, contactName) {
-        if (contactName === null && (contact.name === null || contact.name.formatted
=== null)) {
-            return true;
-        } else if (contact.name && contact.name.formatted && contact.name.formatted.indexOf(contactName)
> -1) {
-            return true;
-        }
-        return false;
-    }
 
     /******************************************************************************/
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ca62fa78/www/contacts.js
----------------------------------------------------------------------
diff --git a/www/contacts.js b/www/contacts.js
index 178a20a..b1b2711 100644
--- a/www/contacts.js
+++ b/www/contacts.js
@@ -22,10 +22,8 @@
 var argscheck = require('cordova/argscheck'),
     exec = require('cordova/exec'),
     ContactError = require('./ContactError'),
-    utils = require('cordova/utils'),
     Contact = require('./Contact'),
     fieldType = require('./ContactFieldType');
-    
 
 /**
 * Represents a group of Contacts.
@@ -44,10 +42,12 @@ var contacts = {
     find:function(fields, successCB, errorCB, options) {
         argscheck.checkArgs('afFO', 'contacts.find', arguments);
         if (!fields.length) {
-            errorCB && errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
+            if (errorCB) {
+                errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
+            }
         } else {
             // missing 'options' param means return all contacts
-            options = options || {filter: '', multiple: true}
+            options = options || { filter: '', multiple: true };
             var win = function(result) {
                 var cs = [];
                 for (var i = 0, l = result.length; i < l; i++) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message