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

3682
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -21,19 +21,19 @@
/* 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;
};
var encodeToBase64String = function (buffer) {
const encodeToBase64String = function (buffer) {
return Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
};
var OptUnique = Windows.Storage.CreationCollisionOption.generateUniqueName;
var CapMSType = Windows.Media.Capture.MediaStreamType;
var webUIApp = Windows.UI.WebUI.WebUIApplication;
var fileIO = Windows.Storage.FileIO;
var pickerLocId = Windows.Storage.Pickers.PickerLocationId;
const OptUnique = Windows.Storage.CreationCollisionOption.generateUniqueName;
const CapMSType = Windows.Media.Capture.MediaStreamType;
const webUIApp = Windows.UI.WebUI.WebUIApplication;
const fileIO = Windows.Storage.FileIO;
const pickerLocId = Windows.Storage.Pickers.PickerLocationId;
module.exports = {
@ -53,7 +53,7 @@ module.exports = {
// 11 cameraDirection:0
takePicture: function (successCallback, errorCallback, args) {
var sourceType = args[2];
const sourceType = args[2];
if (sourceType !== Camera.PictureSourceType.CAMERA) {
takePictureFromFile(successCallback, errorCallback, args);
@ -64,19 +64,19 @@ module.exports = {
};
// 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'];
var windowsPhoneVideoContainers = ['.avi', '.3gp', '.3g2', '.wmv', '.3gp', '.3g2', '.mp4', '.m4v'];
const windowsVideoContainers = ['.avi', '.flv', '.asx', '.asf', '.mov', '.mp4', '.mpg', '.rm', '.srt', '.swf', '.wmv', '.vob'];
const windowsPhoneVideoContainers = ['.avi', '.3gp', '.3g2', '.wmv', '.3gp', '.3g2', '.mp4', '.m4v'];
// 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.
var HIGHEST_POSSIBLE_Z_INDEX = 2147483647;
const HIGHEST_POSSIBLE_Z_INDEX = 2147483647;
// Resize method
function resizeImage (successCallback, errorCallback, file, targetWidth, targetHeight, encodingType) {
var tempPhotoFileName = '';
var targetContentType = '';
let tempPhotoFileName = '';
let targetContentType = '';
if (encodingType === Camera.EncodingType.PNG) {
tempPhotoFileName = 'camera_cordova_temp_return.png';
@ -86,36 +86,36 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH
targetContentType = 'image/jpeg';
}
var storageFolder = getAppData().localFolder;
const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting)
.then(function (storageFile) {
return fileIO.readBufferAsync(storageFile);
})
.then(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64;
var image = new Image(); /* eslint no-undef : 0 */
const strBase64 = encodeToBase64String(buffer);
const imageData = 'data:' + file.contentType + ';base64,' + strBase64;
const image = new Image(); /* eslint no-undef : 0 */
image.src = imageData;
image.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
const ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
const imageWidth = ratio * this.width;
const imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
var storageFileName;
const canvas = document.createElement('canvas');
let storageFileName;
canvas.width = imageWidth;
canvas.height = 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)
.then(function (storagefile) {
var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
const content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
storageFileName = storagefile.name;
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.
function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) {
fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64;
const strBase64 = encodeToBase64String(buffer);
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.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
const ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
const imageWidth = ratio * this.width;
const imageHeight = ratio * this.height;
const canvas = document.createElement('canvas');
canvas.width = imageWidth;
canvas.height = imageHeight;
var ctx = canvas.getContext('2d');
const ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// 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.
var arr = finalFile.split(',');
var newStr = finalFile.substr(arr[0].length + 1);
const arr = finalFile.split(',');
const newStr = finalFile.substr(arr[0].length + 1);
successCallback(newStr);
};
}, function (err) { errorCallback(err); });
@ -171,20 +171,20 @@ function takePictureFromFile (successCallback, errorCallback, args) {
}
function takePictureFromFileWP (successCallback, errorCallback, args) {
var mediaType = args[6];
var destinationType = args[1];
var targetWidth = args[3];
var targetHeight = args[4];
var encodingType = args[5];
const mediaType = args[6];
const destinationType = args[1];
const targetWidth = args[3];
const targetHeight = args[4];
const encodingType = args[5];
/*
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
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) {
var file = eventArgs.files[0];
const file = eventArgs.files[0];
if (!file) {
errorCallback("User didn't choose a file.");
webUIApp.removeEventListener('activated', filePickerActivationHandler);
@ -194,7 +194,7 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
if (targetHeight > 0 && targetWidth > 0) {
resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
} else {
var storageFolder = getAppData().localFolder;
const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
successCallback(URL.createObjectURL(storageFile));
}, function () {
@ -206,7 +206,7 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
} else {
fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
const strBase64 = encodeToBase64String(buffer);
successCallback(strBase64);
}, 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) {
fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']);
fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary;
@ -232,13 +232,13 @@ function takePictureFromFileWP (successCallback, errorCallback, args) {
}
function takePictureFromFileWindows (successCallback, errorCallback, args) {
var mediaType = args[6];
var destinationType = args[1];
var targetWidth = args[3];
var targetHeight = args[4];
var encodingType = args[5];
const mediaType = args[6];
const destinationType = args[1];
const targetWidth = args[3];
const targetHeight = args[4];
const encodingType = args[5];
var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
const fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
if (mediaType === Camera.MediaType.PICTURE) {
fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']);
fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary;
@ -259,7 +259,7 @@ function takePictureFromFileWindows (successCallback, errorCallback, args) {
if (targetHeight > 0 && targetWidth > 0) {
resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType);
} else {
var storageFolder = getAppData().localFolder;
const storageFolder = getAppData().localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) {
successCallback(URL.createObjectURL(storageFile));
}, function () {
@ -271,7 +271,7 @@ function takePictureFromFileWindows (successCallback, errorCallback, args) {
resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight);
} else {
fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
const strBase64 = encodeToBase64String(buffer);
successCallback(strBase64);
}, errorCallback);
}
@ -293,23 +293,23 @@ function takePictureFromCamera (successCallback, errorCallback, args) {
function takePictureFromCameraWP (successCallback, errorCallback, args) {
// We are running on WP8.1 which lacks CameraCaptureUI class
// so we need to use MediaCapture class instead and implement custom UI for camera
var destinationType = args[1];
var targetWidth = args[3];
var targetHeight = args[4];
var encodingType = args[5];
var saveToPhotoAlbum = args[9];
var cameraDirection = args[11];
var capturePreview = null;
var cameraCaptureButton = null;
var cameraCancelButton = null;
var capture = null;
var captureSettings = null;
var CaptureNS = Windows.Media.Capture;
var sensor = null;
const destinationType = args[1];
const targetWidth = args[3];
const targetHeight = args[4];
const encodingType = args[5];
const saveToPhotoAlbum = args[9];
const cameraDirection = args[11];
let capturePreview = null;
let cameraCaptureButton = null;
let cameraCancelButton = null;
let capture = null;
let captureSettings = null;
const CaptureNS = Windows.Media.Capture;
let sensor = null;
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;';
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
// z-order style element for capturePreview and cameraCancelButton elts
@ -343,8 +343,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
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;
var expectedPanel = cameraDirection === 1 ? DeviceEnum.Panel.front : DeviceEnum.Panel.back;
const DeviceEnum = Windows.Devices.Enumeration;
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
window.addEventListener('focus', continueVideoOnFocus);
@ -367,8 +367,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
return capture.initializeAsync(captureSettings);
}).then(function () {
// create focus control if available
var VideoDeviceController = capture.videoDeviceController;
var FocusControl = VideoDeviceController.focusControl;
const VideoDeviceController = capture.videoDeviceController;
const FocusControl = VideoDeviceController.focusControl;
if (FocusControl.supported === true) {
capturePreview.addEventListener('click', function () {
@ -378,8 +378,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
} else {
this.setAttribute('clicked', '1');
}
var preset = Windows.Media.Devices.FocusPreset.autoNormal;
var parent = this;
const preset = Windows.Media.Devices.FocusPreset.autoNormal;
const parent = this;
FocusControl.setPresetAsync(preset).done(function () {
// set the clicked attribute back to '0' to allow focus again
parent.setAttribute('clicked', '0');
@ -410,7 +410,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}
// Get available aspect ratios
var aspectRatios = getAspectRatios(capture);
const aspectRatios = getAspectRatios(capture);
// Couldn't find a good ratio
if (aspectRatios.length === 0) {
@ -468,9 +468,9 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}
function captureAction () {
var encodingProperties;
var fileName;
var tempFolder = getAppData().temporaryFolder;
let encodingProperties;
let fileName;
const tempFolder = getAppData().temporaryFolder;
if (encodingType === Camera.EncodingType.PNG) {
fileName = 'photo.png';
@ -483,8 +483,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
tempFolder.createFileAsync(fileName, OptUnique)
.then(function (tempCapturedFile) {
return new WinJS.Promise(function (complete) {
var photoStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
var finalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
const photoStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
const finalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
capture.capturePhotoToStreamAsync(encodingProperties, photoStream)
.then(function () {
return Windows.Graphics.Imaging.BitmapDecoder.createAsync(photoStream);
@ -518,11 +518,11 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
.done(function (capturedFile) {
destroyCameraPreview();
savePhoto(capturedFile, {
destinationType: destinationType,
targetHeight: targetHeight,
targetWidth: targetWidth,
encodingType: encodingType,
saveToPhotoAlbum: saveToPhotoAlbum
destinationType,
targetHeight,
targetWidth,
encodingType,
saveToPhotoAlbum
}, successCallback, errorCallback);
}, function (err) {
destroyCameraPreview();
@ -531,22 +531,22 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}
function getAspectRatios (capture) {
var videoDeviceController = capture.videoDeviceController;
var photoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo).map(function (element) {
const videoDeviceController = capture.videoDeviceController;
const photoAspectRatios = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo).map(function (element) {
return (element.width / element.height).toFixed(1);
}).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);
}).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);
}).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]) {
map[item] = 0;
}
@ -561,8 +561,8 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
function setAspectRatio (capture, aspect) {
// Max photo resolution with desired aspect ratio
var videoDeviceController = capture.videoDeviceController;
var photoResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo)
const videoDeviceController = capture.videoDeviceController;
const photoResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.photo)
.filter(function (elem) {
return ((elem.width / elem.height).toFixed(1) === aspect);
})
@ -571,7 +571,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
});
// Max video resolution with desired aspect ratio
var videoRecordResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord)
const videoRecordResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoRecord)
.filter(function (elem) {
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
var videoPreviewResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview)
const videoPreviewResolution = videoDeviceController.getAvailableMediaStreamProperties(CapMSType.videoPreview)
.filter(function (elem) {
return ((elem.width / elem.height).toFixed(1) === aspect);
})
@ -681,14 +681,14 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) {
}
function takePictureFromCameraWindows (successCallback, errorCallback, args) {
var destinationType = args[1];
var targetWidth = args[3];
var targetHeight = args[4];
var encodingType = args[5];
var allowCrop = !!args[7];
var saveToPhotoAlbum = args[9];
var WMCapture = Windows.Media.Capture;
var cameraCaptureUI = new WMCapture.CameraCaptureUI();
const destinationType = args[1];
const targetWidth = args[3];
const targetHeight = args[4];
const encodingType = args[5];
const allowCrop = !!args[7];
const saveToPhotoAlbum = args[9];
const WMCapture = Windows.Media.Capture;
const cameraCaptureUI = new WMCapture.CameraCaptureUI();
cameraCaptureUI.photoSettings.allowCropping = allowCrop;
@ -699,9 +699,9 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
}
// decide which max pixels should be supported by targetWidth or targetHeight.
var maxRes = null;
var UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution;
var totalPixels = targetWidth * targetHeight;
let maxRes = null;
const UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution;
const totalPixels = targetWidth * targetHeight;
if (targetWidth === -1 && targetHeight === -1) {
maxRes = UIMaxRes.highestAvailable;
@ -723,18 +723,18 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
cameraCaptureUI.photoSettings.maxResolution = maxRes;
var cameraPicture;
let cameraPicture;
// define focus handler for windows phone 10.0
var savePhotoOnFocus = function () {
const savePhotoOnFocus = function () {
window.removeEventListener('focus', savePhotoOnFocus);
// call only when the app is in focus again
savePhoto(cameraPicture, {
destinationType: destinationType,
targetHeight: targetHeight,
targetWidth: targetWidth,
encodingType: encodingType,
saveToPhotoAlbum: saveToPhotoAlbum
destinationType,
targetHeight,
targetWidth,
encodingType,
saveToPhotoAlbum
}, 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 (navigator.appVersion.indexOf('Windows Phone 10.0') < 0) {
savePhoto(cameraPicture, {
destinationType: destinationType,
targetHeight: targetHeight,
targetWidth: targetWidth,
encodingType: encodingType,
saveToPhotoAlbum: saveToPhotoAlbum
destinationType,
targetHeight,
targetWidth,
encodingType,
saveToPhotoAlbum
}, successCallback, errorCallback);
}
}, function () {
@ -770,7 +770,7 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) {
function savePhoto (picture, options, successCallback, errorCallback) {
// success callback for capture operation
var success = function (picture) {
const success = function (picture) {
if (options.destinationType === Camera.DestinationType.FILE_URI) {
if (options.targetHeight > 0 && options.targetWidth > 0) {
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);
} else {
fileIO.readBufferAsync(picture).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
const strBase64 = encodeToBase64String(buffer);
picture.deleteAsync().done(function () {
successCallback(strBase64);
}, function (err) {
@ -803,8 +803,8 @@ function savePhoto (picture, options, successCallback, errorCallback) {
if (!options.saveToPhotoAlbum) {
success(picture);
} else {
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
var saveFile = function (file) {
const savePicker = new Windows.Storage.Pickers.FileSavePicker();
const saveFile = function (file) {
if (file) {
// Prevent updates to the remote version of the file until we're done
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
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) {
var file = eventArgs.file;
const file = eventArgs.file;
saveFile(file);
webUIApp.removeEventListener('activated', fileSaveHandler);
}

View File

@ -78,20 +78,20 @@ exports.defineAutoTests = function () {
/******************************************************************************/
exports.defineManualTests = function (contentEl, createActionButton) {
var pictureUrl = null;
var fileObj = null;
var fileEntry = null;
var pageStartTime = +new Date();
let pictureUrl = null;
let fileObj = null;
let fileEntry = null;
const pageStartTime = +new Date();
// default camera options
var camQualityDefault = ['50', 50];
var camDestinationTypeDefault = ['FILE_URI', 1];
var camPictureSourceTypeDefault = ['CAMERA', 1];
var camAllowEditDefault = ['allowEdit', false];
var camEncodingTypeDefault = ['JPEG', 0];
var camMediaTypeDefault = ['mediaType', 0];
var camCorrectOrientationDefault = ['correctOrientation', false];
var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
const camQualityDefault = ['50', 50];
const camDestinationTypeDefault = ['FILE_URI', 1];
const camPictureSourceTypeDefault = ['CAMERA', 1];
const camAllowEditDefault = ['allowEdit', false];
const camEncodingTypeDefault = ['JPEG', 0];
const camMediaTypeDefault = ['mediaType', 0];
const camCorrectOrientationDefault = ['correctOrientation', false];
const camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
function log (value) {
console.log(value);
@ -101,7 +101,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
function clearStatus () {
document.getElementById('camera_status').innerHTML = '';
document.getElementById('camera_image').src = 'about:blank';
var canvas = document.getElementById('canvas');
const canvas = document.getElementById('canvas');
canvas.width = canvas.height = 1;
pictureUrl = null;
fileObj = null;
@ -119,8 +119,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
log('URL: "' + url.slice(0, 90) + '"');
pictureUrl = url;
var img = document.getElementById('camera_image');
var startTime = new Date();
const img = document.getElementById('camera_image');
const startTime = new Date();
img.src = url;
img.onload = function () {
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) {
// do nothing
} 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);
}
}
function getPicture () {
clearStatus();
var options = extractOptions();
const options = extractOptions();
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.
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);
};
}
@ -177,7 +177,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
*/
function readFile () {
function onFileReadAsDataURL (evt) {
var img = document.getElementById('camera_image');
const img = document.getElementById('camera_image');
img.style.visibility = 'visible';
img.style.display = 'block';
img.src = evt.target.result;
@ -188,7 +188,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
log('Got file: ' + JSON.stringify(file));
fileObj = file;
/* eslint-disable no-undef */
var reader = new FileReader();
const reader = new FileReader();
/* eslint-enable no-undef */
reader.onload = function () {
log('FileReader.readAsDataURL() - length = ' + reader.result.length);
@ -219,9 +219,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
* This calls FileEntry.copyTo and FileEntry.moveTo.
*/
function copyImage () {
var onFileSystemReceived = function (fileSystem) {
var destDirEntry = fileSystem.root;
var origName = fileEntry.name;
const onFileSystemReceived = function (fileSystem) {
const destDirEntry = fileSystem.root;
const origName = fileEntry.name;
// Test FileEntry API here.
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.
*/
function writeImage () {
var onFileWriterReceived = function (fileWriter) {
const onFileWriterReceived = function (fileWriter) {
fileWriter.onwrite = logCallback('FileWriter.write', true);
fileWriter.onerror = logCallback('FileWriter.write', false);
fileWriter.write('some text!');
};
var onFileTruncateWriterReceived = function (fileWriter) {
const onFileTruncateWriterReceived = function (fileWriter) {
fileWriter.onwrite = logCallback('FileWriter.truncate', true);
fileWriter.onerror = logCallback('FileWriter.truncate', false);
fileWriter.truncate(10);
@ -270,15 +270,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function displayImageUsingCanvas () {
var canvas = document.getElementById('canvas');
var img = document.getElementById('camera_image');
var w = img.width;
var h = img.height;
const canvas = document.getElementById('canvas');
const img = document.getElementById('camera_image');
let w = img.width;
let h = img.height;
h = 100 / w * h;
w = 100;
canvas.width = w;
canvas.height = h;
var context = canvas.getContext('2d');
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0, w, h);
}
@ -311,9 +311,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
return;
}
/* eslint-enable no-undef */
var URLApi = window.URL || window.webkitURL;
const URLApi = window.URL || window.webkitURL;
if (URLApi) {
var blobURL = URLApi.createObjectURL(fileObj);
const blobURL = URLApi.createObjectURL(fileObj);
if (blobURL) {
setPicture(blobURL, function () {
URLApi.revokeObjectURL(blobURL);
@ -327,11 +327,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function extractOptions () {
var els = document.querySelectorAll('#image-options select');
var ret = {};
const els = document.querySelectorAll('#image-options select');
const ret = {};
/* eslint-disable no-cond-assign */
for (var i = 0, el; el = els[i]; ++i) {
var value = el.value;
for (let i = 0, el; el = els[i]; ++i) {
let value = el.value;
if (value === '') continue;
value = +value;
@ -346,20 +346,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function createOptionsEl (name, values, selectionDefault) {
var openDiv = '<div style="display: inline-block">' + name + ': ';
var select = '<select name=' + name + ' id="' + name + '">';
const openDiv = '<div style="display: inline-block">' + name + ': ';
const select = '<select name=' + name + ' id="' + name + '">';
var defaultOption = '';
let defaultOption = '';
if (selectionDefault === undefined) {
defaultOption = '<option value="">default</option>';
}
var options = '';
let options = '';
if (typeof values === 'boolean') {
values = { true: 1, false: 0 };
}
for (var k in values) {
var isSelected = '';
for (const k in values) {
let isSelected = '';
if (selectionDefault) {
if (selectionDefault[0] === k) {
isSelected = 'selected';
@ -368,20 +368,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
options += '<option value="' + values[k] + '" ' + isSelected + '>' + k + '</option>';
}
var closeDiv = '</select></div>';
const closeDiv = '</select></div>';
return openDiv + select + defaultOption + options + closeDiv;
}
/******************************************************************************/
var info_div = '<h1>Camera</h1>' +
const info_div = '<h1>Camera</h1>' +
'<div id="info">' +
'<b>Status:</b> <div id="camera_status"></div>' +
'img: <img width="100" id="camera_image">' +
'canvas: <canvas id="canvas" width="1" height="1"></canvas>' +
'</div>';
var options_div = '<h2>Cordova Camera API Options</h2>' +
const options_div = '<h2>Cordova Camera API Options</h2>' +
'<div id="image-options">' +
createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault) +
createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault) +
@ -395,8 +395,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault) +
createOptionsEl('cameraDirection', Camera.Direction) +
'</div>';
var getpicture_div = '<div id="getpicture"></div>';
var test_procedure = '<h4>Recommended Test Procedure</h4>' +
const getpicture_div = '<div id="getpicture"></div>';
const test_procedure = '<h4>Recommended Test Procedure</h4>' +
'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' +
'</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>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>';
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' +
'</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=camcorder <input type="file" accept="video/*;capture=camcorder" 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' +
'</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"' +
@ -443,12 +443,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
contentEl.innerHTML = info_div + options_div + getpicture_div + test_procedure + inputs_div + actions_div;
}
var elements = document.getElementsByClassName('testInputTag');
var listener = function (e) {
const elements = document.getElementsByClassName('testInputTag');
const listener = function (e) {
testInputTag(e.target);
};
for (var i = 0; i < elements.length; ++i) {
var item = elements[i];
for (let i = 0; i < elements.length; ++i) {
const item = elements[i];
item.addEventListener('change', listener, false);
}

View File

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

View File

@ -23,7 +23,7 @@
* @ignore in favour of iOS' one
* A handle to an image picker popover.
*/
var CameraPopoverHandle = function () {
const CameraPopoverHandle = function () {
this.setPosition = function (popoverOptions) {
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
@ -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} [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
this.x = x || 0;
this.y = y || 32;

View File

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