You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ld...@apache.org on 2014/08/07 19:28:27 UTC

[3/5] git commit: changes made to align with w3c spec

changes made to align with w3c spec


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

Branch: refs/heads/master
Commit: f442fc21ed7e1642d92fa420efd968ebbad13345
Parents: 90c6e5f
Author: Edna Morales <ed...@ednas-mbp-2.raleigh.ibm.com>
Authored: Fri Jul 18 09:19:53 2014 -0400
Committer: Lisa Seacat DeLuca <ld...@us.ibm.com>
Committed: Thu Aug 7 12:51:23 2014 -0400

----------------------------------------------------------------------
 plugin.xml       |  1 +
 www/vibration.js | 41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/f442fc21/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index d2494fd..3e4924b 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -32,6 +32,7 @@
 
     <js-module src="www/vibration.js" name="notification">
         <merges target="navigator.notification" />
+        <merges target="navigator" />
     </js-module>
 
     <!-- firefoxos -->

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/f442fc21/www/vibration.js
----------------------------------------------------------------------
diff --git a/www/vibration.js b/www/vibration.js
index 34b16fb..d1206ed 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -28,12 +28,45 @@ var exec = require('cordova/exec');
 module.exports = {
 
     /**
-     * Vibrates the device for a given amount of time.
+     * Vibrates the device for a given amount of time or for a given pattern or immediately cancels any ongoing vibrations (depending on the parameter).
      *
-     * @param {Integer} mills       The number of milliseconds to vibrate.
+     * @param {Integer} param       The number of milliseconds to vibrate (if 0, cancels vibration)
+     *
+     *
+     * @param {Array of Integer} param    Pattern with which to vibrate the device.
+     *                                      Pass in an array of integers that
+     *                                      are the durations for which to
+     *                                      turn on or off the vibrator in
+     *                                      milliseconds. The first value
+     *                                      indicates the number of milliseconds
+     *                                      to wait before turning the vibrator
+     *                                      on. The next value indicates the
+     *                                      number of milliseconds for which
+     *                                      to keep the vibrator on before
+     *                                      turning it off. Subsequent values
+     *                                      alternate between durations in
+     *                                      milliseconds to turn the vibrator
+     *                                      off or to turn the vibrator on.
+     *                                      (if empty, cancels vibration)
      */
-    vibrate: function(mills) {
-        exec(null, null, "Vibration", "vibrate", [mills]);
+    vibrate: function(param) {
+
+        /* Aligning with w3c spec */
+        
+        //vibrate
+        if ((typeof param == 'number') && param != 0)
+            exec(null, null, "Vibration", "vibrate", [param]);
+
+        //vibrate with a pattern
+        else if ((typeof param == 'object') && param.length != 0)
+        {
+            var repeat = -1; //no repeat
+            exec(null, null, "Vibration", "vibrateWithPattern", [param, repeat]);
+        }
+
+        //cancel vibration (param = 0 or [])
+        else
+            exec(null, null, "Vibration", "cancelVibration", []);
     },
 
     /**