Skip to content
Permalink
Browse files
CB-12895 : added eslint and removed jshint
  • Loading branch information
audreyso committed Aug 2, 2017
1 parent efcce56 commit 1694228a2cd01bdea8b15fb0d6b6f8d4dbcb091f
Showing 18 changed files with 260 additions and 268 deletions.
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off

This file was deleted.

@@ -40,8 +40,8 @@
"cordova-windows"
],
"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",
@@ -56,6 +56,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"
}
}
@@ -21,60 +21,60 @@

/* global PluginResult */

//cordova-js/lib/common/plugin/CaptureError.js
var INTERNAL_ERROR_CODE = 0,
APPLICATION_BUSY_ERROR_CODE = 1,
INVALID_ARGUMENT_ERROR_CODE = 2,
NO_MEDIA_FILES_ERROR_CODE = 3;
// cordova-js/lib/common/plugin/CaptureError.js
var INTERNAL_ERROR_CODE = 0;
var APPLICATION_BUSY_ERROR_CODE = 1;
var INVALID_ARGUMENT_ERROR_CODE = 2;
var NO_MEDIA_FILES_ERROR_CODE = 3;

function capture(action, options, result, webview) {
var limit = options.limit || 1,
fail = function (error) {
result.callbackError({code: INTERNAL_ERROR_CODE});
},
onCaptured = function (path) {
var sb = webview.setFileSystemSandbox;
webview.setFileSystemSandbox = false;
window.webkitRequestFileSystem(window.PERSISTENT, 1024, function (fs) {
fs.root.getFile(path, {}, function (fe) {
fe.file(function (file) {
file.fullPath = fe.fullPath;
webview.setFileSystemSandbox = sb;
result.callbackOk([file]);
}, fail);
function capture (action, options, result, webview) {
var limit = options.limit || 1;
var fail = function (error) { // eslint-disable-line handle-callback-err
result.callbackError({code: INTERNAL_ERROR_CODE});
};
var onCaptured = function (path) {
var sb = webview.setFileSystemSandbox;
webview.setFileSystemSandbox = false;
window.webkitRequestFileSystem(window.PERSISTENT, 1024, function (fs) {
fs.root.getFile(path, {}, function (fe) {
fe.file(function (file) {
file.fullPath = fe.fullPath;
webview.setFileSystemSandbox = sb;
result.callbackOk([file]);
}, fail);
}, fail);
},
onAudioCaptured = function (response) {
window.qnx.webplatform.getApplication().invocation.removeEventListener("childCardClosed", onAudioCaptured);
if (response.data && response.data !== "") {
onCaptured(response.data);
} else {
result.callbackError({code: NO_MEDIA_FILES_ERROR_CODE });
}
},
onCancelled = function () {
result.callbackError({code: NO_MEDIA_FILES_ERROR_CODE });
},
onInvoked = function (error) {
if (error) {
result.callbackError({code: APPLICATION_BUSY_ERROR_CODE});
}
};
}, fail);
};
var onAudioCaptured = function (response) {
window.qnx.webplatform.getApplication().invocation.removeEventListener('childCardClosed', onAudioCaptured);
if (response.data && response.data !== '') {
onCaptured(response.data);
} else {
result.callbackError({ code: NO_MEDIA_FILES_ERROR_CODE });
}
};
var onCancelled = function () {
result.callbackError({ code: NO_MEDIA_FILES_ERROR_CODE });
};
var onInvoked = function (error) {
if (error) {
result.callbackError({ code: APPLICATION_BUSY_ERROR_CODE });
}
};

if (limit < 0) {
result.error({code: INVALID_ARGUMENT_ERROR_CODE});
} else if (action === "audio") {
} else if (action === 'audio') {
window.qnx.webplatform.getApplication().invocation.invoke(
{
target: "sys.apps.audiorecorder",
action: "bb.action.CAPTURE"
{
target: 'sys.apps.audiorecorder',
action: 'bb.action.CAPTURE'
},
function (error) {
if (error) {
console.log(error);
} else {
window.qnx.webplatform.getApplication().invocation.addEventListener("childCardClosed", onAudioCaptured);
window.qnx.webplatform.getApplication().invocation.addEventListener('childCardClosed', onAudioCaptured);
}
});
result.noResult(true);
@@ -98,19 +98,19 @@ module.exports = {
result.ok([]);
},
captureImage: function (win, fail, args, env) {
var result = new PluginResult(args, env),
options = args[0] === "undefined" ? {} : JSON.parse(decodeURIComponent(args[0]));
var result = new PluginResult(args, env);
var options = args[0] === 'undefined' ? {} : JSON.parse(decodeURIComponent(args[0]));

capture("photo", options, result, env.webview);
capture('photo', options, result, env.webview);
},
captureVideo: function (win, fail, args, env) {
var result = new PluginResult(args, env),
options = args[0] === "undefined" ? {} : JSON.parse(decodeURIComponent(args[0]));
var result = new PluginResult(args, env);
var options = args[0] === 'undefined' ? {} : JSON.parse(decodeURIComponent(args[0]));

capture("video", options, result, env.webview);
capture('video', options, result, env.webview);
},
captureAudio: function (win, fail, args, env) {
var result = new PluginResult(args, env);
capture("audio", {}, result, env.webview);
capture('audio', {}, result, env.webview);
}
};
@@ -19,7 +19,7 @@
*
*/

/*global require, module*/
/* global require, module */

var MediaFile = require('cordova-plugin-media-capture.MediaFile');
var MediaFileData = require('cordova-plugin-media-capture.MediaFileData');
@@ -30,10 +30,10 @@ var CaptureError = require('cordova-plugin-media-capture.CaptureError');
* @param {String} dataURI Data URI to convert
* @return {Blob} Blob, covnerted from DataURI String
*/
function dataURItoBlob(dataURI) {
function dataURItoBlob (dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs
var byteString = atob(dataURI.split(',')[1]);
var byteString = atob(dataURI.split(',')[1]); // eslint-disable-line no-undef

// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
@@ -46,26 +46,26 @@ function dataURItoBlob(dataURI) {
}

// write the ArrayBuffer to a blob, and you're done
return new Blob([ab], { type: mimeString });
return new Blob([ab], { type: mimeString }); // eslint-disable-line no-undef
}

/**
* Creates basic camera UI with preview 'video' element and 'Cancel' button
* Capture starts, when you clicking on preview.
*/
function CameraUI() {
function CameraUI () {

// Root element for preview
// Root element for preview
var container = document.createElement('div');
container.style.cssText = "left: 0px; top: 0px; width: 100%; height: 100%; position: fixed; z-index:9999;" +
"padding: 40px; background-color: rgba(0,0,0,0.75);" +
"text-align:center; visibility: hidden";
container.style.cssText = 'left: 0px; top: 0px; width: 100%; height: 100%; position: fixed; z-index:9999;' +
'padding: 40px; background-color: rgba(0,0,0,0.75);' +
'text-align:center; visibility: hidden';

// Set up root element contetnts
container.innerHTML =
'<div id="captureHint" style="height:100%; position:relative; display:inline-flex; align-content:flex-start;">' +
'<h2 style="position: absolute; width: 100%; background-color: rgba(255,255,255,0.25); margin: 0">' +
'Click on preview to capture image. Click outside of preview to cancel.</h1>' +
'Click on preview to capture image. Click outside of preview to cancel.</h1>' +
'<video id="capturePreview" style="height: 100%"></video>' +
'</div>';

@@ -91,7 +91,7 @@ function CameraUI() {
* @param {Function} successCB Success callback, that accepts data URL of captured image
* @param {Function} errorCB Error callback
*/
CameraUI.prototype.startPreview = function(count, successCB, errorCB) {
CameraUI.prototype.startPreview = function (count, successCB, errorCB) {
var that = this;

this.preview.onclick = function (e) {
@@ -115,12 +115,12 @@ CameraUI.prototype.startPreview = function(count, successCB, errorCB) {
};

navigator.getUserMedia({video: true}, function (previewStream) {
// Save video stream to be able to stop it later
// Save video stream to be able to stop it later
that._previewStream = previewStream;
that.preview.src = URL.createObjectURL(previewStream);
that.preview.src = URL.createObjectURL(previewStream); // eslint-disable-line no-undef
// We don't need to set visibility = true for preview element
// since this will be done automatically in onplay event handler
}, function (/*err*/) {
}, function (/* err */) {
errorCB(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));
});
};
@@ -138,21 +138,20 @@ CameraUI.prototype.destroyPreview = function () {
}
};


module.exports = {
captureAudio:function(successCallback, errorCallback) {
captureAudio: function (successCallback, errorCallback) {
if (errorCallback) {
errorCallback(new CaptureError(CaptureError.CAPTURE_NOT_SUPPORTED));
}
},

captureVideo:function (successCallback, errorCallback) {
captureVideo: function (successCallback, errorCallback) {
if (errorCallback) {
errorCallback(new CaptureError(CaptureError.CAPTURE_NOT_SUPPORTED));
}
},

captureImage:function (successCallback, errorCallback, args) {
captureImage: function (successCallback, errorCallback, args) {

var fail = function (code) {
if (errorCallback) {
@@ -231,4 +230,4 @@ module.exports = {
}
};

require("cordova/exec/proxy").add("Capture",module.exports);
require('cordova/exec/proxy').add('Capture', module.exports);

0 comments on commit 1694228

Please sign in to comment.