CB-12895 : added eslint and removed jshint
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..0cccb8c
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,10 @@
+root: true
+extends: semistandard
+rules:
+ indent:
+ - error
+ - 4
+ camelcase: off
+ padded-blocks: off
+ operator-linebreak: off
+ no-throw-literal: off
\ No newline at end of file
diff --git a/package.json b/package.json
index 8970c2a..cecdee5 100644
--- a/package.json
+++ b/package.json
@@ -39,8 +39,8 @@
"cordova-tizen"
],
"scripts": {
- "test": "npm run jshint",
- "jshint": "jshint www && jshint src && jshint tests"
+ "test": "npm run eslint",
+ "eslint": "eslint www && eslint src && eslint tests"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
@@ -52,6 +52,12 @@
}
},
"devDependencies": {
- "jshint": "^2.6.0"
+ "eslint": "^4.0.0",
+ "eslint-config-semistandard": "^11.0.0",
+ "eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.3.0",
+ "eslint-plugin-node": "^5.0.0",
+ "eslint-plugin-promise": "^3.5.0",
+ "eslint-plugin-standard": "^3.0.1"
}
}
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index b014f24..491f9bf 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -25,51 +25,51 @@
module.exports = {
vibrate: function (success, fail, args, env) {
- var result = new PluginResult(args, env),
- duration = args[0],
- response = vibration.getInstance().vibrate(duration);
+ var result = new PluginResult(args, env);
+ var duration = args[0];
+ var response = vibration.getInstance().vibrate(duration);
result.ok(response, false);
}
};
-///////////////////////////////////////////////////////////////////
+/// ////////////////////////////////////////////////////////////////
// JavaScript wrapper for JNEXT plugin
-///////////////////////////////////////////////////////////////////
+/// ////////////////////////////////////////////////////////////////
JNEXT.Vibration = function () {
- var self = this,
- hasInstance = false;
+ var self = this;
+ var hasInstance = false;
self.vibrate = function (duration) {
- //This is how Javascript calls into native
- return JNEXT.invoke(self.m_id, "vibrate " + duration);
+ // This is how Javascript calls into native
+ return JNEXT.invoke(self.m_id, 'vibrate ' + duration);
};
self.init = function () {
- //Checks that the jnext library is present and loads it
- if (!JNEXT.require("libVibration")) {
+ // Checks that the jnext library is present and loads it
+ if (!JNEXT.require('libVibration')) {
return false;
}
- //Creates the native object that this interface will call
- self.m_id = JNEXT.createObject("libVibration.Vibration");
+ // Creates the native object that this interface will call
+ self.m_id = JNEXT.createObject('libVibration.Vibration');
- if (self.m_id === "") {
+ if (self.m_id === '') {
return false;
}
- //Registers for the JNEXT event loop
+ // Registers for the JNEXT event loop
JNEXT.registerEvents(self);
};
- self.m_id = "";
+ self.m_id = '';
- //Used by JNEXT library to get the ID
+ // Used by JNEXT library to get the ID
self.getId = function () {
return self.m_id;
};
- //Not truly required but useful for instance management
+ // Not truly required but useful for instance management
self.getInstance = function () {
if (!hasInstance) {
self.init();
diff --git a/src/browser/Vibration.js b/src/browser/Vibration.js
index f803a8d..26860c7 100644
--- a/src/browser/Vibration.js
+++ b/src/browser/Vibration.js
@@ -20,7 +20,7 @@
*/
module.exports = {
- vibrate: function(success, fail, milliseconds) {
+ vibrate: function (success, fail, milliseconds) {
console.log('Vibration is not supported');
return false;
}
diff --git a/src/firefoxos/VibrationProxy.js b/src/firefoxos/VibrationProxy.js
index 3d2a2cf..d847411 100644
--- a/src/firefoxos/VibrationProxy.js
+++ b/src/firefoxos/VibrationProxy.js
@@ -21,13 +21,13 @@
module.exports = {
- vibrate: function(success, fail, milliseconds) {
+ vibrate: function (success, fail, milliseconds) {
if (navigator.notification.vibrate) {
navigator.vibrate(milliseconds);
} else {
- console.log ("cordova/plugin/firefoxos/vibration, vibrate API does not exist");
+ console.log('cordova/plugin/firefoxos/vibration, vibrate API does not exist');
}
}
};
-require("cordova/exec/proxy").add("Vibration", module.exports);
\ No newline at end of file
+require('cordova/exec/proxy').add('Vibration', module.exports);
diff --git a/src/tizen/VibrationProxy.js b/src/tizen/VibrationProxy.js
index 2123cd6..53ddd5d 100644
--- a/src/tizen/VibrationProxy.js
+++ b/src/tizen/VibrationProxy.js
@@ -20,11 +20,11 @@
*/
module.exports = {
- vibrate: function(milliseconds) {
+ vibrate: function (milliseconds) {
if (navigator.vibrate) {
navigator.vibrate(milliseconds);
}
}
};
-require("cordova/tizen/commandProxy").add("Vibration", module.exports);
+require('cordova/tizen/commandProxy').add('Vibration', module.exports);
diff --git a/src/windows/VibrationProxy.js b/src/windows/VibrationProxy.js
index eede750..a70e500 100644
--- a/src/windows/VibrationProxy.js
+++ b/src/windows/VibrationProxy.js
@@ -21,8 +21,8 @@
/* global Windows, WinJS, Vibration */
-function checkReqs(actionName, fail) {
- if (!(Windows.Phone && Windows.Phone.Devices && Windows.Phone.Devices.Notification && Windows.Phone.Devices.Notification.VibrationDevice) && WinJS.Utilities.isPhone !== true) {
+function checkReqs (actionName, fail) {
+ if (!(Windows.Phone && Windows.Phone.Devices && Windows.Phone.Devices.Notification && Windows.Phone.Devices.Notification.VibrationDevice) && WinJS.Utilities.isPhone !== true) {
fail(actionName + ' is unsupported by this platform.');
return false;
}
@@ -30,7 +30,7 @@
return true;
}
-function tryDoAction(actionName, success, fail, args, action) {
+function tryDoAction (actionName, success, fail, args, action) {
try {
if (checkReqs(actionName, fail) !== true) {
return;
@@ -43,7 +43,7 @@
}
}
-/**
+/**
* @typedef patternParsingResult
* @type {Object}
* @property {Array} result.parsed - Array with parsed integers
@@ -56,8 +56,9 @@
* @param {Array} pattern Array of delays
* @returns {patternParsingResult} result
*/
-function tryParsePatternValues(pattern) {
- var passed = true, failedItem;
+function tryParsePatternValues (pattern) {
+ var passed = true;
+ var failedItem;
pattern = pattern.map(function (item) {
var num = parseInt(item, 10);
@@ -76,7 +77,7 @@
};
}
-/**
+/**
* @typedef checkPatternReqsResult
* @type {Object}
* @property {Array} result.patternParsingResult - Array with parsed integers
@@ -87,10 +88,11 @@
* Checks params for vibrateWithPattern function
* @return {checkPatternReqsResult}
*/
-function checkPatternReqs(args, fail) {
+function checkPatternReqs (args, fail) {
var patternParsingResult = tryParsePatternValues(args[0]);
var repeat = args[1];
- var passed = true, errMsg = '';
+ var passed = true;
+ var errMsg = '';
if (!patternParsingResult.passed) {
errMsg += 'Could not parse ' + patternParsingResult.failedItem + ' in the vibration pattern';
@@ -123,7 +125,7 @@
* @param {Array} patternCycle Cycled part of the pattern array
* @return {Promise} Promise chaining single vibrate/pause actions
*/
-function vibratePattern(patternArr, shouldRepeat, fail, patternCycle) {
+function vibratePattern (patternArr, shouldRepeat, fail, patternCycle) {
return patternArr.reduce(function (previousValue, currentValue, index) {
if (index % 2 === 0) {
return previousValue.then(function () {
@@ -163,7 +165,7 @@
if (VibrationDevice) {
// Windows Phone 10 code paths
module.exports = {
- vibrate: function(success, fail, args) {
+ vibrate: function (success, fail, args) {
try {
var duration = parseInt(args[0]);
if (isNaN(duration)) {
@@ -171,11 +173,10 @@
}
VibrationDevice.getDefault().vibrate(duration);
success();
- }
- catch (e) {
+ } catch (e) {
fail(e);
}
- },
+ },
vibrateWithPattern: function (success, fail, args) {
// Cancel current vibrations first
module.exports.cancelVibration(function () {
@@ -196,7 +197,7 @@
patternChainPromise = vibratePattern(pattern, shouldRepeat, fail, patternCycle);
}, fail);
},
- cancelVibration: function(success, fail, args) {
+ cancelVibration: function (success, fail, args) {
try {
if (patternChainPromise) {
patternChainPromise.cancel();
@@ -205,27 +206,26 @@
if (success) {
success();
}
- }
- catch (e) {
+ } catch (e) {
if (fail) {
fail(e);
}
}
}
};
-} else if (typeof Vibration !== 'undefined' && Vibration.Vibration) {
+} else if (typeof Vibration !== 'undefined' && Vibration.Vibration) {
// Windows Phone 8.1 code paths
module.exports = {
vibrate: function (success, fail, args) {
- tryDoAction("vibrate", success, fail, args, Vibration.Vibration.vibrate);
+ tryDoAction('vibrate', success, fail, args, Vibration.Vibration.vibrate);
},
vibrateWithPattern: function (success, fail, args) {
- tryDoAction("vibrate", success, fail, [DEFAULT_DURATION], Vibration.Vibration.vibrate);
+ tryDoAction('vibrate', success, fail, [DEFAULT_DURATION], Vibration.Vibration.vibrate);
},
cancelVibration: function (success, fail, args) {
- tryDoAction("cancelVibration", success, fail, args, Vibration.Vibration.cancelVibration);
+ tryDoAction('cancelVibration', success, fail, args, Vibration.Vibration.cancelVibration);
}
};
} else {
@@ -250,4 +250,4 @@
};
}
-require("cordova/exec/proxy").add("Vibration", module.exports);
+require('cordova/exec/proxy').add('Vibration', module.exports);
diff --git a/tests/tests.js b/tests/tests.js
index 5fbfab6..ff57d9e 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,18 +19,17 @@
*
*/
-/* jshint jasmine: true */
+/* eslint-env jasmine */
exports.defineAutoTests = function () {
describe('Vibration (navigator.notification.vibrate)', function () {
- it("navigator.notification should exist with vibrate function", function () {
+ it('navigator.notification should exist with vibrate function', function () {
expect(navigator.notification).toBeDefined();
expect(typeof navigator.notification.vibrate).toBeDefined();
- expect(typeof navigator.notification.vibrate).toBe("function");
+ expect(typeof navigator.notification.vibrate).toBe('function');
- if (cordova.platformId == "browser")
- expect(navigator.notification.vibrate(0)).toBe(false);
+ if (cordova.platformId === 'browser') { expect(navigator.notification.vibrate(0)).toBe(false); } // eslint-disable-line no-undef
});
});
};
@@ -51,112 +50,111 @@
log.innerHTML = '';
};
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
// Vibrations
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
- //old vibrate call
- var vibrateOld = function(){
+ // old vibrate call
+ var vibrateOld = function () {
clearLog();
navigator.notification.vibrate(2500);
- logMessage("navigator.notification.vibrate(2500)", "green");
+ logMessage('navigator.notification.vibrate(2500)', 'green');
};
- //old vibrate with pattern call
- var vibrateWithPatternOld = function(){
+ // old vibrate with pattern call
+ var vibrateWithPatternOld = function () {
clearLog();
navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000]);
- logMessage("navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000])", "green");
+ logMessage('navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000])', 'green');
};
- //old vibrate with pattern with repeat call
- var vibrateWithPatternOldWithRepeat = function(){
+ // old vibrate with pattern with repeat call
+ var vibrateWithPatternOldWithRepeat = function () {
clearLog();
navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000], 2);
- logMessage("navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000], 2)", "green");
+ logMessage('navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000], 2)', 'green');
};
- //old cancel vibrate call
- var cancelOld = function(){
+ // old cancel vibrate call
+ var cancelOld = function () {
clearLog();
navigator.notification.cancelVibration();
- logMessage("navigator.notification.cancelVibration()", "green");
+ logMessage('navigator.notification.cancelVibration()', 'green');
};
- //new standard vibrate call that aligns to w3c spec with param long
- var vibrateWithInt = function() {
+ // new standard vibrate call that aligns to w3c spec with param long
+ var vibrateWithInt = function () {
clearLog();
navigator.vibrate(3000);
- logMessage("navigator.vibrate(3000)", "green");
+ logMessage('navigator.vibrate(3000)', 'green');
};
- //new standard vibrate call that aligns to w3c spec with param array
- var vibrateWithArray = function() {
+ // new standard vibrate call that aligns to w3c spec with param array
+ var vibrateWithArray = function () {
clearLog();
navigator.vibrate([3000]);
- logMessage("navigator.vibrate([3000])", "green");
+ logMessage('navigator.vibrate([3000])', 'green');
};
- //vibrate with a pattern using w3c spec
- var vibrateWithPattern = function() {
+ // vibrate with a pattern using w3c spec
+ var vibrateWithPattern = function () {
clearLog();
navigator.vibrate([1000, 2000, 3000, 2000, 5000]);
- logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000])", "green");
+ logMessage('navigator.vibrate([1000, 2000, 3000, 2000, 5000])', 'green');
};
- //cancel existing vibration using w3c spec navigator.vibrate(0)
- var cancelWithZero = function() {
+ // cancel existing vibration using w3c spec navigator.vibrate(0)
+ var cancelWithZero = function () {
clearLog();
navigator.vibrate(0);
- logMessage("navigator.vibrate(0)", "green");
+ logMessage('navigator.vibrate(0)', 'green');
};
- //cancel existing vibration using w3c spec navigator.vibrate([])
- var cancelWithEmpty = function() {
+ // cancel existing vibration using w3c spec navigator.vibrate([])
+ var cancelWithEmpty = function () {
clearLog();
navigator.vibrate([]);
- logMessage("navigator.vibrate([])", "green");
+ logMessage('navigator.vibrate([])', 'green');
};
- //reference to the timeout variable
+ // reference to the timeout variable
var timeout;
- //check whether there is an ongoing vibration
+ // check whether there is an ongoing vibration
var vibrateOn = false;
- //special long vibrate used to test cancel
- var longVibrate = function() {
+ // special long vibrate used to test cancel
+ var longVibrate = function () {
clearLog();
navigator.vibrate(60000);
vibrateOn = true;
- logMessage("navigator.vibrate(60000)", "green");
- timeout = setTimeout(resetVibrateOn, 60000); //if user doesn't cancel vibrate, reset vibrateOn var after 60 seconds
+ logMessage('navigator.vibrate(60000)', 'green');
+ timeout = setTimeout(resetVibrateOn, 60000); // if user doesn't cancel vibrate, reset vibrateOn var after 60 seconds
};
- //special long vibrate with pattern used to test cancel
- var longVibrateWithPattern = function() {
+ // special long vibrate with pattern used to test cancel
+ var longVibrateWithPattern = function () {
clearLog();
navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000]);
vibrateOn = true;
- logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000])", "green");
- timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds
+ logMessage('navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000])', 'green');
+ timeout = setTimeout(resetVibrateOn, 45000); // if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds
};
- //initiate two vibrations to test cancel
- var multipleVibrations = function() {
+ // initiate two vibrations to test cancel
+ var multipleVibrations = function () {
clearLog();
navigator.vibrate(20000);
navigator.vibrate(45000);
vibrateOn = true;
- logMessage("navigator.vibrate(15000)\nnavigator.vibrate(45000)", "green");
- timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds
+ logMessage('navigator.vibrate(15000)\nnavigator.vibrate(45000)', 'green');
+ timeout = setTimeout(resetVibrateOn, 45000); // if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds
};
- function resetVibrateOn() {
+ function resetVibrateOn () {
vibrateOn = false;
}
-
var vibrate_tests = '<h1>Vibrate Tests</h1>' +
'<h3>Starred tests only work for Android and Windows. </h3>' +
'<h3>iOS ignores the time given for a vibrate </h3>' +
@@ -187,141 +185,119 @@
'<p/> <div id="cancelMultipleVibrations"></div>' +
'Expected result: Press once to initiate two vibrations simultaneously (one for 20s the other for 45s so total of 45s). Press again to cancel both vibrations immediately.';
-
contentEl.innerHTML = '<div id="info"></div>' + vibrate_tests;
- //standard vibrate with old call
+ // standard vibrate with old call
createActionButton('Vibrate (Old)', function () {
vibrateOld();
}, 'vibrate_old');
- //vibrate with pattern with old call
+ // vibrate with pattern with old call
createActionButton('* Vibrate with a pattern (Old)', function () {
vibrateWithPatternOld();
}, 'vibrateWithPattern_old');
- //vibrate with pattern with repeat with old call
+ // vibrate with pattern with repeat with old call
createActionButton('* Vibrate with a pattern with repeat (Old)', function () {
vibrateWithPatternOldWithRepeat();
}, 'vibrateWithPatternRepeat_old');
- //cancel vibrate with old call
- createActionButton('* Cancel vibration (Old)', function() {
+ // cancel vibrate with old call
+ createActionButton('* Cancel vibration (Old)', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrate();
- }
- else
- {
+ } else {
cancelOld();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancelVibrate_old');
- //cancel vibrate with pattern with old call
- createActionButton('* Cancel vibration with pattern (Old)', function() {
+ // cancel vibrate with pattern with old call
+ createActionButton('* Cancel vibration with pattern (Old)', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrateWithPattern();
- }
- else
- {
+ } else {
cancelOld();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancelVibrateWithPattern_old');
- //standard vibrate with new call param int
- createActionButton('Vibrate with int', function() {
+ // standard vibrate with new call param int
+ createActionButton('Vibrate with int', function () {
vibrateWithInt();
}, 'vibrate_int');
- //standard vibrate with new call param array
- createActionButton('Vibrate with array', function() {
+ // standard vibrate with new call param array
+ createActionButton('Vibrate with array', function () {
vibrateWithArray();
}, 'vibrate_array');
- //vibrate with a pattern
- createActionButton('* Vibrate with a pattern', function() {
+ // vibrate with a pattern
+ createActionButton('* Vibrate with a pattern', function () {
vibrateWithPattern();
}, 'vibrate_with_pattern');
- //cancel any existing vibrations with param 0
- createActionButton('* Cancel vibration with 0', function() {
+ // cancel any existing vibrations with param 0
+ createActionButton('* Cancel vibration with 0', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrate();
- }
- else
- {
+ } else {
cancelWithZero();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancel_zero');
- //cancel any existing vibrations with param []
- createActionButton('* Cancel vibration with []', function() {
+ // cancel any existing vibrations with param []
+ createActionButton('* Cancel vibration with []', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrate();
- }
- else
- {
+ } else {
cancelWithEmpty();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancel_array');
- //cancel vibration with pattern with param 0
- createActionButton('* Cancel vibration with pattern with 0', function() {
+ // cancel vibration with pattern with param 0
+ createActionButton('* Cancel vibration with pattern with 0', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrateWithPattern();
- }
- else
- {
+ } else {
cancelWithZero();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancelWithPattern_zero');
- //cancel vibration with pattern with param []
- createActionButton('* Cancel vibration with pattern with []', function() {
+ // cancel vibration with pattern with param []
+ createActionButton('* Cancel vibration with pattern with []', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
longVibrateWithPattern();
- }
- else
- {
+ } else {
cancelWithEmpty();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancelWithPattern_array');
- //cancel multiple vibrations
- createActionButton('* Cancel multiple vibrations', function() {
+ // cancel multiple vibrations
+ createActionButton('* Cancel multiple vibrations', function () {
- if (!vibrateOn)
- {
+ if (!vibrateOn) {
multipleVibrations();
- }
- else
- {
+ } else {
cancelWithZero();
resetVibrateOn();
- clearTimeout(timeout); //clear the timeout since user has canceled the vibrate
+ clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
}
}, 'cancelMultipleVibrations');
};
diff --git a/www/blackberry10/vibrate.js b/www/blackberry10/vibrate.js
index ff7a1ec..85abc46 100644
--- a/www/blackberry10/vibrate.js
+++ b/www/blackberry10/vibrate.js
@@ -19,7 +19,7 @@
*
*/
-var vibrate = function(duration) {
+var vibrate = function (duration) {
navigator.vibrate(duration);
};
diff --git a/www/vibration.js b/www/vibration.js
index 409be0b..8b78e3c 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -50,36 +50,31 @@
* off or to turn the vibrator on.
* (if empty, cancels vibration)
*/
- vibrate: function(param) {
-
+ vibrate: function (param) {
/* Aligning with w3c spec */
- //vibrate
- if ((typeof param == 'number') && param !== 0)
- exec(null, null, "Vibration", "vibrate", [param]);
+ // vibrate
+ if ((typeof param === 'number') && param !== 0) {
+ exec(null, null, 'Vibration', 'vibrate', [param]);
- //vibrate with array ( i.e. vibrate([3000]) )
- else if ((typeof param == 'object') && param.length == 1)
- {
- //cancel if vibrate([0])
- if (param[0] === 0)
- exec(null, null, "Vibration", "cancelVibration", []);
+ // vibrate with array ( i.e. vibrate([3000]) )
+ } else if ((typeof param === 'object') && param.length === 1) {
+ // cancel if vibrate([0])
+ if (param[0] === 0) {
+ exec(null, null, 'Vibration', 'cancelVibration', []);
- //else vibrate
- else
- exec(null, null, "Vibration", "vibrate", [param[0]]);
- }
+ // else vibrate
+ } else {
+ exec(null, null, 'Vibration', 'vibrate', [param[0]]);
+ }
- //vibrate with a pattern
- else if ((typeof param == 'object') && param.length > 1)
- {
- var repeat = -1; //no repeat
- exec(null, null, "Vibration", "vibrateWithPattern", [param, repeat]);
- }
+ // vibrate with a pattern
+ } else if ((typeof param === 'object') && param.length > 1) {
+ var repeat = -1; // no repeat
+ exec(null, null, 'Vibration', 'vibrateWithPattern', [param, repeat]);
- //cancel vibration (param = 0 or [])
- else
- exec(null, null, "Vibration", "cancelVibration", []);
+ // cancel vibration (param = 0 or [])
+ } else { exec(null, null, 'Vibration', 'cancelVibration', []); }
return true;
},
@@ -106,16 +101,16 @@
* to start repeating (will repeat until canceled),
* or -1 for no repetition (default).
*/
- vibrateWithPattern: function(pattern, repeat) {
- repeat = (typeof repeat !== "undefined") ? repeat : -1;
- pattern = pattern.unshift(0); //add a 0 at beginning for backwards compatibility from w3c spec
- exec(null, null, "Vibration", "vibrateWithPattern", [pattern, repeat]);
+ vibrateWithPattern: function (pattern, repeat) {
+ repeat = (typeof repeat !== 'undefined') ? repeat : -1;
+ pattern = pattern.unshift(0); // add a 0 at beginning for backwards compatibility from w3c spec
+ exec(null, null, 'Vibration', 'vibrateWithPattern', [pattern, repeat]);
},
/**
* Immediately cancels any currently running vibration.
*/
- cancelVibration: function() {
- exec(null, null, "Vibration", "cancelVibration", []);
+ cancelVibration: function () {
+ exec(null, null, 'Vibration', 'cancelVibration', []);
}
};