Skip to content

Commit

Permalink
CB-12895 : setup eslint and removed jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso committed Aug 2, 2017
1 parent 8225941 commit 0b532b6
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 219 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
50 changes: 25 additions & 25 deletions src/blackberry10/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand All @@ -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);
}
}
};
58 changes: 27 additions & 31 deletions src/firefoxos/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,78 +58,78 @@ 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 = {
input1: '',
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];
Expand All @@ -150,6 +147,5 @@ var Notification = {
}
};


module.exports = Notification;
require('cordova/exec/proxy').add('Notification', Notification);
Loading

0 comments on commit 0b532b6

Please sign in to comment.