Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4FDB518942 for ; Wed, 24 Feb 2016 14:27:15 +0000 (UTC) Received: (qmail 64273 invoked by uid 500); 24 Feb 2016 14:20:29 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 64243 invoked by uid 500); 24 Feb 2016 14:20:29 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 64234 invoked by uid 99); 24 Feb 2016 14:20:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Feb 2016 14:20:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2A14DE8EA3; Wed, 24 Feb 2016 14:20:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: daserge@apache.org To: commits@cordova.apache.org Message-Id: <17241b7c2cf44e01b6d98e096ecd5f67@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cordova-plugin-camera git commit: CB-10636 Add JSHint for plugins Date: Wed, 24 Feb 2016 14:20:29 +0000 (UTC) Repository: cordova-plugin-camera Updated Branches: refs/heads/master c1948fc0d -> b16c5234d CB-10636 Add JSHint for plugins Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/b16c5234 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/b16c5234 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/b16c5234 Branch: refs/heads/master Commit: b16c5234d5846d5235c2824ece2082255c4f1ce6 Parents: c1948fc Author: daserge Authored: Thu Feb 18 15:18:09 2016 +0300 Committer: daserge Committed: Wed Feb 24 17:14:58 2016 +0300 ---------------------------------------------------------------------- .jshintrc | 16 ++++++++++++ .travis.yml | 4 +++ README.md | 2 ++ jsdoc2md/TEMPLATE.md | 2 ++ package.json | 7 ++++-- src/blackberry10/index.js | 9 ++++--- src/browser/CameraProxy.js | 2 -- src/firefoxos/CameraProxy.js | 4 ++- src/windows/CameraProxy.js | 46 +++++++++++++++++------------------ tests/tests.js | 51 +++++++++++++++++++++------------------ www/CameraPopoverHandle.js | 2 -- 11 files changed, 88 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/.jshintrc ---------------------------------------------------------------------- diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..cf48aac --- /dev/null +++ b/.jshintrc @@ -0,0 +1,16 @@ +{ + "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 + } +} http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b9af4c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: + - "4.2" http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 6eb650c..520dd6f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ # under the License. --> +[![Build Status](https://travis-ci.org/apache/cordova-plugin-camera.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-camera) + # cordova-plugin-camera This plugin defines a global `navigator.camera` object, which provides an API for taking pictures and for choosing images from http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/jsdoc2md/TEMPLATE.md ---------------------------------------------------------------------- diff --git a/jsdoc2md/TEMPLATE.md b/jsdoc2md/TEMPLATE.md index 39f06ba..9422564 100644 --- a/jsdoc2md/TEMPLATE.md +++ b/jsdoc2md/TEMPLATE.md @@ -1,5 +1,7 @@ {{>cdv-license~}} +[![Build Status](https://travis-ci.org/apache/cordova-plugin-camera.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-camera) + # cordova-plugin-camera This plugin defines a global `navigator.camera` object, which provides an API for taking pictures and for choosing images from http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 35fc2e3..fc5b333 100644 --- a/package.json +++ b/package.json @@ -43,13 +43,16 @@ }, "scripts": { "precommit": "npm run gen-docs && git add README.md", - "gen-docs": "jsdoc2md --template \"jsdoc2md/TEMPLATE.md\" \"www/**/*.js\" --plugin \"dmd-plugin-cordova-plugin\" > README.md" + "gen-docs": "jsdoc2md --template \"jsdoc2md/TEMPLATE.md\" \"www/**/*.js\" --plugin \"dmd-plugin-cordova-plugin\" > README.md", + "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" }, "author": "Apache Software Foundation", "license": "Apache-2.0", "devDependencies": { "dmd-plugin-cordova-plugin": "^0.1.0", "husky": "^0.10.1", - "jsdoc-to-markdown": "^1.2.0" + "jsdoc-to-markdown": "^1.2.0", + "jshint": "^2.6.0" } } http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/src/blackberry10/index.js ---------------------------------------------------------------------- diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js index b913368..afc3539 100644 --- a/src/blackberry10/index.js +++ b/src/blackberry10/index.js @@ -18,6 +18,9 @@ * under the License. * */ + +/* globals qnx, FileError, PluginResult */ + var PictureSourceType = { PHOTOLIBRARY : 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android) CAMERA : 1, // Take picture from camera @@ -40,7 +43,7 @@ window.qnx.webplatform.getApplication().invocation.queryTargets( }, function (error, targets) { invokeAvailable = !error && targets && targets instanceof Array && - targets.filter(function (t) { return t.default === 'sys.camera.card' }).length > 0; + targets.filter(function (t) { return t.default === 'sys.camera.card'; }).length > 0; } ); @@ -85,7 +88,7 @@ function showCameraDialog (done, cancel, fail) { //create unique name for saved file (same pattern as BB10 camera app) function imgName() { var date = new Date(), - pad = function (n) { return n < 10 ? '0' + n : n }; + pad = function (n) { return n < 10 ? '0' + n : n; }; return 'IMG_' + date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' + pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds()) + '.png'; } @@ -145,7 +148,7 @@ function encodeBase64(filePath, callback) { default: msg += "Unknown Error"; break; - }; + } // set it back to original value window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/src/browser/CameraProxy.js ---------------------------------------------------------------------- diff --git a/src/browser/CameraProxy.js b/src/browser/CameraProxy.js index d115f51..8f95c6f 100644 --- a/src/browser/CameraProxy.js +++ b/src/browser/CameraProxy.js @@ -32,8 +32,6 @@ function takePicture(success, error, opts) { input.name = 'files[]'; input.onchange = function(inputEvent) { - var canvas = document.createElement('canvas'); - var reader = new FileReader(); reader.onload = function(readerEvent) { input.parentNode.removeChild(input); http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/src/firefoxos/CameraProxy.js ---------------------------------------------------------------------- diff --git a/src/firefoxos/CameraProxy.js b/src/firefoxos/CameraProxy.js index 872d0ad..1e3018e 100644 --- a/src/firefoxos/CameraProxy.js +++ b/src/firefoxos/CameraProxy.js @@ -19,6 +19,8 @@ * */ +/* globals MozActivity */ + function takePicture(success, error, opts) { var pick = new MozActivity({ name: "pick", @@ -32,7 +34,7 @@ function takePicture(success, error, opts) { pick.onsuccess = function() { // image is returned as Blob in this.result.blob // we need to call success with url or base64 encoded image - if (opts && opts.destinationType == 0) { + if (opts && opts.destinationType === 0) { // TODO: base64 return; } http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/src/windows/CameraProxy.js ---------------------------------------------------------------------- diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js index 3acba81..46a7aa9 100644 --- a/src/windows/CameraProxy.js +++ b/src/windows/CameraProxy.js @@ -325,14 +325,14 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { CaptureNS = Windows.Media.Capture, sensor = null; - var createCameraUI = function () { + function createCameraUI() { // create style for take and cancel buttons var buttonStyle = "width:45%;padding: 10px 16px;font-size: 18px;line-height: 1.3333333;color: #333;background-color: #fff;border-color: #ccc; border: 1px solid transparent;border-radius: 6px; display: block; margin: 20px; z-index: 1000;border-color: #adadad;"; // Create fullscreen preview // z-order style element for capturePreview and cameraCancelButton elts // is necessary to avoid overriding by another page elements, -1 sometimes is not enough - capturePreview = document.createElement("video"); + capturePreview = document.createElement("video"); capturePreview.style.cssText = "position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: " + (HIGHEST_POSSIBLE_Z_INDEX - 1) + ";"; // Create capture button @@ -349,9 +349,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { captureSettings = new CaptureNS.MediaCaptureInitializationSettings(); captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video; - }; + } - var startCameraPreview = function () { + function startCameraPreview() { // Search for available camera devices // This is necessary to detect which camera (front or back) we should use var DeviceEnum = Windows.Devices.Enumeration; @@ -443,9 +443,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { destroyCameraPreview(); errorCallback('Camera intitialization error ' + err); }); - }; + } - var destroyCameraPreview = function () { + function destroyCameraPreview() { // If sensor is available, remove event listener if (sensor !== null) { sensor.removeEventListener('orientationchanged', onOrientationChange); @@ -471,9 +471,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { capture.stopRecordAsync(); capture = null; } - }; + } - var captureAction = function () { + function captureAction() { var encodingProperties, fileName, @@ -535,9 +535,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { destroyCameraPreview(); errorCallback(err); }); - }; + } - var getAspectRatios = function (capture) { + function getAspectRatios(capture) { var videoDeviceController = capture.videoDeviceController; var photoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo).map(function (element) { return (element.width / element.height).toFixed(1); @@ -564,9 +564,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { return Object.keys(aspectObj).filter(function (k) { return aspectObj[k] === 3; }); - }; + } - var setAspectRatio = function (capture, aspect) { + function setAspectRatio(capture, aspect) { // Max photo resolution with desired aspect ratio var videoDeviceController = capture.videoDeviceController; var photoResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo) @@ -602,12 +602,12 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { .then(function () { return videoDeviceController.setMediaStreamPropertiesAsync(CapMSType.videoRecord, videoRecordResolution); }); - }; + } /** * When Capture button is clicked, try to capture a picture and return */ - var onCameraCaptureButtonClick = function() { + function onCameraCaptureButtonClick() { // Make sure user can't click more than once if (this.getAttribute('clicked') === '1') { return false; @@ -615,12 +615,12 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { this.setAttribute('clicked', '1'); } captureAction(); - }; + } /** * When Cancel button is clicked, destroy camera preview and return with error callback */ - var onCameraCancelButtonClick = function() { + function onCameraCancelButtonClick() { // Make sure user can't click more than once if (this.getAttribute('clicked') === '1') { return false; @@ -629,15 +629,15 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { } destroyCameraPreview(); errorCallback('no image selected'); - }; + } /** * When the phone orientation change, get the event and change camera preview rotation * @param {Object} e - SimpleOrientationSensorOrientationChangedEventArgs */ - var onOrientationChange = function (e) { + function onOrientationChange(e) { setPreviewRotation(e.orientation); - }; + } /** * Converts SimpleOrientation to a VideoRotation to remove difference between camera sensor orientation @@ -645,7 +645,7 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { * @param {number} orientation - Windows.Devices.Sensors.SimpleOrientation * @return {number} - Windows.Media.Capture.VideoRotation */ - var orientationToRotation = function (orientation) { + function orientationToRotation(orientation) { // VideoRotation enumerable and BitmapRotation enumerable have the same values // https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.videorotation.aspx // https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaprotation.aspx @@ -669,15 +669,15 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { // Falling back to portrait default return Windows.Media.Capture.VideoRotation.clockwise90Degrees; } - }; + } /** * Rotates the current MediaCapture's video * @param {number} orientation - Windows.Devices.Sensors.SimpleOrientation */ - var setPreviewRotation = function(orientation) { + function setPreviewRotation(orientation) { capture.setPreviewRotation(orientationToRotation(orientation)); - }; + } try { createCameraUI(); http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b16c5234/tests/tests.js ---------------------------------------------------------------------- diff --git a/tests/tests.js b/tests/tests.js index 868140c..fd7bd6f 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,6 +19,9 @@ * */ +/* globals Camera, resolveLocalFileSystemURI, FileEntry, CameraPopoverOptions, FileTransfer, FileUploadOptions, LocalFileSystem, MSApp */ +/* jshint jasmine: true */ + exports.defineAutoTests = function () { describe('Camera (navigator.camera)', function () { it("should exist", function () { @@ -78,7 +81,6 @@ exports.defineAutoTests = function () { /******************************************************************************/ exports.defineManualTests = function (contentEl, createActionButton) { - var platformId = cordova.require('cordova/platform').id; var pictureUrl = null; var fileObj = null; var fileEntry = null; @@ -94,11 +96,6 @@ exports.defineManualTests = function (contentEl, createActionButton) { var camCorrectOrientationDefault = ['correctOrientation', false]; var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true]; - var clearLog = function () { - var log = document.getElementById('info'); - log.innerHTML = ""; - } - function log(value) { console.log(value); document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n'; @@ -130,7 +127,9 @@ exports.defineManualTests = function (contentEl, createActionButton) { img.src = url; img.onloadend = function () { log('Image tag load time: ' + (new Date() - startTime)); - callback && callback(); + if (callback) { + callback(); + } }; } @@ -141,13 +140,13 @@ exports.defineManualTests = function (contentEl, createActionButton) { function getPictureWin(data) { setPicture(data); // TODO: Fix resolveLocalFileSystemURI to work with native-uri. - if (pictureUrl.indexOf('file:') == 0 || pictureUrl.indexOf('content:') == 0 || pictureUrl.indexOf('ms-appdata:') === 0 || pictureUrl.indexOf('assets-library:') === 0) { + if (pictureUrl.indexOf('file:') === 0 || pictureUrl.indexOf('content:') === 0 || pictureUrl.indexOf('ms-appdata:') === 0 || pictureUrl.indexOf('assets-library:') === 0) { resolveLocalFileSystemURI(data, function (e) { fileEntry = e; logCallback('resolveLocalFileSystemURI()', true)(e.toURL()); readFile(); }, logCallback('resolveLocalFileSystemURI()', false)); - } else if (pictureUrl.indexOf('data:image/jpeg;base64') == 0) { + } else if (pictureUrl.indexOf('data:image/jpeg;base64') === 0) { // do nothing } else { var path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' '); @@ -165,13 +164,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { window.onorientationchange = function () { var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0); popoverHandle.setPosition(newPopoverOptions); - } + }; } function uploadImage() { var ft = new FileTransfer(), - uploadcomplete = 0, - progress = 0, options = new FileUploadOptions(); options.fileKey = "photo"; options.fileName = 'test.jpg'; @@ -207,7 +204,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { img.style.display = "block"; img.src = evt.target.result; log("FileReader.readAsDataURL success"); - }; + } function onFileReceived(file) { log('Got file: ' + JSON.stringify(file)); @@ -220,7 +217,8 @@ exports.defineManualTests = function (contentEl, createActionButton) { reader.onerror = logCallback('FileReader.readAsDataURL', false); reader.onloadend = onFileReadAsDataURL; reader.readAsDataURL(file); - }; + } + // Test out onFileReceived when the file object was set via a native elements. if (fileObj) { onFileReceived(fileObj); @@ -228,13 +226,14 @@ exports.defineManualTests = function (contentEl, createActionButton) { fileEntry.file(onFileReceived, logCallback('FileEntry.file', false)); } } + function getFileInfo() { // Test FileEntry API here. fileEntry.getMetadata(logCallback('FileEntry.getMetadata', true), logCallback('FileEntry.getMetadata', false)); fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { "com.apple.MobileBackup": 1 }); fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false)); fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false)); - }; + } /** * Copy image from library using a NATIVE_URI destination type @@ -268,7 +267,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { }; window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null); - }; + } /** * Write image to library using a NATIVE_URI destination type @@ -289,7 +288,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { fileEntry.createWriter(onFileWriterReceived, logCallback('FileEntry.createWriter', false)); fileEntry.createWriter(onFileTruncateWriterReceived, null); - }; + } function displayImageUsingCanvas() { var canvas = document.getElementById('canvas'); @@ -302,7 +301,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { canvas.height = h; var context = canvas.getContext('2d'); context.drawImage(img, 0, 0, w, h); - }; + } /** * Remove image from library using a NATIVE_URI destination type @@ -310,7 +309,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { */ function removeImage() { fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false)); - }; + } function testInputTag(inputEl) { clearStatus(); @@ -319,7 +318,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { window.setTimeout(function () { testNativeFile2(inputEl); }, 0); - }; + } function testNativeFile2(inputEl) { if (!inputEl.value) { @@ -349,15 +348,19 @@ exports.defineManualTests = function (contentEl, createActionButton) { function extractOptions() { var els = document.querySelectorAll('#image-options select'); var ret = {}; + /*jshint -W084 */ for (var i = 0, el; el = els[i]; ++i) { var value = el.value; if (value === '') continue; + value = +value; + if (el.isBool) { - ret[el.getAttribute("name")] = !!+value; + ret[el.getAttribute("name")] = !!value; } else { - ret[el.getAttribute("name")] = +value; + ret[el.getAttribute("name")] = value; } } + /*jshint +W084 */ return ret; } @@ -366,7 +369,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { var select = '