dep(dev)!: bump @cordova/eslint-config@5.0.0 (#846)

* dep(dev)!: bump @cordova/eslint-config@5.0.0
* chore: apply automatic lint fix
This commit is contained in:
エリス 2023-08-18 00:59:25 +09:00 committed by GitHub
parent c2eb21d201
commit 61a6e9bb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2067 additions and 2039 deletions

3666
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -66,6 +66,6 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@cordova/eslint-config": "^3.0.0" "@cordova/eslint-config": "^5.0.0"
} }
} }

View File

@ -19,13 +19,13 @@
* *
*/ */
var HIGHEST_POSSIBLE_Z_INDEX = 2147483647; const HIGHEST_POSSIBLE_Z_INDEX = 2147483647;
function takePicture (success, error, opts) { function takePicture (success, error, opts) {
if (opts && opts[2] === 1) { if (opts && opts[2] === 1) {
capture(success, error, opts); capture(success, error, opts);
} else { } else {
var input = document.createElement('input'); const input = document.createElement('input');
input.style.position = 'relative'; input.style.position = 'relative';
input.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX; input.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX;
input.className = 'cordova-camera-select'; input.className = 'cordova-camera-select';
@ -33,11 +33,11 @@ function takePicture (success, error, opts) {
input.name = 'files[]'; input.name = 'files[]';
input.onchange = function (inputEvent) { input.onchange = function (inputEvent) {
var reader = new FileReader(); /* eslint no-undef : 0 */ const reader = new FileReader(); /* eslint no-undef : 0 */
reader.onload = function (readerEvent) { reader.onload = function (readerEvent) {
input.parentNode.removeChild(input); input.parentNode.removeChild(input);
var imageData = readerEvent.target.result; const imageData = readerEvent.target.result;
return success(imageData.substr(imageData.indexOf(',') + 1)); return success(imageData.substr(imageData.indexOf(',') + 1));
}; };
@ -50,16 +50,16 @@ function takePicture (success, error, opts) {
} }
function capture (success, errorCallback, opts) { function capture (success, errorCallback, opts) {
var localMediaStream; let localMediaStream;
var targetWidth = opts[3]; let targetWidth = opts[3];
var targetHeight = opts[4]; let targetHeight = opts[4];
targetWidth = targetWidth === -1 ? 320 : targetWidth; targetWidth = targetWidth === -1 ? 320 : targetWidth;
targetHeight = targetHeight === -1 ? 240 : targetHeight; targetHeight = targetHeight === -1 ? 240 : targetHeight;
var video = document.createElement('video'); const video = document.createElement('video');
var button = document.createElement('button'); const button = document.createElement('button');
var parent = document.createElement('div'); const parent = document.createElement('div');
parent.style.position = 'relative'; parent.style.position = 'relative';
parent.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX; parent.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX;
parent.className = 'cordova-camera-capture'; parent.className = 'cordova-camera-capture';
@ -72,13 +72,13 @@ function capture (success, errorCallback, opts) {
button.onclick = function () { button.onclick = function () {
// create a canvas and capture a frame from video stream // create a canvas and capture a frame from video stream
var canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = targetWidth; canvas.width = targetWidth;
canvas.height = targetHeight; canvas.height = targetHeight;
canvas.getContext('2d').drawImage(video, 0, 0, targetWidth, targetHeight); canvas.getContext('2d').drawImage(video, 0, 0, targetWidth, targetHeight);
// convert image stored in canvas to base64 encoded image // convert image stored in canvas to base64 encoded image
var imageData = canvas.toDataURL('image/png'); let imageData = canvas.toDataURL('image/png');
imageData = imageData.replace('data:image/png;base64,', ''); imageData = imageData.replace('data:image/png;base64,', '');
// stop video stream, remove video and button. // stop video stream, remove video and button.
@ -100,7 +100,7 @@ function capture (success, errorCallback, opts) {
navigator.mozGetUserMedia || navigator.mozGetUserMedia ||
navigator.msGetUserMedia; navigator.msGetUserMedia;
var successCallback = function (stream) { const successCallback = function (stream) {
localMediaStream = stream; localMediaStream = stream;
if ('srcObject' in video) { if ('srcObject' in video) {
video.srcObject = localMediaStream; video.srcObject = localMediaStream;
@ -123,7 +123,7 @@ function capture (success, errorCallback, opts) {
} }
module.exports = { module.exports = {
takePicture: takePicture, takePicture,
cleanup: function () {} cleanup: function () {}
}; };

View File

@ -21,19 +21,19 @@
/* global Windows:true, URL:true, module:true, require:true, WinJS:true */ /* global Windows:true, URL:true, module:true, require:true, WinJS:true */
var Camera = require('./Camera'); const Camera = require('./Camera');
var getAppData = function () { const getAppData = function () {
return Windows.Storage.ApplicationData.current; return Windows.Storage.ApplicationData.current;
}; };
var encodeToBase64String = function (buffer) { const encodeToBase64String = function (buffer) {
return Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer); return Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
}; };
var OptUnique = Windows.Storage.CreationCollisionOption.generateUniqueName; const OptUnique = Windows.Storage.CreationCollisionOption.generateUniqueName;
var CapMSType = Windows.Media.Capture.MediaStreamType; const CapMSType = Windows.Media.Capture.MediaStreamType;
var webUIApp = Windows.UI.WebUI.WebUIApplication; const webUIApp = Windows.UI.WebUI.WebUIApplication;
var fileIO = Windows.Storage.FileIO; const fileIO = Windows.Storage.FileIO;
var pickerLocId = Windows.Storage.Pickers.PickerLocationId; const pickerLocId = Windows.Storage.Pickers.PickerLocationId;
module.exports = { module.exports = {
@ -53,7 +53,7 @@ module.exports = {
// 11 cameraDirection:0 // 11 cameraDirection:0
takePicture: function (successCallback, errorCallback, args) { takePicture: function (successCallback, errorCallback, args) {
var sourceType = args[2]; const sourceType = args[2];
if (sourceType !== Camera.PictureSourceType.CAMERA) { if (sourceType !== Camera.PictureSourceType.CAMERA) {
takePictureFromFile(successCallback, errorCallback, args); takePictureFromFile(successCallback, errorCallback, args);
@ -64,19 +64,19 @@ module.exports = {
}; };
// https://msdn.microsoft.com/en-us/library/windows/apps/ff462087(v=vs.105).aspx // https://msdn.microsoft.com/en-us/library/windows/apps/ff462087(v=vs.105).aspx
var windowsVideoContainers = ['.avi', '.flv', '.asx', '.asf', '.mov', '.mp4', '.mpg', '.rm', '.srt', '.swf', '.wmv', '.vob']; const windowsVideoContainers = ['.avi', '.flv', '.asx', '.asf', '.mov', '.mp4', '.mpg', '.rm', '.srt', '.swf', '.wmv', '.vob'];
var windowsPhoneVideoContainers = ['.avi', '.3gp', '.3g2', '.wmv', '.3gp', '.3g2', '.mp4', '.m4v']; const windowsPhoneVideoContainers = ['.avi', '.3gp', '.3g2', '.wmv', '.3gp', '.3g2', '.mp4', '.m4v'];
// Default aspect ratio 1.78 (16:9 hd video standard) // Default aspect ratio 1.78 (16:9 hd video standard)
var DEFAULT_ASPECT_RATIO = '1.8'; const DEFAULT_ASPECT_RATIO = '1.8';
// Highest possible z-index supported across browsers. Anything used above is converted to this value. // Highest possible z-index supported across browsers. Anything used above is converted to this value.
var HIGHEST_POSSIBLE_Z_INDEX = 2147483647; const HIGHEST_POSSIBLE_Z_INDEX = 2147483647;
// Resize method // Resize method
function resizeImage (successCallback, errorCallback, file, targetWidth, targetHeight, encodingType) { function resizeImage (successCallback, errorCallback, file, targetWidth, targetHeight, encodingType) {
var tempPhotoFileName = ''; let tempPhotoFileName = '';
var targetContentType = ''; let targetContentType = '';
if (encodingType === Camera.EncodingType.PNG) { if (encodingType === Camera.EncodingType.PNG) {
tempPhotoFileName = 'camera_cordova_temp_return.png'; tempPhotoFileName = 'camera_cordova_temp_return.png';
@ -86,36 +86,36 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH
targetContentType = 'image/jpeg'; targetContentType = 'image/jpeg';
} }
var storageFolder = getAppData().localFolder; const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting) file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting)
.then(function (storageFile) { .then(function (storageFile) {
return fileIO.readBufferAsync(storageFile); return fileIO.readBufferAsync(storageFile);
}) })
.then(function (buffer) { .then(function (buffer) {
var strBase64 = encodeToBase64String(buffer); const strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64; const imageData = 'data:' + file.contentType + ';base64,' + strBase64;
var image = new Image(); /* eslint no-undef : 0 */ const image = new Image(); /* eslint no-undef : 0 */
image.src = imageData; image.src = imageData;
image.onload = function () { image.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height); const ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width; const imageWidth = ratio * this.width;
var imageHeight = ratio * this.height; const imageHeight = ratio * this.height;
var canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
var storageFileName; let storageFileName;
canvas.width = imageWidth; canvas.width = imageWidth;
canvas.height = imageHeight; canvas.height = imageHeight;
canvas.getContext('2d').drawImage(this, 0, 0, imageWidth, imageHeight); canvas.getContext('2d').drawImage(this, 0, 0, imageWidth, imageHeight);
var fileContent = canvas.toDataURL(targetContentType).split(',')[1]; const fileContent = canvas.toDataURL(targetContentType).split(',')[1];
var storageFolder = getAppData().localFolder; const storageFolder = getAppData().localFolder;
storageFolder.createFileAsync(tempPhotoFileName, OptUnique) storageFolder.createFileAsync(tempPhotoFileName, OptUnique)
.then(function (storagefile) { .then(function (storagefile) {
var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent); const content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
storageFileName = storagefile.name; storageFileName = storagefile.name;
return fileIO.writeBufferAsync(storagefile, content); return fileIO.writeBufferAsync(storagefile, content);
}) })
@ -132,30 +132,30 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH
// Because of asynchronous method, so let the successCallback be called in it. // Because of asynchronous method, so let the successCallback be called in it.
function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) { function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) {
fileIO.readBufferAsync(file).done(function (buffer) { fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer); const strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64; const imageData = 'data:' + file.contentType + ';base64,' + strBase64;
var image = new Image(); /* eslint no-undef : 0 */ const image = new Image(); /* eslint no-undef : 0 */
image.src = imageData; image.src = imageData;
image.onload = function () { image.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height); const ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width; const imageWidth = ratio * this.width;
var imageHeight = ratio * this.height; const imageHeight = ratio * this.height;
var canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = imageWidth; canvas.width = imageWidth;
canvas.height = imageHeight; canvas.height = imageHeight;
var ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0, imageWidth, imageHeight); ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// The resized file ready for upload // The resized file ready for upload
var finalFile = canvas.toDataURL(file.contentType); const finalFile = canvas.toDataURL(file.contentType);
// Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API. // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
var arr = finalFile.split(','); const arr = finalFile.split(',');
var newStr = finalFile.substr(arr[0].length + 1); const newStr = finalFile.substr(arr[0].length + 1);
successCallback(newStr); successCallback(newStr);
}; };
}, function (err) { errorCallback(err); }); }, function (err) { errorCallback(err); });
@ -171,20 +171,20 @@ function takePictureFromFile (successCallback, errorCallback, args) {
} }
function takePictureFromFileWP (successCallback, errorCallback, args) { function takePictureFromFileWP (successCallback, errorCallback, args) {
var mediaType = args[6]; const mediaType = args[6];
var destinationType = args[1]; const destinationType = args[1];
var targetWidth = args[3]; const targetWidth = args[3];
var targetHeight = args[4]; const targetHeight = args[4];
var encodingType = args[5]; const encodingType = args[5];
/* /*
Need to add and remove an event listener to catch activation state Need to add and remove an event listener to catch activation state
Using FileOpenPicker will suspend the app and it's required to catch the PickSingleFileAndContinue Using FileOpenPicker will suspend the app and it's required to catch the PickSingleFileAndContinue
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
*/ */
var filePickerActivationHandler = function (eventArgs) { const filePickerActivationHandler = function (eventArgs) {
if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickFileContinuation) { if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickFileContinuation) {
var file = eventArgs.files[0]; const file = eventArgs.files[0];
if (!file) { if (!file) {
errorCallback("User didn't choose a file."); errorCallback("User didn't choose a file.");
webUIApp.removeEventListener('activated', filePickerActivationHandler); webUIApp.removeEventListener('activated', filePickerActivationHandler);
@ -194,7 +194,7 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
if (targetHeight > 0 && targetWidth > 0) { if (targetHeight > 0 && targetWidth > 0) {
resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType); resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
} else { } else {
var storageFolder = getAppData().localFolder; const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) { file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
successCallback(URL.createObjectURL(storageFile)); successCallback(URL.createObjectURL(storageFile));
}, function () { }, function () {
@ -206,7 +206,7 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight); resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
} else { } else {
fileIO.readBufferAsync(file).done(function (buffer) { fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer); const strBase64 = encodeToBase64String(buffer);
successCallback(strBase64); successCallback(strBase64);
}, errorCallback); }, errorCallback);
} }
@ -215,7 +215,7 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
} }
}; };
var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker(); const fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
if (mediaType === Camera.MediaType.PICTURE) { if (mediaType === Camera.MediaType.PICTURE) {
fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']); fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']);
fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary; fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary;
@ -232,13 +232,13 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
} }
function takePictureFromFileWindows (successCallback, errorCallback, args) { function takePictureFromFileWindows (successCallback, errorCallback, args) {
var mediaType = args[6]; const mediaType = args[6];
var destinationType = args[1]; const destinationType = args[1];
var targetWidth = args[3]; const targetWidth = args[3];
var targetHeight = args[4]; const targetHeight = args[4];
var encodingType = args[5]; const encodingType = args[5];
var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker(); const fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
if (mediaType === Camera.MediaType.PICTURE) { if (mediaType === Camera.MediaType.PICTURE) {
fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']); fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']);
fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary; fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary;
@ -259,7 +259,7 @@ function takePictureFromFileWindows (successCallback, errorCallback, args) {
if (targetHeight > 0 && targetWidth > 0) { if (targetHeight > 0 && targetWidth > 0) {
resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType); resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
} else { } else {
var storageFolder = getAppData().localFolder; const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) { file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
successCallback(URL.createObjectURL(storageFile)); successCallback(URL.createObjectURL(storageFile));
}, function () { }, function () {
@ -271,7 +271,7 @@ function takePictureFromFileWindows (successCallback, errorCallback, args) {
resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight); resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
} else { } else {
fileIO.readBufferAsync(file).done(function (buffer) { fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer); const strBase64 = encodeToBase64String(buffer);
successCallback(strBase64); successCallback(strBase64);
}, errorCallback); }, errorCallback);
} }
@ -293,23 +293,23 @@ function takePictureFromCamera (successCallback, errorCallback, args) {
function takePictureFromCameraWP (successCallback, errorCallback, args) { function takePictureFromCameraWP (successCallback, errorCallback, args) {
// We are running on WP8.1 which lacks CameraCaptureUI class // We are running on WP8.1 which lacks CameraCaptureUI class
// so we need to use MediaCapture class instead and implement custom UI for camera // so we need to use MediaCapture class instead and implement custom UI for camera
var destinationType = args[1]; const destinationType = args[1];
var targetWidth = args[3]; const targetWidth = args[3];
var targetHeight = args[4]; const targetHeight = args[4];
var encodingType = args[5]; const encodingType = args[5];
var saveToPhotoAlbum = args[9]; const saveToPhotoAlbum = args[9];
var cameraDirection = args[11]; const cameraDirection = args[11];
var capturePreview = null; let capturePreview = null;
var cameraCaptureButton = null; let cameraCaptureButton = null;
var cameraCancelButton = null; let cameraCancelButton = null;
var capture = null; let capture = null;
var captureSettings = null; let captureSettings = null;
var CaptureNS = Windows.Media.Capture; const CaptureNS = Windows.Media.Capture;
var sensor = null; let sensor = null;
function createCameraUI () { function createCameraUI () {
// create style for take and cancel buttons // 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;'; const 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 // Create fullscreen preview
// z-order style element for capturePreview and cameraCancelButton elts // z-order style element for capturePreview and cameraCancelButton elts
@ -343,8 +343,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
function startCameraPreview () { function startCameraPreview () {
// Search for available camera devices // Search for available camera devices
// This is necessary to detect which camera (front or back) we should use // This is necessary to detect which camera (front or back) we should use
var DeviceEnum = Windows.Devices.Enumeration; const DeviceEnum = Windows.Devices.Enumeration;
var expectedPanel = cameraDirection === 1 ? DeviceEnum.Panel.front : DeviceEnum.Panel.back; const expectedPanel = cameraDirection === 1 ? DeviceEnum.Panel.front : DeviceEnum.Panel.back;
// Add focus event handler to capture the event when user suspends the app and comes back while the preview is on // Add focus event handler to capture the event when user suspends the app and comes back while the preview is on
window.addEventListener('focus', continueVideoOnFocus); window.addEventListener('focus', continueVideoOnFocus);
@ -367,8 +367,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
return capture.initializeAsync(captureSettings); return capture.initializeAsync(captureSettings);
}).then(function () { }).then(function () {
// create focus control if available // create focus control if available
var VideoDeviceController = capture.videoDeviceController; const VideoDeviceController = capture.videoDeviceController;
var FocusControl = VideoDeviceController.focusControl; const FocusControl = VideoDeviceController.focusControl;
if (FocusControl.supported === true) { if (FocusControl.supported === true) {
capturePreview.addEventListener('click', function () { capturePreview.addEventListener('click', function () {
@ -378,8 +378,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} else { } else {
this.setAttribute('clicked', '1'); this.setAttribute('clicked', '1');
} }
var preset = Windows.Media.Devices.FocusPreset.autoNormal; const preset = Windows.Media.Devices.FocusPreset.autoNormal;
var parent = this; const parent = this;
FocusControl.setPresetAsync(preset).done(function () { FocusControl.setPresetAsync(preset).done(function () {
// set the clicked attribute back to '0' to allow focus again // set the clicked attribute back to '0' to allow focus again
parent.setAttribute('clicked', '0'); parent.setAttribute('clicked', '0');
@ -410,7 +410,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} }
// Get available aspect ratios // Get available aspect ratios
var aspectRatios = getAspectRatios(capture); const aspectRatios = getAspectRatios(capture);
// Couldn't find a good ratio // Couldn't find a good ratio
if (aspectRatios.length === 0) { if (aspectRatios.length === 0) {
@ -468,9 +468,9 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} }
function captureAction () { function captureAction () {
var encodingProperties; let encodingProperties;
var fileName; let fileName;
var tempFolder = getAppData().temporaryFolder; const tempFolder = getAppData().temporaryFolder;
if (encodingType === Camera.EncodingType.PNG) { if (encodingType === Camera.EncodingType.PNG) {
fileName = 'photo.png'; fileName = 'photo.png';
@ -483,8 +483,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
tempFolder.createFileAsync(fileName, OptUnique) tempFolder.createFileAsync(fileName, OptUnique)
.then(function (tempCapturedFile) { .then(function (tempCapturedFile) {
return new WinJS.Promise(function (complete) { return new WinJS.Promise(function (complete) {
var photoStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); const photoStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
var finalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); const finalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
capture.capturePhotoToStreamAsync(encodingProperties, photoStream) capture.capturePhotoToStreamAsync(encodingProperties, photoStream)
.then(function () { .then(function () {
return Windows.Graphics.Imaging.BitmapDecoder.createAsync(photoStream); return Windows.Graphics.Imaging.BitmapDecoder.createAsync(photoStream);
@ -518,11 +518,11 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
.done(function (capturedFile) { .done(function (capturedFile) {
destroyCameraPreview(); destroyCameraPreview();
savePhoto(capturedFile, { savePhoto(capturedFile, {
destinationType: destinationType, destinationType,
targetHeight: targetHeight, targetHeight,
targetWidth: targetWidth, targetWidth,
encodingType: encodingType, encodingType,
saveToPhotoAlbum: saveToPhotoAlbum saveToPhotoAlbum
}, successCallback, errorCallback); }, successCallback, errorCallback);
}, function (err) { }, function (err) {
destroyCameraPreview(); destroyCameraPreview();
@ -531,22 +531,22 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} }
function getAspectRatios (capture) { function getAspectRatios (capture) {
var videoDeviceController = capture.videoDeviceController; const videoDeviceController = capture.videoDeviceController;
var photoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo).map(function (element) { const photoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo).map(function (element) {
return (element.width / element.height).toFixed(1); return (element.width / element.height).toFixed(1);
}).filter(function (element, index, array) { return (index === array.indexOf(element)); }); }).filter(function (element, index, array) { return (index === array.indexOf(element)); });
var videoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord).map(function (element) { const videoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord).map(function (element) {
return (element.width / element.height).toFixed(1); return (element.width / element.height).toFixed(1);
}).filter(function (element, index, array) { return (index === array.indexOf(element)); }); }).filter(function (element, index, array) { return (index === array.indexOf(element)); });
var videoPreviewAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview).map(function (element) { const videoPreviewAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview).map(function (element) {
return (element.width / element.height).toFixed(1); return (element.width / element.height).toFixed(1);
}).filter(function (element, index, array) { return (index === array.indexOf(element)); }); }).filter(function (element, index, array) { return (index === array.indexOf(element)); });
var allAspectRatios = [].concat(photoAspectRatios, videoAspectRatios, videoPreviewAspectRatios); const allAspectRatios = [].concat(photoAspectRatios, videoAspectRatios, videoPreviewAspectRatios);
var aspectObj = allAspectRatios.reduce(function (map, item) { const aspectObj = allAspectRatios.reduce(function (map, item) {
if (!map[item]) { if (!map[item]) {
map[item] = 0; map[item] = 0;
} }
@ -561,8 +561,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
function setAspectRatio (capture, aspect) { function setAspectRatio (capture, aspect) {
// Max photo resolution with desired aspect ratio // Max photo resolution with desired aspect ratio
var videoDeviceController = capture.videoDeviceController; const videoDeviceController = capture.videoDeviceController;
var photoResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo) const photoResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo)
.filter(function (elem) { .filter(function (elem) {
return ((elem.width / elem.height).toFixed(1) === aspect); return ((elem.width / elem.height).toFixed(1) === aspect);
}) })
@ -571,7 +571,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}); });
// Max video resolution with desired aspect ratio // Max video resolution with desired aspect ratio
var videoRecordResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord) const videoRecordResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord)
.filter(function (elem) { .filter(function (elem) {
return ((elem.width / elem.height).toFixed(1) === aspect); return ((elem.width / elem.height).toFixed(1) === aspect);
}) })
@ -580,7 +580,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}); });
// Max video preview resolution with desired aspect ratio // Max video preview resolution with desired aspect ratio
var videoPreviewResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview) const videoPreviewResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview)
.filter(function (elem) { .filter(function (elem) {
return ((elem.width / elem.height).toFixed(1) === aspect); return ((elem.width / elem.height).toFixed(1) === aspect);
}) })
@ -681,14 +681,14 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} }
function takePictureFromCameraWindows (successCallback, errorCallback, args) { function takePictureFromCameraWindows (successCallback, errorCallback, args) {
var destinationType = args[1]; const destinationType = args[1];
var targetWidth = args[3]; const targetWidth = args[3];
var targetHeight = args[4]; const targetHeight = args[4];
var encodingType = args[5]; const encodingType = args[5];
var allowCrop = !!args[7]; const allowCrop = !!args[7];
var saveToPhotoAlbum = args[9]; const saveToPhotoAlbum = args[9];
var WMCapture = Windows.Media.Capture; const WMCapture = Windows.Media.Capture;
var cameraCaptureUI = new WMCapture.CameraCaptureUI(); const cameraCaptureUI = new WMCapture.CameraCaptureUI();
cameraCaptureUI.photoSettings.allowCropping = allowCrop; cameraCaptureUI.photoSettings.allowCropping = allowCrop;
@ -699,9 +699,9 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
} }
// decide which max pixels should be supported by targetWidth or targetHeight. // decide which max pixels should be supported by targetWidth or targetHeight.
var maxRes = null; let maxRes = null;
var UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution; const UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution;
var totalPixels = targetWidth * targetHeight; const totalPixels = targetWidth * targetHeight;
if (targetWidth === -1 && targetHeight === -1) { if (targetWidth === -1 && targetHeight === -1) {
maxRes = UIMaxRes.highestAvailable; maxRes = UIMaxRes.highestAvailable;
@ -723,18 +723,18 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
cameraCaptureUI.photoSettings.maxResolution = maxRes; cameraCaptureUI.photoSettings.maxResolution = maxRes;
var cameraPicture; let cameraPicture;
// define focus handler for windows phone 10.0 // define focus handler for windows phone 10.0
var savePhotoOnFocus = function () { const savePhotoOnFocus = function () {
window.removeEventListener('focus', savePhotoOnFocus); window.removeEventListener('focus', savePhotoOnFocus);
// call only when the app is in focus again // call only when the app is in focus again
savePhoto(cameraPicture, { savePhoto(cameraPicture, {
destinationType: destinationType, destinationType,
targetHeight: targetHeight, targetHeight,
targetWidth: targetWidth, targetWidth,
encodingType: encodingType, encodingType,
saveToPhotoAlbum: saveToPhotoAlbum saveToPhotoAlbum
}, successCallback, errorCallback); }, successCallback, errorCallback);
}; };
@ -755,11 +755,11 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
// If not windows 10, call savePhoto() now. If windows 10, wait for the app to be in focus again // If not windows 10, call savePhoto() now. If windows 10, wait for the app to be in focus again
if (navigator.appVersion.indexOf('Windows Phone 10.0') < 0) { if (navigator.appVersion.indexOf('Windows Phone 10.0') < 0) {
savePhoto(cameraPicture, { savePhoto(cameraPicture, {
destinationType: destinationType, destinationType,
targetHeight: targetHeight, targetHeight,
targetWidth: targetWidth, targetWidth,
encodingType: encodingType, encodingType,
saveToPhotoAlbum: saveToPhotoAlbum saveToPhotoAlbum
}, successCallback, errorCallback); }, successCallback, errorCallback);
} }
}, function () { }, function () {
@ -770,7 +770,7 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
function savePhoto (picture, options, successCallback, errorCallback) { function savePhoto (picture, options, successCallback, errorCallback) {
// success callback for capture operation // success callback for capture operation
var success = function (picture) { const success = function (picture) {
if (options.destinationType === Camera.DestinationType.FILE_URI) { if (options.destinationType === Camera.DestinationType.FILE_URI) {
if (options.targetHeight > 0 && options.targetWidth > 0) { if (options.targetHeight > 0 && options.targetWidth > 0) {
resizeImage(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight, options.encodingType); resizeImage(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight, options.encodingType);
@ -789,7 +789,7 @@ function savePhoto (picture, options, successCallback, errorCallback) {
resizeImageBase64(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight); resizeImageBase64(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight);
} else { } else {
fileIO.readBufferAsync(picture).done(function (buffer) { fileIO.readBufferAsync(picture).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer); const strBase64 = encodeToBase64String(buffer);
picture.deleteAsync().done(function () { picture.deleteAsync().done(function () {
successCallback(strBase64); successCallback(strBase64);
}, function (err) { }, function (err) {
@ -803,8 +803,8 @@ function savePhoto (picture, options, successCallback, errorCallback) {
if (!options.saveToPhotoAlbum) { if (!options.saveToPhotoAlbum) {
success(picture); success(picture);
} else { } else {
var savePicker = new Windows.Storage.Pickers.FileSavePicker(); const savePicker = new Windows.Storage.Pickers.FileSavePicker();
var saveFile = function (file) { const saveFile = function (file) {
if (file) { if (file) {
// Prevent updates to the remote version of the file until we're done // Prevent updates to the remote version of the file until we're done
Windows.Storage.CachedFileManager.deferUpdates(file); Windows.Storage.CachedFileManager.deferUpdates(file);
@ -842,9 +842,9 @@ function savePhoto (picture, options, successCallback, errorCallback) {
Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation Using FileSavePicker will suspend the app and it's required to catch the pickSaveFileContinuation
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx
*/ */
var fileSaveHandler = function (eventArgs) { const fileSaveHandler = function (eventArgs) {
if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) { if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.pickSaveFileContinuation) {
var file = eventArgs.file; const file = eventArgs.file;
saveFile(file); saveFile(file);
webUIApp.removeEventListener('activated', fileSaveHandler); webUIApp.removeEventListener('activated', fileSaveHandler);
} }

View File

@ -78,20 +78,20 @@ exports.defineAutoTests = function () {
/******************************************************************************/ /******************************************************************************/
exports.defineManualTests = function (contentEl, createActionButton) { exports.defineManualTests = function (contentEl, createActionButton) {
var pictureUrl = null; let pictureUrl = null;
var fileObj = null; let fileObj = null;
var fileEntry = null; let fileEntry = null;
var pageStartTime = +new Date(); const pageStartTime = +new Date();
// default camera options // default camera options
var camQualityDefault = ['50', 50]; const camQualityDefault = ['50', 50];
var camDestinationTypeDefault = ['FILE_URI', 1]; const camDestinationTypeDefault = ['FILE_URI', 1];
var camPictureSourceTypeDefault = ['CAMERA', 1]; const camPictureSourceTypeDefault = ['CAMERA', 1];
var camAllowEditDefault = ['allowEdit', false]; const camAllowEditDefault = ['allowEdit', false];
var camEncodingTypeDefault = ['JPEG', 0]; const camEncodingTypeDefault = ['JPEG', 0];
var camMediaTypeDefault = ['mediaType', 0]; const camMediaTypeDefault = ['mediaType', 0];
var camCorrectOrientationDefault = ['correctOrientation', false]; const camCorrectOrientationDefault = ['correctOrientation', false];
var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true]; const camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
function log (value) { function log (value) {
console.log(value); console.log(value);
@ -101,7 +101,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
function clearStatus () { function clearStatus () {
document.getElementById('camera_status').innerHTML = ''; document.getElementById('camera_status').innerHTML = '';
document.getElementById('camera_image').src = 'about:blank'; document.getElementById('camera_image').src = 'about:blank';
var canvas = document.getElementById('canvas'); const canvas = document.getElementById('canvas');
canvas.width = canvas.height = 1; canvas.width = canvas.height = 1;
pictureUrl = null; pictureUrl = null;
fileObj = null; fileObj = null;
@ -119,8 +119,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
log('URL: "' + url.slice(0, 90) + '"'); log('URL: "' + url.slice(0, 90) + '"');
pictureUrl = url; pictureUrl = url;
var img = document.getElementById('camera_image'); const img = document.getElementById('camera_image');
var startTime = new Date(); const startTime = new Date();
img.src = url; img.src = url;
img.onload = function () { img.onload = function () {
log('Img size: ' + img.naturalWidth + 'x' + img.naturalHeight); log('Img size: ' + img.naturalWidth + 'x' + img.naturalHeight);
@ -147,20 +147,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} else if (pictureUrl.indexOf('data:image/jpeg;base64') === 0) { } else if (pictureUrl.indexOf('data:image/jpeg;base64') === 0) {
// do nothing // do nothing
} else { } else {
var path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' '); const path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' ');
fileEntry = new FileEntry('image_name.png', path); fileEntry = new FileEntry('image_name.png', path);
} }
} }
function getPicture () { function getPicture () {
clearStatus(); clearStatus();
var options = extractOptions(); const options = extractOptions();
log('Getting picture with options: ' + JSON.stringify(options)); log('Getting picture with options: ' + JSON.stringify(options));
var popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options); const popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options);
// Reposition the popover if the orientation changes. // Reposition the popover if the orientation changes.
window.onorientationchange = function () { window.onorientationchange = function () {
var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0, 300, 400); const newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0, 300, 400);
popoverHandle.setPosition(newPopoverOptions); popoverHandle.setPosition(newPopoverOptions);
}; };
} }
@ -177,7 +177,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
*/ */
function readFile () { function readFile () {
function onFileReadAsDataURL (evt) { function onFileReadAsDataURL (evt) {
var img = document.getElementById('camera_image'); const img = document.getElementById('camera_image');
img.style.visibility = 'visible'; img.style.visibility = 'visible';
img.style.display = 'block'; img.style.display = 'block';
img.src = evt.target.result; img.src = evt.target.result;
@ -188,7 +188,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
log('Got file: ' + JSON.stringify(file)); log('Got file: ' + JSON.stringify(file));
fileObj = file; fileObj = file;
/* eslint-disable no-undef */ /* eslint-disable no-undef */
var reader = new FileReader(); const reader = new FileReader();
/* eslint-enable no-undef */ /* eslint-enable no-undef */
reader.onload = function () { reader.onload = function () {
log('FileReader.readAsDataURL() - length = ' + reader.result.length); log('FileReader.readAsDataURL() - length = ' + reader.result.length);
@ -219,9 +219,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
* This calls FileEntry.copyTo and FileEntry.moveTo. * This calls FileEntry.copyTo and FileEntry.moveTo.
*/ */
function copyImage () { function copyImage () {
var onFileSystemReceived = function (fileSystem) { const onFileSystemReceived = function (fileSystem) {
var destDirEntry = fileSystem.root; const destDirEntry = fileSystem.root;
var origName = fileEntry.name; const origName = fileEntry.name;
// Test FileEntry API here. // Test FileEntry API here.
fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false)); fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false));
@ -253,13 +253,13 @@ exports.defineManualTests = function (contentEl, createActionButton) {
* This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate. * This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate.
*/ */
function writeImage () { function writeImage () {
var onFileWriterReceived = function (fileWriter) { const onFileWriterReceived = function (fileWriter) {
fileWriter.onwrite = logCallback('FileWriter.write', true); fileWriter.onwrite = logCallback('FileWriter.write', true);
fileWriter.onerror = logCallback('FileWriter.write', false); fileWriter.onerror = logCallback('FileWriter.write', false);
fileWriter.write('some text!'); fileWriter.write('some text!');
}; };
var onFileTruncateWriterReceived = function (fileWriter) { const onFileTruncateWriterReceived = function (fileWriter) {
fileWriter.onwrite = logCallback('FileWriter.truncate', true); fileWriter.onwrite = logCallback('FileWriter.truncate', true);
fileWriter.onerror = logCallback('FileWriter.truncate', false); fileWriter.onerror = logCallback('FileWriter.truncate', false);
fileWriter.truncate(10); fileWriter.truncate(10);
@ -270,15 +270,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} }
function displayImageUsingCanvas () { function displayImageUsingCanvas () {
var canvas = document.getElementById('canvas'); const canvas = document.getElementById('canvas');
var img = document.getElementById('camera_image'); const img = document.getElementById('camera_image');
var w = img.width; let w = img.width;
var h = img.height; let h = img.height;
h = 100 / w * h; h = 100 / w * h;
w = 100; w = 100;
canvas.width = w; canvas.width = w;
canvas.height = h; canvas.height = h;
var context = canvas.getContext('2d'); const context = canvas.getContext('2d');
context.drawImage(img, 0, 0, w, h); context.drawImage(img, 0, 0, w, h);
} }
@ -311,9 +311,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
return; return;
} }
/* eslint-enable no-undef */ /* eslint-enable no-undef */
var URLApi = window.URL || window.webkitURL; const URLApi = window.URL || window.webkitURL;
if (URLApi) { if (URLApi) {
var blobURL = URLApi.createObjectURL(fileObj); const blobURL = URLApi.createObjectURL(fileObj);
if (blobURL) { if (blobURL) {
setPicture(blobURL, function () { setPicture(blobURL, function () {
URLApi.revokeObjectURL(blobURL); URLApi.revokeObjectURL(blobURL);
@ -327,11 +327,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} }
function extractOptions () { function extractOptions () {
var els = document.querySelectorAll('#image-options select'); const els = document.querySelectorAll('#image-options select');
var ret = {}; const ret = {};
/* eslint-disable no-cond-assign */ /* eslint-disable no-cond-assign */
for (var i = 0, el; el = els[i]; ++i) { for (let i = 0, el; el = els[i]; ++i) {
var value = el.value; let value = el.value;
if (value === '') continue; if (value === '') continue;
value = +value; value = +value;
@ -346,20 +346,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} }
function createOptionsEl (name, values, selectionDefault) { function createOptionsEl (name, values, selectionDefault) {
var openDiv = '<div style="display: inline-block">' + name + ': '; const openDiv = '<div style="display: inline-block">' + name + ': ';
var select = '<select name=' + name + ' id="' + name + '">'; const select = '<select name=' + name + ' id="' + name + '">';
var defaultOption = ''; let defaultOption = '';
if (selectionDefault === undefined) { if (selectionDefault === undefined) {
defaultOption = '<option value="">default</option>'; defaultOption = '<option value="">default</option>';
} }
var options = ''; let options = '';
if (typeof values === 'boolean') { if (typeof values === 'boolean') {
values = { true: 1, false: 0 }; values = { true: 1, false: 0 };
} }
for (var k in values) { for (const k in values) {
var isSelected = ''; let isSelected = '';
if (selectionDefault) { if (selectionDefault) {
if (selectionDefault[0] === k) { if (selectionDefault[0] === k) {
isSelected = 'selected'; isSelected = 'selected';
@ -368,20 +368,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
options += '<option value="' + values[k] + '" ' + isSelected + '>' + k + '</option>'; options += '<option value="' + values[k] + '" ' + isSelected + '>' + k + '</option>';
} }
var closeDiv = '</select></div>'; const closeDiv = '</select></div>';
return openDiv + select + defaultOption + options + closeDiv; return openDiv + select + defaultOption + options + closeDiv;
} }
/******************************************************************************/ /******************************************************************************/
var info_div = '<h1>Camera</h1>' + const info_div = '<h1>Camera</h1>' +
'<div id="info">' + '<div id="info">' +
'<b>Status:</b> <div id="camera_status"></div>' + '<b>Status:</b> <div id="camera_status"></div>' +
'img: <img width="100" id="camera_image">' + 'img: <img width="100" id="camera_image">' +
'canvas: <canvas id="canvas" width="1" height="1"></canvas>' + 'canvas: <canvas id="canvas" width="1" height="1"></canvas>' +
'</div>'; '</div>';
var options_div = '<h2>Cordova Camera API Options</h2>' + const options_div = '<h2>Cordova Camera API Options</h2>' +
'<div id="image-options">' + '<div id="image-options">' +
createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault) + createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault) +
createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault) + createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault) +
@ -395,8 +395,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault) + createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault) +
createOptionsEl('cameraDirection', Camera.Direction) + createOptionsEl('cameraDirection', Camera.Direction) +
'</div>'; '</div>';
var getpicture_div = '<div id="getpicture"></div>'; const getpicture_div = '<div id="getpicture"></div>';
var test_procedure = '<h4>Recommended Test Procedure</h4>' + const test_procedure = '<h4>Recommended Test Procedure</h4>' +
'Options not specified should be the default value' + 'Options not specified should be the default value' +
'<br>Status box should update with image and info whenever an image is taken or selected from library' + '<br>Status box should update with image and info whenever an image is taken or selected from library' +
'</p><div style="background:#B0C4DE;border:1px solid #FFA07A;margin:15px 6px 0px;min-width:295px;max-width:97%;padding:4px 0px 2px 10px;min-height:160px;max-height:200px;overflow:auto">' + '</p><div style="background:#B0C4DE;border:1px solid #FFA07A;margin:15px 6px 0px;min-width:295px;max-width:97%;padding:4px 0px 2px 10px;min-height:160px;max-height:200px;overflow:auto">' +
@ -410,13 +410,13 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'</p><li>sourceType=CAMERA<br>targetWidth & targetHeight=50<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with width and height=800. Size should be significantly larger.</li>' + '</p><li>sourceType=CAMERA<br>targetWidth & targetHeight=50<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with width and height=800. Size should be significantly larger.</li>' +
'</p><li>quality=0<br>targetWidth & targetHeight=default<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with quality=80. Size should be significantly larger.</li>' + '</p><li>quality=0<br>targetWidth & targetHeight=default<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with quality=80. Size should be significantly larger.</li>' +
'</ol></div>'; '</ol></div>';
var inputs_div = '<h2>Native File Inputs</h2>' + const inputs_div = '<h2>Native File Inputs</h2>' +
'For the following tests, status box should update with file selected' + 'For the following tests, status box should update with file selected' +
'</p><div>input type=file <input type="file" class="testInputTag"></div>' + '</p><div>input type=file <input type="file" class="testInputTag"></div>' +
'<div>capture=camera <input type="file" accept="image/*;capture=camera" class="testInputTag"></div>' + '<div>capture=camera <input type="file" accept="image/*;capture=camera" class="testInputTag"></div>' +
'<div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" class="testInputTag"></div>' + '<div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" class="testInputTag"></div>' +
'<div>capture=microphone <input type="file" accept="audio/*;capture=microphone" class="testInputTag"></div>'; '<div>capture=microphone <input type="file" accept="audio/*;capture=microphone" class="testInputTag"></div>';
var actions_div = '<h2>Actions</h2>' + const actions_div = '<h2>Actions</h2>' +
'For the following tests, ensure that an image is set in status box' + 'For the following tests, ensure that an image is set in status box' +
'</p><div id="metadata"></div>' + '</p><div id="metadata"></div>' +
'Expected result: Get metadata about file selected.<br>Status box will show, along with the metadata, "Call to FileEntry.getMetadata success, Call to FileEntry.setMetadata success, Call to FileEntry.getParent success"' + 'Expected result: Get metadata about file selected.<br>Status box will show, along with the metadata, "Call to FileEntry.getMetadata success, Call to FileEntry.setMetadata success, Call to FileEntry.getParent success"' +
@ -443,12 +443,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
contentEl.innerHTML = info_div + options_div + getpicture_div + test_procedure + inputs_div + actions_div; contentEl.innerHTML = info_div + options_div + getpicture_div + test_procedure + inputs_div + actions_div;
} }
var elements = document.getElementsByClassName('testInputTag'); const elements = document.getElementsByClassName('testInputTag');
var listener = function (e) { const listener = function (e) {
testInputTag(e.target); testInputTag(e.target);
}; };
for (var i = 0; i < elements.length; ++i) { for (let i = 0; i < elements.length; ++i) {
var item = elements[i]; const item = elements[i];
item.addEventListener('change', listener, false); item.addEventListener('change', listener, false);
} }

View File

@ -19,9 +19,9 @@
* *
*/ */
var argscheck = require('cordova/argscheck'); const argscheck = require('cordova/argscheck');
var exec = require('cordova/exec'); const exec = require('cordova/exec');
var Camera = require('./Camera'); const Camera = require('./Camera');
// XXX: commented out // XXX: commented out
// CameraPopoverHandle = require('./CameraPopoverHandle'); // CameraPopoverHandle = require('./CameraPopoverHandle');
@ -32,10 +32,10 @@ var Camera = require('./Camera');
/** /**
* @exports camera * @exports camera
*/ */
var cameraExport = {}; const cameraExport = {};
// Tack on the Camera Constants to the base camera plugin. // Tack on the Camera Constants to the base camera plugin.
for (var key in Camera) { for (const key in Camera) {
cameraExport[key] = Camera[key]; cameraExport[key] = Camera[key];
} }
@ -134,22 +134,22 @@ for (var key in Camera) {
cameraExport.getPicture = function (successCallback, errorCallback, options) { cameraExport.getPicture = function (successCallback, errorCallback, options) {
argscheck.checkArgs('fFO', 'Camera.getPicture', arguments); argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);
options = options || {}; options = options || {};
var getValue = argscheck.getValue; const getValue = argscheck.getValue;
var quality = getValue(options.quality, 50); const quality = getValue(options.quality, 50);
var destinationType = getValue(options.destinationType, Camera.DestinationType.FILE_URI); const destinationType = getValue(options.destinationType, Camera.DestinationType.FILE_URI);
var sourceType = getValue(options.sourceType, Camera.PictureSourceType.CAMERA); const sourceType = getValue(options.sourceType, Camera.PictureSourceType.CAMERA);
var targetWidth = getValue(options.targetWidth, -1); const targetWidth = getValue(options.targetWidth, -1);
var targetHeight = getValue(options.targetHeight, -1); const targetHeight = getValue(options.targetHeight, -1);
var encodingType = getValue(options.encodingType, Camera.EncodingType.JPEG); const encodingType = getValue(options.encodingType, Camera.EncodingType.JPEG);
var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE); const mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE);
var allowEdit = !!options.allowEdit; const allowEdit = !!options.allowEdit;
var correctOrientation = !!options.correctOrientation; const correctOrientation = !!options.correctOrientation;
var saveToPhotoAlbum = !!options.saveToPhotoAlbum; const saveToPhotoAlbum = !!options.saveToPhotoAlbum;
var popoverOptions = getValue(options.popoverOptions, null); const popoverOptions = getValue(options.popoverOptions, null);
var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK); const cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK);
var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, const args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection]; mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection];
exec(successCallback, errorCallback, 'Camera', 'takePicture', args); exec(successCallback, errorCallback, 'Camera', 'takePicture', args);

View File

@ -23,7 +23,7 @@
* @ignore in favour of iOS' one * @ignore in favour of iOS' one
* A handle to an image picker popover. * A handle to an image picker popover.
*/ */
var CameraPopoverHandle = function () { const CameraPopoverHandle = function () {
this.setPosition = function (popoverOptions) { this.setPosition = function (popoverOptions) {
console.log('CameraPopoverHandle.setPosition is only supported on iOS.'); console.log('CameraPopoverHandle.setPosition is only supported on iOS.');
}; };

View File

@ -19,7 +19,7 @@
* *
*/ */
var Camera = require('./Camera'); const Camera = require('./Camera');
/** /**
* @namespace navigator * @namespace navigator
@ -42,7 +42,7 @@ var Camera = require('./Camera');
* @param {Number} [popoverWidth=0] - width of the popover (0 or not specified will use apple's default width). * @param {Number} [popoverWidth=0] - width of the popover (0 or not specified will use apple's default width).
* @param {Number} [popoverHeight=0] - height of the popover (0 or not specified will use apple's default height). * @param {Number} [popoverHeight=0] - height of the popover (0 or not specified will use apple's default height).
*/ */
var CameraPopoverOptions = function (x, y, width, height, arrowDir, popoverWidth, popoverHeight) { const CameraPopoverOptions = function (x, y, width, height, arrowDir, popoverWidth, popoverHeight) {
// information of rectangle that popover should be anchored to // information of rectangle that popover should be anchored to
this.x = x || 0; this.x = x || 0;
this.y = y || 32; this.y = y || 32;

View File

@ -19,7 +19,7 @@
* *
*/ */
var exec = require('cordova/exec'); const exec = require('cordova/exec');
/** /**
* @namespace navigator * @namespace navigator
@ -48,7 +48,7 @@ var exec = require('cordova/exec');
* } * }
* @module CameraPopoverHandle * @module CameraPopoverHandle
*/ */
var CameraPopoverHandle = function () { const CameraPopoverHandle = function () {
/** /**
* Can be used to reposition the image selection dialog, * Can be used to reposition the image selection dialog,
* for example, when the device orientation changes. * for example, when the device orientation changes.
@ -58,7 +58,7 @@ var CameraPopoverHandle = function () {
* @param {module:CameraPopoverOptions} popoverOptions * @param {module:CameraPopoverOptions} popoverOptions
*/ */
this.setPosition = function (popoverOptions) { this.setPosition = function (popoverOptions) {
var args = [popoverOptions]; const args = [popoverOptions];
exec(null, null, 'Camera', 'repositionPopover', args); exec(null, null, 'Camera', 'repositionPopover', args);
}; };
}; };