From 0b532b6eeb04c6adbccfea60f132f88de0c14755 Mon Sep 17 00:00:00 2001 From: Audrey So Date: Fri, 9 Jun 2017 16:01:13 -0700 Subject: [PATCH] CB-12895 : setup eslint and removed jshint --- .eslintrc.yml | 10 ++++ .jshintrc | 17 ------- package.json | 12 +++-- src/blackberry10/index.js | 50 +++++++++---------- src/firefoxos/notification.js | 58 +++++++++++----------- src/windows/NotificationProxy.js | 81 ++++++++++++++++--------------- tests/tests.js | 82 ++++++++++++++++---------------- www/android/notification.js | 14 +++--- www/blackberry10/beep.js | 16 +++---- www/browser/notification.js | 37 +++++++------- www/notification.js | 50 +++++++++---------- 11 files changed, 208 insertions(+), 219 deletions(-) create mode 100644 .eslintrc.yml delete mode 100644 .jshintrc diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 00000000..0cccb8c7 --- /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/.jshintrc b/.jshintrc deleted file mode 100644 index 479adebd..00000000 --- a/.jshintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "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, - "Notification": true - } -} diff --git a/package.json b/package.json index c93dac01..8896a5cf 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "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" + "test": "npm run eslint", + "eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests" }, "author": "Apache Software Foundation", "license": "Apache-2.0", @@ -56,6 +56,12 @@ } }, "devDependencies": { - "jshint": "^2.6.0" + "eslint": "^3.19.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 4969a770..0f7fa2fe 100644 --- a/src/blackberry10/index.js +++ b/src/blackberry10/index.js @@ -16,41 +16,41 @@ /* global qnx, PluginResult */ -function showDialog(args, dialogType, result) { - //Unpack and map the args - var msg = JSON.parse(decodeURIComponent(args[0])), - title = JSON.parse(decodeURIComponent(args[1])), - btnLabel = JSON.parse(decodeURIComponent(args[2])); +function showDialog (args, dialogType, result) { + // Unpack and map the args + var msg = JSON.parse(decodeURIComponent(args[0])); + var title = JSON.parse(decodeURIComponent(args[1])); + var btnLabel = JSON.parse(decodeURIComponent(args[2])); if (!Array.isArray(btnLabel)) { - //Converts to array for (string) and (string,string, ...) cases - btnLabel = btnLabel.split(","); + // Converts to array for (string) and (string,string, ...) cases + btnLabel = btnLabel.split(','); } - if (msg && typeof msg === "string") { - msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"'); + if (msg && typeof msg === 'string') { + msg = msg.replace(/^"|"$/g, '').replace(/\\"/g, '"'); } else { - result.error("message is undefined"); + result.error('message is undefined'); return; } var messageObj = { - title : title, - htmlmessage : msg, - dialogType : dialogType, - optionalButtons : btnLabel + title: title, + htmlmessage: msg, + dialogType: dialogType, + optionalButtons: btnLabel }; - //TODO replace with getOverlayWebview() when available in webplatform + // TODO replace with getOverlayWebview() when available in webplatform qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) { - if (typeof data === "number") { - //Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc] + if (typeof data === 'number') { + // Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc] result.callbackOk(++data, false); } else { - //Prompt dialog callback expects object + // Prompt dialog callback expects object result.callbackOk({ buttonIndex: data.ok ? 1 : 0, - input1: (data.oktext) ? decodeURIComponent(data.oktext) : "" + input1: (data.oktext) ? decodeURIComponent(data.oktext) : '' }, false); } }); @@ -63,27 +63,27 @@ module.exports = { var result = new PluginResult(args, env); if (Object.keys(args).length < 3) { - result.error("Notification action - alert arguments not found."); + result.error('Notification action - alert arguments not found.'); } else { - showDialog(args, "CustomAsk", result); + showDialog(args, 'CustomAsk', result); } }, confirm: function (success, fail, args, env) { var result = new PluginResult(args, env); if (Object.keys(args).length < 3) { - result.error("Notification action - confirm arguments not found."); + result.error('Notification action - confirm arguments not found.'); } else { - showDialog(args, "CustomAsk", result); + showDialog(args, 'CustomAsk', result); } }, prompt: function (success, fail, args, env) { var result = new PluginResult(args, env); if (Object.keys(args).length < 3) { - result.error("Notification action - prompt arguments not found."); + result.error('Notification action - prompt arguments not found.'); } else { - showDialog(args, "JavaScriptPrompt", result); + showDialog(args, 'JavaScriptPrompt', result); } } }; diff --git a/src/firefoxos/notification.js b/src/firefoxos/notification.js index aea562d0..604cd859 100644 --- a/src/firefoxos/notification.js +++ b/src/firefoxos/notification.js @@ -21,14 +21,11 @@ var modulemapper = require('cordova/modulemapper'); - var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open'); +function _empty () {} -function _empty() {} - - -function modal(message, callback, title, buttonLabels, domObjects) { +function modal (message, callback, title, buttonLabels, domObjects) { var mainWindow = window; var modalWindow = origOpenFunc(); var modalDocument = modalWindow.document; @@ -61,24 +58,24 @@ function modal(message, callback, title, buttonLabels, domObjects) { box.appendChild(menu); for (var index = 0; index < buttonLabels.length; index++) { // TODO: last button listens to the cancel key - addButton(buttonLabels[index], (index+1), (index === 0)); + addButton(buttonLabels[index], (index + 1), (index === 0)); } modalDocument.body.appendChild(box); - function addButton(label, index, recommended) { + function addButton (label, index, recommended) { var thisButtonCallback = makeCallbackButton(index + 1); var button = modalDocument.createElement('button'); button.appendChild(modalDocument.createTextNode(label)); button.addEventListener('click', thisButtonCallback, false); if (recommended) { // TODO: default one listens to Enter key - button.classList.add('recommend'); + button.classList.add('recommend'); } menu.appendChild(button); } // TODO: onUnload listens to the cancel key - function onUnload() { + function onUnload () { var result = 0; if (modalDocument.getElementById('prompt-input')) { result = { @@ -86,53 +83,53 @@ function modal(message, callback, title, buttonLabels, domObjects) { buttonIndex: 0 }; } - mainWindow.setTimeout(function() { + mainWindow.setTimeout(function () { callback(result); }, 10); } modalWindow.addEventListener('unload', onUnload, false); // call callback and destroy modal - function makeCallbackButton(labelIndex) { - return function() { - if (modalWindow) { - modalWindow.removeEventListener('unload', onUnload, false); - modalWindow.close(); - } + function makeCallbackButton (labelIndex) { + return function () { + if (modalWindow) { + modalWindow.removeEventListener('unload', onUnload, false); + modalWindow.close(); + } // checking if prompt - var promptInput = modalDocument.getElementById('prompt-input'); - var response; - if (promptInput) { - response = { - input1: promptInput.value, - buttonIndex: labelIndex - }; - } - response = response || labelIndex; - callback(response); + var promptInput = modalDocument.getElementById('prompt-input'); + var response; + if (promptInput) { + response = { + input1: promptInput.value, + buttonIndex: labelIndex + }; + } + response = response || labelIndex; + callback(response); }; } } var Notification = { - vibrate: function(milliseconds) { + vibrate: function (milliseconds) { navigator.vibrate(milliseconds); }, - alert: function(successCallback, errorCallback, args) { + alert: function (successCallback, errorCallback, args) { var message = args[0]; var title = args[1]; var _buttonLabels = [args[2]]; var _callback = (successCallback || _empty); modal(message, _callback, title, _buttonLabels); }, - confirm: function(successCallback, errorCallback, args) { + confirm: function (successCallback, errorCallback, args) { var message = args[0]; var title = args[1]; var buttonLabels = args[2]; var _callback = (successCallback || _empty); modal(message, _callback, title, buttonLabels); }, - prompt: function(successCallback, errorCallback, args) { + prompt: function (successCallback, errorCallback, args) { var message = args[0]; var title = args[1]; var buttonLabels = args[2]; @@ -150,6 +147,5 @@ var Notification = { } }; - module.exports = Notification; require('cordova/exec/proxy').add('Notification', Notification); diff --git a/src/windows/NotificationProxy.js b/src/windows/NotificationProxy.js index c5bc2724..c3f9fc17 100644 --- a/src/windows/NotificationProxy.js +++ b/src/windows/NotificationProxy.js @@ -19,7 +19,7 @@ * */ -/*global Windows:true, WinJS, toStaticHTML */ +/* global Windows:true, WinJS, toStaticHTML */ var cordova = require('cordova'); var urlutil = require('cordova/urlutil'); @@ -27,8 +27,8 @@ var urlutil = require('cordova/urlutil'); var isAlertShowing = false; var alertStack = []; -function createCSSElem(fileName) { - var elemId = fileName.substr(0, fileName.lastIndexOf(".")) + "-plugin-style"; +function createCSSElem (fileName) { + var elemId = fileName.substr(0, fileName.lastIndexOf('.')) + '-plugin-style'; // If the CSS element exists, don't recreate it. if (document.getElementById(elemId)) { return false; @@ -37,42 +37,41 @@ function createCSSElem(fileName) { // Create CSS and append it to DOM. var $elem = document.createElement('link'); $elem.id = elemId; - $elem.rel = "stylesheet"; - $elem.type = "text/css"; - $elem.href = urlutil.makeAbsolute("/www/css/" + fileName); + $elem.rel = 'stylesheet'; + $elem.type = 'text/css'; + $elem.href = urlutil.makeAbsolute('/www/css/' + fileName); document.head.appendChild($elem); return true; } // CB-8928: When toStaticHTML is undefined, prompt fails to run -var _cleanHtml = function(html) { return html; }; +var _cleanHtml = function (html) { return html; }; if (typeof toStaticHTML !== 'undefined') { _cleanHtml = toStaticHTML; } // Windows does not provide native UI for promp dialog so we use some // simple html-based implementation until it is available -function createPromptDialog(title, message, buttons, defaultText, callback) { +function createPromptDialog (title, message, buttons, defaultText, callback) { - var isPhone = cordova.platformId === "windows" && WinJS.Utilities.isPhone; + var isPhone = cordova.platformId === 'windows' && WinJS.Utilities.isPhone; var isWindows = !!cordova.platformId.match(/windows/); - createCSSElem("notification.css"); + createCSSElem('notification.css'); - var dlgWrap = document.createElement("div"); - dlgWrap.className = "dlgWrap"; + var dlgWrap = document.createElement('div'); + dlgWrap.className = 'dlgWrap'; - var dlg = document.createElement("div"); - dlg.className = "dlgContainer"; + var dlg = document.createElement('div'); + dlg.className = 'dlgContainer'; if (isWindows) { - dlg.className += " dlgContainer-windows"; + dlg.className += ' dlgContainer-windows'; } else if (isPhone) { - dlg.className += " dlgContainer-phone"; + dlg.className += ' dlgContainer-phone'; } - // dialog layout template dlg.innerHTML = _cleanHtml("
" + // title "
" + // message @@ -83,24 +82,24 @@ function createPromptDialog(title, message, buttons, defaultText, callback) { dlg.querySelector('#prompt-input').setAttribute('placeholder', defaultText); dlg.querySelector('#prompt-input').setAttribute('value', defaultText); - function makeButtonCallback(idx) { + function makeButtonCallback (idx) { return function () { var value = dlg.querySelector('#prompt-input').value || defaultText; dlgWrap.parentNode.removeChild(dlgWrap); if (callback) { - callback({ input1: value, buttonIndex: idx }); + callback({ input1: value, buttonIndex: idx }); // eslint-disable-line standard/no-callback-literal } }; } - function addButton(idx, label) { + function addButton (idx, label) { var button = document.createElement('button'); - button.className = "dlgButton"; + button.className = 'dlgButton'; button.tabIndex = idx; button.onclick = makeButtonCallback(idx + 1); if (idx === 0) { - button.className += " dlgButtonFirst"; + button.className += ' dlgButtonFirst'; } button.appendChild(document.createTextNode(label)); dlg.appendChild(button); @@ -117,10 +116,10 @@ function createPromptDialog(title, message, buttons, defaultText, callback) { // make sure input field is under focus dlg.querySelector('#prompt-input').select(); // add Enter/Return key handling - var defaultButton = dlg.querySelector(".dlgButtonFirst"); - dlg.addEventListener("keypress",function(e) { + var defaultButton = dlg.querySelector('.dlgButtonFirst'); + dlg.addEventListener('keypress', function (e) { if (e.keyCode === 13) { // enter key - if(defaultButton) { + if (defaultButton) { defaultButton.click(); } } @@ -130,7 +129,7 @@ function createPromptDialog(title, message, buttons, defaultText, callback) { } module.exports = { - alert:function(win, loseX, args) { + alert: function (win, loseX, args) { if (isAlertShowing) { var later = function () { @@ -147,7 +146,7 @@ module.exports = { var md = new Windows.UI.Popups.MessageDialog(message, _title); md.commands.append(new Windows.UI.Popups.UICommand(_buttonLabel)); - md.showAsync().then(function() { + md.showAsync().then(function () { isAlertShowing = false; if (win) { win(); @@ -171,10 +170,10 @@ module.exports = { isAlertShowing = true; - var message = args[0], - title = args[1], - buttons = args[2], - defaultText = args[3]; + var message = args[0]; + var title = args[1]; + var buttons = args[2]; + var defaultText = args[3]; try { createPromptDialog(title, message, buttons, defaultText, function (evt) { @@ -195,7 +194,7 @@ module.exports = { } }, - confirm:function(win, loseX, args) { + confirm: function (win, loseX, args) { if (isAlertShowing) { var later = function () { @@ -214,11 +213,11 @@ module.exports = { var md = new Windows.UI.Popups.MessageDialog(message, _title); - buttons.forEach(function(buttonLabel) { + buttons.forEach(function (buttonLabel) { md.commands.append(new Windows.UI.Popups.UICommand(buttonLabel)); }); - md.showAsync().then(function(res) { + md.showAsync().then(function (res) { isAlertShowing = false; var result = res ? buttons.indexOf(res.label) + 1 : 0; if (win) { @@ -240,20 +239,20 @@ module.exports = { } }, - beep:function(winX, loseX, args) { + beep: function (winX, loseX, args) { // set a default args if it is not set - args = args && args.length ? args : ["1"]; + args = args && args.length ? args : ['1']; - var snd = new Audio('ms-winsoundevent:Notification.Default'); + var snd = new Audio('ms-winsoundevent:Notification.Default'); // eslint-disable-line no-undef var count = parseInt(args[0]) || 1; - snd.msAudioCategory = "Alerts"; + snd.msAudioCategory = 'Alerts'; var onEvent = function () { if (count > 0) { snd.play(); } else { - snd.removeEventListener("ended", onEvent); + snd.removeEventListener('ended', onEvent); snd = null; if (winX) { winX(); // notification.js just sends null, but this is future friendly @@ -261,10 +260,10 @@ module.exports = { } count--; }; - snd.addEventListener("ended", onEvent); + snd.addEventListener('ended', onEvent); onEvent(); } }; -require("cordova/exec/proxy").add("Notification",module.exports); +require('cordova/exec/proxy').add('Notification', module.exports); diff --git a/tests/tests.js b/tests/tests.js index fc1dea47..004570a5 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,33 +19,33 @@ * */ -/* jshint jasmine: true */ +/* eslint-env jasmine */ /* global cordova */ exports.defineAutoTests = function () { describe('Notification (navigator.notification)', function () { - it("should exist", function () { + it('should exist', function () { expect(navigator.notification).toBeDefined(); }); - it("should contain a beep function", function () { + it('should contain a beep function', function () { expect(typeof navigator.notification.beep).toBeDefined(); - expect(typeof navigator.notification.beep).toBe("function"); + expect(typeof navigator.notification.beep).toBe('function'); }); - it("should contain an alert function", function () { + it('should contain an alert function', function () { expect(typeof navigator.notification.alert).toBeDefined(); - expect(typeof navigator.notification.alert).toBe("function"); + expect(typeof navigator.notification.alert).toBe('function'); }); - it("should contain a confirm function", function () { + it('should contain a confirm function', function () { expect(typeof navigator.notification.confirm).toBeDefined(); - expect(typeof navigator.notification.confirm).toBe("function"); + expect(typeof navigator.notification.confirm).toBe('function'); }); - it("should contain a prompt function", function () { + it('should contain a prompt function', function () { expect(typeof navigator.notification.prompt).toBeDefined(); - expect(typeof navigator.notification.prompt).toBe("function"); + expect(typeof navigator.notification.prompt).toBe('function'); }); }); }; @@ -68,18 +68,18 @@ exports.defineManualTests = function (contentEl, createActionButton) { }; var beep = function () { - console.log("beep()"); + console.log('beep()'); navigator.notification.beep(3); }; var alertDialog = function (message, title, button) { - console.log("alertDialog()"); + console.log('alertDialog()'); navigator.notification.alert(message, function () { - console.log("Alert dismissed."); + console.log('Alert dismissed.'); }, title, button); - console.log("After alert"); + console.log('After alert'); }; var confirmDialogA = function (message, title, buttons) { @@ -87,11 +87,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { navigator.notification.confirm(message, function (r) { if (r === 0) { - logMessage("Dismissed dialog without making a selection."); - console.log("Dismissed dialog without making a selection."); + logMessage('Dismissed dialog without making a selection.'); + console.log('Dismissed dialog without making a selection.'); } else { - console.log("You selected " + r); - logMessage("You selected " + (buttons.split(","))[r - 1]); + console.log('You selected ' + r); + logMessage('You selected ' + (buttons.split(','))[r - 1]); } }, title, @@ -103,35 +103,35 @@ exports.defineManualTests = function (contentEl, createActionButton) { navigator.notification.confirm(message, function (r) { if (r === 0) { - logMessage("Dismissed dialog without making a selection."); - console.log("Dismissed dialog without making a selection."); + logMessage('Dismissed dialog without making a selection.'); + console.log('Dismissed dialog without making a selection.'); } else { - console.log("You selected " + r); - logMessage("You selected " + buttons[r - 1]); + console.log('You selected ' + r); + logMessage('You selected ' + buttons[r - 1]); } }, title, buttons); }; - var promptDialog = function (message, title, buttons,defaultText) { + var promptDialog = function (message, title, buttons, defaultText) { clearLog(); navigator.notification.prompt(message, function (r) { if (r && r.buttonIndex === 0) { - var msg = "Dismissed dialog"; + var msg = 'Dismissed dialog'; if (r.input1) { - msg += " with input: " + r.input1; + msg += ' with input: ' + r.input1; } logMessage(msg); console.log(msg); } else { - console.log("You selected " + r.buttonIndex + " and entered: " + r.input1); - logMessage("You selected " + buttons[r.buttonIndex - 1] + " and entered: " + r.input1); + console.log('You selected ' + r.buttonIndex + ' and entered: ' + r.input1); + logMessage('You selected ' + buttons[r.buttonIndex - 1] + ' and entered: ' + r.input1); } }, title, - buttons,defaultText); + buttons, defaultText); }; /******************************************************************************/ @@ -169,7 +169,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { }, 'alert'); // WP8.1 detection is necessary since it doesn't support confirm dialogs with more than 2 buttons - var isRunningOnWP81 = cordova.platformId == "windows" && navigator.userAgent.indexOf('Windows Phone') > -1; + var isRunningOnWP81 = cordova.platformId === 'windows' && navigator.userAgent.indexOf('Windows Phone') > -1; createActionButton('Confirm Dialog - Deprecated', function () { var buttons = isRunningOnWP81 ? 'Yes,No' : 'Yes,No,Maybe'; @@ -182,55 +182,55 @@ exports.defineManualTests = function (contentEl, createActionButton) { }, 'confirm'); createActionButton('Prompt Dialog', function () { - promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure'],'Default Text'); + promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure'], 'Default Text'); }, 'prompt'); createActionButton('Prompt Dialog - no default', function () { promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No']); - }, 'prompt'); + }, 'prompt'); createActionButton('Built-in Alert Dialog', function () { if (typeof alert === 'function') { - alert('You pressed alert'); + alert('You pressed alert'); // eslint-disable-line no-undef } }, 'built_in_alert'); createActionButton('Built-in Confirm Dialog', function () { if (typeof confirm === 'function') { - confirm('You selected confirm'); + confirm('You selected confirm'); // eslint-disable-line no-undef } }, 'built_in_confirm'); createActionButton('Built-in Prompt Dialog', function () { if (typeof prompt === 'function') { - prompt('This is a prompt', 'Default value'); + prompt('This is a prompt', 'Default value'); // eslint-disable-line no-undef } }, 'built_in_prompt'); // CB-8947 - ensure number messages don't crash iOS createActionButton('Alert Dialog with Number', function () { - var callback = function() { clearLog(); console.log("Test passed"); }; + var callback = function () { clearLog(); console.log('Test passed'); }; navigator.notification.alert(17, callback); }, 'cb8947'); // CB-8947 - ensure object messages don't crash iOS createActionButton('Alert Dialog with Object', function () { - var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947'}; - var callback = function() { clearLog(); console.log("Test passed"); }; + var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947' }; + var callback = function () { clearLog(); console.log('Test passed'); }; navigator.notification.alert(object, callback); }, 'cb8947'); // CB-8947 - ensure object messages don't crash iOS createActionButton('Confirm Dialog with Object', function () { - var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947'}; - var callback = function() { clearLog(); console.log("Test passed"); }; + var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947' }; + var callback = function () { clearLog(); console.log('Test passed'); }; navigator.notification.confirm(object, callback); }, 'cb8947'); // CB-8947 - ensure object messages don't crash iOS createActionButton('Prompt Dialog with Object', function () { - var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947'}; - var callback = function() { clearLog(); console.log("Test passed"); }; + var object = { number: 42, message: "Make sure an object doesn't crash iOS", issue: 'CB-8947' }; + var callback = function () { clearLog(); console.log('Test passed'); }; navigator.notification.prompt(object, callback); }, 'cb8947'); diff --git a/www/android/notification.js b/www/android/notification.js index 8936a5c2..5562a9fe 100644 --- a/www/android/notification.js +++ b/www/android/notification.js @@ -25,11 +25,11 @@ var exec = require('cordova/exec'); * Provides Android enhanced notification API. */ module.exports = { - activityStart : function(title, message) { + activityStart: function (title, message) { // If title and message not specified then mimic Android behavior of // using default strings. - if (typeof title === "undefined" && typeof message == "undefined") { - title = "Busy"; + if (typeof title === 'undefined' && typeof message === 'undefined') { + title = 'Busy'; message = 'Please wait...'; } @@ -39,7 +39,7 @@ module.exports = { /** * Close an activity dialog */ - activityStop : function() { + activityStop: function () { exec(null, null, 'Notification', 'activityStop', []); }, @@ -51,14 +51,14 @@ module.exports = { * @param {String} * message Message to display in the dialog. */ - progressStart : function(title, message) { + progressStart: function (title, message) { exec(null, null, 'Notification', 'progressStart', [ title, message ]); }, /** * Close the progress dialog. */ - progressStop : function() { + progressStop: function () { exec(null, null, 'Notification', 'progressStop', []); }, @@ -68,7 +68,7 @@ module.exports = { * @param {Number} * value 0-100 */ - progressValue : function(value) { + progressValue: function (value) { exec(null, null, 'Notification', 'progressValue', [ value ]); } }; diff --git a/www/blackberry10/beep.js b/www/blackberry10/beep.js index da2e75d1..da36d64d 100644 --- a/www/blackberry10/beep.js +++ b/www/blackberry10/beep.js @@ -20,22 +20,22 @@ */ module.exports = function (quantity) { - var count = 0, - beepObj; + var count = 0; + var beepObj; - function callback() { + function callback () { if (--count > 0) { play(); } else { - beepObj.removeEventListener("ended", callback); + beepObj.removeEventListener('ended', callback); beepObj = null; } } - function play() { - //create new object every time due to strage playback behaviour - beepObj = new Audio('local:///chrome/plugin/cordova-plugin-dialogs/notification-beep.wav'); - beepObj.addEventListener("ended", callback); + function play () { + // create new object every time due to strage playback behaviour + beepObj = new Audio('local:///chrome/plugin/cordova-plugin-dialogs/notification-beep.wav'); // eslint-disable-line no-undef + beepObj.addEventListener('ended', callback); beepObj.play(); } diff --git a/www/browser/notification.js b/www/browser/notification.js index 1fdfafd7..f8bb065a 100644 --- a/www/browser/notification.js +++ b/www/browser/notification.js @@ -22,9 +22,9 @@ // Platform: browser window.navigator.notification = window.navigator.notification || {}; -module.exports.alert = window.navigator.notification.alert = function(message, callback) { +module.exports.alert = window.navigator.notification.alert = function (message, callback) { // `notification.alert` executes asynchronously - setTimeout(function() { + setTimeout(function () { window.alert(message); if (callback) { callback(); @@ -32,40 +32,36 @@ module.exports.alert = window.navigator.notification.alert = function(message, c }, 0); }; - -module.exports.confirm = window.navigator.notification.confirm = function(message, callback) { +module.exports.confirm = window.navigator.notification.confirm = function (message, callback) { // `notification.confirm` executes asynchronously - setTimeout(function() { + /* eslint-disable standard/no-callback-literal */ + setTimeout(function () { var result = window.confirm(message); if (callback) { if (result) { callback(1); // OK - } - else { + } else { callback(2); // Cancel } } }, 0); }; - -module.exports.prompt = window.navigator.notification.prompt = function(message, callback, title, buttonLabels, defaultText) { +module.exports.prompt = window.navigator.notification.prompt = function (message, callback, title, buttonLabels, defaultText) { // `notification.prompt` executes asynchronously - setTimeout(function() { - var result = window.prompt(message, defaultText || ''); + setTimeout(function () { + var result = window.prompt(message, defaultText || ''); if (callback) { if (result === null) { callback({ buttonIndex: 2, input1: '' }); // Cancel - } - else { + } else { callback({ buttonIndex: 1, input1: result }); // OK } } }, 0); }; - - -var audioContext = (function() { +/* eslint-enable standard/no-callback-literal */ +var audioContext = (function () { // Determine if the Audio API is supported by this browser var AudioApi = window.AudioContext; if (!AudioApi) { @@ -80,7 +76,7 @@ var audioContext = (function() { return undefined; }()); -module.exports.beep = window.navigator.notification.beep = function(times) { +module.exports.beep = window.navigator.notification.beep = function (times) { if (times > 0) { var BEEP_DURATION = 700; var BEEP_INTERVAL = 300; @@ -92,20 +88,19 @@ module.exports.beep = window.navigator.notification.beep = function(times) { osc.connect(audioContext.destination); osc.start(0); - setTimeout(function() { + setTimeout(function () { // Stop the beep after the BEEP_DURATION osc.stop(0); if (--times > 0) { // Beep again, after a pause - setTimeout(function() { + setTimeout(function () { navigator.notification.beep(times); }, BEEP_INTERVAL); } }, BEEP_DURATION); - } - else if (typeof(console) !== 'undefined' && typeof(console.log) === 'function') { + } else if (typeof (console) !== 'undefined' && typeof (console.log) === 'function') { // Audio API isn't supported, so just write `beep` to the console for (var i = 0; i < times; i++) { console.log('Beep!'); diff --git a/www/notification.js b/www/notification.js index b6d4d394..4a428d7d 100644 --- a/www/notification.js +++ b/www/notification.js @@ -36,11 +36,11 @@ module.exports = { * @param {String} title Title of the alert dialog (default: Alert) * @param {String} buttonLabel Label of the close button (default: OK) */ - alert: function(message, completeCallback, title, buttonLabel) { - var _message = (typeof message === "string" ? message : JSON.stringify(message)); - var _title = (typeof title === "string" ? title : "Alert"); - var _buttonLabel = (buttonLabel && typeof buttonLabel === "string" ? buttonLabel : "OK"); - exec(completeCallback, null, "Notification", "alert", [_message, _title, _buttonLabel]); + alert: function (message, completeCallback, title, buttonLabel) { + var _message = (typeof message === 'string' ? message : JSON.stringify(message)); + var _title = (typeof title === 'string' ? title : 'Alert'); + var _buttonLabel = (buttonLabel && typeof buttonLabel === 'string' ? buttonLabel : 'OK'); + exec(completeCallback, null, 'Notification', 'alert', [_message, _title, _buttonLabel]); }, /** @@ -52,19 +52,19 @@ module.exports = { * @param {String} title Title of the alert dialog (default: Confirm) * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) */ - confirm: function(message, resultCallback, title, buttonLabels) { - var _message = (typeof message === "string" ? message : JSON.stringify(message)); - var _title = (typeof title === "string" ? title : "Confirm"); - var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); + confirm: function (message, resultCallback, title, buttonLabels) { + var _message = (typeof message === 'string' ? message : JSON.stringify(message)); + var _title = (typeof title === 'string' ? title : 'Confirm'); + var _buttonLabels = (buttonLabels || ['OK', 'Cancel']); // Strings are deprecated! if (typeof _buttonLabels === 'string') { - console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); + console.log('Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).'); } _buttonLabels = convertButtonLabels(_buttonLabels); - exec(resultCallback, null, "Notification", "confirm", [_message, _title, _buttonLabels]); + exec(resultCallback, null, 'Notification', 'confirm', [_message, _title, _buttonLabels]); }, /** @@ -79,20 +79,20 @@ module.exports = { * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) * @param {String} defaultText Textbox input value (default: empty string) */ - prompt: function(message, resultCallback, title, buttonLabels, defaultText) { - var _message = (typeof message === "string" ? message : JSON.stringify(message)); - var _title = (typeof title === "string" ? title : "Prompt"); - var _buttonLabels = (buttonLabels || ["OK","Cancel"]); + prompt: function (message, resultCallback, title, buttonLabels, defaultText) { + var _message = (typeof message === 'string' ? message : JSON.stringify(message)); + var _title = (typeof title === 'string' ? title : 'Prompt'); + var _buttonLabels = (buttonLabels || ['OK', 'Cancel']); // Strings are deprecated! if (typeof _buttonLabels === 'string') { - console.log("Notification.prompt(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); + console.log('Notification.prompt(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).'); } _buttonLabels = convertButtonLabels(_buttonLabels); - var _defaultText = (defaultText || ""); - exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); + var _defaultText = (defaultText || ''); + exec(resultCallback, null, 'Notification', 'prompt', [_message, _title, _buttonLabels, _defaultText]); }, /** @@ -101,23 +101,23 @@ module.exports = { * * @param {Integer} count The number of beeps. */ - beep: function(count) { + beep: function (count) { var defaultedCount = count || 1; - exec(null, null, "Notification", "beep", [ defaultedCount ]); + exec(null, null, 'Notification', 'beep', [ defaultedCount ]); } }; -function convertButtonLabels(buttonLabels) { +function convertButtonLabels (buttonLabels) { // Some platforms take an array of button label names. // Other platforms take a comma separated list. // For compatibility, we convert to the desired type based on the platform. - if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || - platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || - platform.id == "windows8" || platform.id == "windows") { + if (platform.id === 'amazon-fireos' || platform.id === 'android' || platform.id === 'ios' || + platform.id === 'windowsphone' || platform.id === 'firefoxos' || platform.id === 'ubuntu' || + platform.id === 'windows8' || platform.id === 'windows') { if (typeof buttonLabels === 'string') { - buttonLabels = buttonLabels.split(","); // not crazy about changing the var type here + buttonLabels = buttonLabels.split(','); // not crazy about changing the var type here } } else { if (Array.isArray(buttonLabels)) {