Modificado login y upload
|
@ -13,6 +13,7 @@
|
|||
"author": "Apache Cordova Team",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"cordova-android": "^8.0.0",
|
||||
"cordova-ios": "^5.0.1",
|
||||
"cordova-plugin-camera": "^4.0.3",
|
||||
|
@ -22,6 +23,7 @@
|
|||
"phonegap-plugin-barcodescanner": "^8.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cordova-browser": "^6.0.0",
|
||||
"cordova-plugin-whitelist": "^1.3.3"
|
||||
},
|
||||
"cordova": {
|
||||
|
@ -36,7 +38,8 @@
|
|||
},
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
"android",
|
||||
"browser"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<manifest android:hardwareAccelerated="true" android:versionCode="10006" android:versionName="1.0.6" package="es.verdnatura.verdnaturafoto" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="es.verdnatura.verdnaturafoto" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
|
||||
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize" android:screenOrientation="portrait">
|
||||
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter android:label="@string/launcher_name">
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -15,7 +15,6 @@
|
|||
<activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.RECORD_VIDEO" />
|
||||
|
|
|
@ -1,59 +1,63 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
|
||||
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<title>Verdnatura Photo</title>
|
||||
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="js/fastclick.js" type="application/javascript"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<img id="logo" src="img/logo.png" alt="verdnatura"/>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/user.png" alt="verdnatura" />
|
||||
<input type="text" id="txtuser" placeholder="usuario" value=""/>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/password.png" alt="verdnatura"/>
|
||||
<input type="password" id="txtpassword" placeholder="contraseña" value=""/>
|
||||
</div>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
|
||||
<div class="btn loginbtn">
|
||||
Entrar
|
||||
</div>
|
||||
<head>
|
||||
|
||||
|
||||
<div class="loading">
|
||||
<div class="loadingcontent">
|
||||
<div class="sk-cube-grid">
|
||||
<div class="sk-cube sk-cube1"></div>
|
||||
<div class="sk-cube sk-cube2"></div>
|
||||
<div class="sk-cube sk-cube3"></div>
|
||||
<div class="sk-cube sk-cube4"></div>
|
||||
<div class="sk-cube sk-cube5"></div>
|
||||
<div class="sk-cube sk-cube6"></div>
|
||||
<div class="sk-cube sk-cube7"></div>
|
||||
<div class="sk-cube sk-cube8"></div>
|
||||
<div class="sk-cube sk-cube9"></div>
|
||||
</div>
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<title>Verdnatura Photo</title>
|
||||
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="js/fastclick.js" type="application/javascript"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<img id="logo" src="img/logo.png" alt="verdnatura" />
|
||||
|
||||
<div class="input">
|
||||
<img src="img/user.png" alt="verdnatura" />
|
||||
<input type="text" id="txtuser" placeholder="usuario" value="" />
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/password.png" alt="verdnatura" />
|
||||
<input type="password" id="txtpassword" placeholder="contraseña" value="" />
|
||||
</div>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
|
||||
<div class="btn loginbtn">
|
||||
Entrar
|
||||
</div>
|
||||
|
||||
|
||||
<div class="loading">
|
||||
<div class="loadingcontent">
|
||||
<div class="sk-cube-grid">
|
||||
<div class="sk-cube sk-cube1"></div>
|
||||
<div class="sk-cube sk-cube2"></div>
|
||||
<div class="sk-cube sk-cube3"></div>
|
||||
<div class="sk-cube sk-cube4"></div>
|
||||
<div class="sk-cube sk-cube5"></div>
|
||||
<div class="sk-cube sk-cube6"></div>
|
||||
<div class="sk-cube sk-cube7"></div>
|
||||
<div class="sk-cube sk-cube8"></div>
|
||||
<div class="sk-cube sk-cube9"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="js/login.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="js/login.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,3 +1,6 @@
|
|||
|
||||
|
||||
|
||||
//var url = "http://172.16.198.221:3000/api/";
|
||||
var url = "https://salix.verdnatura.es/api/";
|
||||
var urlweb = "https://verdnatura.es/";
|
||||
|
@ -77,7 +80,7 @@ $(document).ready(function () {
|
|||
var ref = cordova.InAppBrowser.open(url, target, options);
|
||||
});
|
||||
|
||||
$("#txtarticle").on("keypress", function(event){
|
||||
$("#txtarticle").on("keypress", function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
setManualMode();
|
||||
event.preventDefault();
|
||||
|
@ -91,11 +94,11 @@ function setManualMode() {
|
|||
|
||||
if (idArticulo.trim().length > 0) {
|
||||
navigator.notification.confirm(
|
||||
'Article: ' + idArticulo, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Biblioteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
'Article: ' + idArticulo, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Biblioteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
} else {
|
||||
navigator.notification.alert("Insert manual id or scan article", null, "Verdnatura says:", "¡ups!");
|
||||
}
|
||||
|
@ -104,96 +107,82 @@ function setManualMode() {
|
|||
function savePhoto() {
|
||||
|
||||
navigator.notification.confirm(
|
||||
'Estas seguro de actualizar la foto de: ' + idArticulo, // message
|
||||
confirmSave, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Guardar', 'Cancelar'] // buttonLabels
|
||||
);
|
||||
'Estas seguro de actualizar la foto de: ' + idArticulo, // message
|
||||
confirmSaveSALIX, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Guardar', 'Cancelar'] // buttonLabels
|
||||
);
|
||||
|
||||
// confirmSave(1);
|
||||
// confirmSave(1);
|
||||
|
||||
}
|
||||
function confirmSave(buttonIndex) {
|
||||
|
||||
function confirmSaveSALIX(buttonIndex) {
|
||||
if (buttonIndex == 1) {
|
||||
$(".loading").fadeIn(200);
|
||||
var img = dataURItoBlob(cropper.getCroppedCanvas().toDataURL('image/png'));
|
||||
|
||||
|
||||
var data = new FormData();
|
||||
|
||||
data.append("srv", "json:image/upload");
|
||||
|
||||
data.append("schema", "catalog");
|
||||
|
||||
data.append("name", "" + idArticulo + "");
|
||||
|
||||
data.append("token", localStorage.getItem("token"));
|
||||
|
||||
data.append("user", localStorage.getItem("user"));
|
||||
|
||||
data.append("password", localStorage.getItem("password"));
|
||||
|
||||
data.append("updateMatching", true);
|
||||
|
||||
data.append("image", img);
|
||||
|
||||
var date = new Date();
|
||||
var timestamp = date.getTime();
|
||||
var fileName = `${idArticulo}_${timestamp}`;
|
||||
const data = new FormData();
|
||||
data.append("blob", img, fileName);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", urlweb, true);
|
||||
var urlUpload = url + 'Images/upload' + '?fileName=' + idArticulo + '&collection=catalog&id=' + idArticulo;
|
||||
console.log("la web " + urlUpload);
|
||||
xhr.open("POST", urlUpload);
|
||||
xhr.setRequestHeader('Authorization', localStorage.getItem('token'));
|
||||
xhr.send(data);
|
||||
xhr.onload = function () {
|
||||
var response = JSON.parse(xhr.response);
|
||||
if (response.data == true) {
|
||||
navigator.notification.alert("Carga completa!", function () {
|
||||
window.location = "main.html";
|
||||
}, "Verdnatura dice:", "¡Buen trabajo!");
|
||||
} else {
|
||||
navigator.notification.alert("Error al cargar la foto", null, "Verdnatura dice:", "¡ooohh!");
|
||||
$(".loading").fadeOut(500);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
|
||||
if (this.status >= 200 && this.status < 300) {
|
||||
navigator.notification.alert("Carga completa!", function () {
|
||||
window.location = "main.html";
|
||||
}, "Verdnatura dice:", "¡Buen trabajo!");
|
||||
} else {
|
||||
navigator.notification.alert("Error al cargar la foto (método upload)", null, "Inténtalo de nuevo");
|
||||
$(".loading").fadeOut(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
navigator.notification.alert("Error al cargar la foto", null, "Verdnatura dice:", "¡ooohh!");
|
||||
$(".loading").fadeOut(500);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function dataURItoBlob(dataURI) {
|
||||
var binary = atob(dataURI.split(',')[1]);
|
||||
var array = [];
|
||||
for (var i = 0; i < binary.length; i++) {
|
||||
array.push(binary.charCodeAt(i));
|
||||
}
|
||||
return new Blob([new Uint8Array(array)], {type: 'image/png'});
|
||||
return new Blob([new Uint8Array(array)], { type: 'image/png' });
|
||||
}
|
||||
function scanBarcode() {
|
||||
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
idArticulo = result.text;
|
||||
function (result) {
|
||||
idArticulo = result.text;
|
||||
|
||||
navigator.notification.confirm(
|
||||
'Article: ' + result.text, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Bibloteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
navigator.notification.confirm(
|
||||
'Article: ' + result.text, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Bibloteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
|
||||
},
|
||||
function (error) {
|
||||
navigator.notification.alert(
|
||||
"Could not scan: " + error, // message
|
||||
onError, // callback
|
||||
'Game Over', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
},
|
||||
function (error) {
|
||||
navigator.notification.alert(
|
||||
"Could not scan: " + error, // message
|
||||
onError, // callback
|
||||
'Información', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
function onConfirm(buttonIndex) {
|
||||
|
@ -217,7 +206,7 @@ function onError() {
|
|||
}
|
||||
function showCamera() {
|
||||
var srcType = Camera.PictureSourceType.CAMERA;
|
||||
|
||||
|
||||
var options = {
|
||||
saveToPhotoAlbum: true,
|
||||
quality: 100,
|
||||
|
@ -228,7 +217,7 @@ function showCamera() {
|
|||
allowEdit: false,
|
||||
correctOrientation: true
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
navigator.camera.getPicture(cameraSuccess, cameraError, options);
|
||||
|
@ -236,8 +225,8 @@ function showCamera() {
|
|||
}
|
||||
function showLibrary() {
|
||||
var srcType = Camera.PictureSourceType.PHOTOLIBRARY;
|
||||
|
||||
var options = {
|
||||
|
||||
var options = {
|
||||
saveToPhotoAlbum: false,
|
||||
quality: 100,
|
||||
destinationType: Camera.DestinationType.FILE_URI,
|
||||
|
@ -273,11 +262,11 @@ function setCrop() {
|
|||
var height = event.detail.height;
|
||||
|
||||
if (
|
||||
width < minCroppedWidth
|
||||
|| height < minCroppedHeight
|
||||
|| width > maxCroppedWidth
|
||||
|| height > maxCroppedHeight
|
||||
) {
|
||||
width < minCroppedWidth
|
||||
|| height < minCroppedHeight
|
||||
|| width > maxCroppedWidth
|
||||
|| height > maxCroppedHeight
|
||||
) {
|
||||
cropper.setData({
|
||||
width: Math.max(minCroppedWidth, Math.min(maxCroppedWidth, width)),
|
||||
height: Math.max(minCroppedHeight, Math.min(maxCroppedHeight, height))
|
||||
|
@ -313,11 +302,11 @@ function setCrop() {
|
|||
}
|
||||
function cameraError(message) {
|
||||
navigator.notification.alert(
|
||||
"Could not take a picture: " + message, // message
|
||||
onError, // callback
|
||||
'Game Over', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
"Could not take a picture: " + message, // message
|
||||
onError, // callback
|
||||
'Información', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
}
|
||||
function setOptions(srcType) {
|
||||
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
//var url = "http://172.16.198.221:3000/api/";
|
||||
var url = "https://salix.verdnatura.es";
|
||||
var urlweb = "https://verdnatura.es/";
|
||||
var LOGIN = "Accounts/login";
|
||||
//var urlweb = "https://verdnatura.es/";
|
||||
var LOGIN = "/api/Accounts/login";
|
||||
var CHECKUUID = "Devices/checkUuid";
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".loading").show();
|
||||
FastClick.attach(document.body);
|
||||
$(".loginbtn").on("click", login);
|
||||
$(".loginbtn").on("click", login_new);
|
||||
|
||||
$("#txtuser").val(localStorage.getItem("user"));
|
||||
$("#txtpassword").val(localStorage.getItem("password"));
|
||||
|
||||
checkLogin();
|
||||
//$("#txtpassword").on("click", login_new);
|
||||
|
||||
checkLogin_new();
|
||||
});
|
||||
|
||||
|
||||
|
@ -26,32 +29,47 @@ function checkLogin() {
|
|||
login();
|
||||
}
|
||||
}
|
||||
function checkLogin_new() {
|
||||
|
||||
function login() {
|
||||
|
||||
|
||||
if (localStorage.getItem("user") == null) {
|
||||
$(".loading").hide();
|
||||
} else {
|
||||
$("#txtuser").val(localStorage.getItem("user"));
|
||||
$("#txtpassword").val(localStorage.getItem("password"));
|
||||
login_new();
|
||||
}
|
||||
}
|
||||
|
||||
function login_new() {
|
||||
//navigator.notification.alert("User or password fail.", null, "Verdnatura says:", "¡ok!");
|
||||
$(".loading").fadeIn(500);
|
||||
var data = new FormData();
|
||||
var boundary = generateUUID();
|
||||
|
||||
|
||||
data.append("srv", "json:core/login");
|
||||
|
||||
data.append("remember", "0");
|
||||
|
||||
data.append("user", $("#txtuser").val());
|
||||
|
||||
data.append("password", $("#txtpassword").val());
|
||||
// var boundary = generateUUID();
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", urlweb, true);
|
||||
xhr.send(data);
|
||||
xhr.open("POST", url + LOGIN, true);
|
||||
xhr.setRequestHeader("version", "1");
|
||||
xhr.setRequestHeader("application", "json");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
|
||||
let json = {
|
||||
user: $("#txtuser").val(),
|
||||
password: $("#txtpassword").val()
|
||||
}
|
||||
|
||||
xhr.send(JSON.stringify(json));
|
||||
|
||||
|
||||
|
||||
xhr.onload = function () {
|
||||
var response = JSON.parse(xhr.response);
|
||||
|
||||
if (response.data["login"] == true) {
|
||||
if (response["token"]) {
|
||||
|
||||
localStorage.setItem("user", $("#txtuser").val());
|
||||
localStorage.setItem("password", $("#txtpassword").val());
|
||||
localStorage.setItem("token", response.data["token"]);
|
||||
localStorage.setItem("token", response["token"]);
|
||||
window.location = "main.html";
|
||||
} else {
|
||||
navigator.notification.alert("User or password fail.", null, "Verdnatura says:", "¡ok!");
|
||||
|
@ -61,7 +79,8 @@ function login() {
|
|||
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
xhr.onerror = function (e) {
|
||||
console.log(e)
|
||||
navigator.notification.alert("We could not authenticate you contact with Verdnatura spain", null, "Verdnatura says:", "¡ups!");
|
||||
removeItems();
|
||||
$(".loading").fadeOut(500);
|
||||
|
@ -70,7 +89,6 @@ function login() {
|
|||
|
||||
|
||||
}
|
||||
|
||||
function cancelLoading() {
|
||||
|
||||
navigator.notification.alert("Esto te va un poco lento, ¿no?, ¿Has mirado tu conexión?", null, "Verdnatura dice:", "jopee, qué pesados..");
|
||||
|
|
|
@ -1,88 +1,92 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<link href="css/cropper.css" rel="stylesheet" type="text/css"/>
|
||||
<title>Verdnatura Photo</title>
|
||||
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="js/fastclick.js" type="application/javascript"></script>
|
||||
</head>
|
||||
<body class="blackground">
|
||||
<header>
|
||||
<div class="btnback"></div>
|
||||
<div class="btnsave"></div>
|
||||
|
||||
</header>
|
||||
<head>
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<link href="css/cropper.css" rel="stylesheet" type="text/css" />
|
||||
<title>Verdnatura Photo</title>
|
||||
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="js/fastclick.js" type="application/javascript"></script>
|
||||
</head>
|
||||
|
||||
<body class="blackground">
|
||||
<header>
|
||||
<div class="btnback"></div>
|
||||
<div class="btnsave"></div>
|
||||
|
||||
</header>
|
||||
|
||||
|
||||
<div class="contentPhoto">
|
||||
<img id="photo" src="img/IMG_9861.png"/>
|
||||
<div class="contentPhoto">
|
||||
<img id="photo" src="img/IMG_9861.png" />
|
||||
</div>
|
||||
|
||||
<div class="menubtn">
|
||||
<div id="btn1" class="btnmin selected">3:2</div>
|
||||
<div id="btn2" class="btnmin">16:9</div>
|
||||
<div id="btn3" class="btnmin">1:1</div>
|
||||
</div>
|
||||
|
||||
<div class="menu">
|
||||
<div class="btnlogout"></div>
|
||||
<img id="logo" src="img/logo.png" alt="verdnatura" />
|
||||
<br>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/article.png" alt="verdnatura" />
|
||||
<input type="number" id="txtarticle" placeholder="ID ARTICULO" value="" />
|
||||
</div>
|
||||
|
||||
<div class="menubtn">
|
||||
<div id="btn1" class="btnmin selected">3:2</div>
|
||||
<div id="btn2" class="btnmin">16:9</div>
|
||||
<div id="btn3" class="btnmin">1:1</div>
|
||||
</div>
|
||||
<!--<div class="btnbarcode">Scan</div>-->
|
||||
|
||||
<div class="menu">
|
||||
<div class="btnlogout"></div>
|
||||
<img id="logo" src="img/logo.png" alt="verdnatura"/>
|
||||
<br>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/article.png" alt="verdnatura"/>
|
||||
<input type="number" id="txtarticle" placeholder="ID ARTICULO" value=""/>
|
||||
</div>
|
||||
|
||||
<!--<div class="btnbarcode">Scan</div>-->
|
||||
|
||||
|
||||
<div class="btn loginbtn" id="btntakepicture">
|
||||
¡Vamos!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="loading">
|
||||
<div class="loadingcontent">
|
||||
<div class="sk-cube-grid">
|
||||
<div class="sk-cube sk-cube1"></div>
|
||||
<div class="sk-cube sk-cube2"></div>
|
||||
<div class="sk-cube sk-cube3"></div>
|
||||
<div class="sk-cube sk-cube4"></div>
|
||||
<div class="sk-cube sk-cube5"></div>
|
||||
<div class="sk-cube sk-cube6"></div>
|
||||
<div class="sk-cube sk-cube7"></div>
|
||||
<div class="sk-cube sk-cube8"></div>
|
||||
<div class="sk-cube sk-cube9"></div>
|
||||
</div>
|
||||
|
||||
<div class="btn loginbtn" id="btntakepicture">
|
||||
Buscar
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="loading">
|
||||
<div class="loadingcontent">
|
||||
<div class="sk-cube-grid">
|
||||
<div class="sk-cube sk-cube1"></div>
|
||||
<div class="sk-cube sk-cube2"></div>
|
||||
<div class="sk-cube sk-cube3"></div>
|
||||
<div class="sk-cube sk-cube4"></div>
|
||||
<div class="sk-cube sk-cube5"></div>
|
||||
<div class="sk-cube sk-cube6"></div>
|
||||
<div class="sk-cube sk-cube7"></div>
|
||||
<div class="sk-cube sk-cube8"></div>
|
||||
<div class="sk-cube sk-cube9"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script src="plugins/phonegap-plugin-barcodescanner/www/barcodescanner.js" type="text/javascript"></script>
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script src="plugins/phonegap-plugin-barcodescanner/www/barcodescanner.js" type="text/javascript"></script>
|
||||
|
||||
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/Camera.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/CameraConstants.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/CameraPopoverOptions.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/ios/CameraPopoverHandle.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/Camera.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/CameraConstants.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/CameraPopoverOptions.js"></script>
|
||||
<script type="text/javascript" src="plugins/cordova-plugin-camera/www/ios/CameraPopoverHandle.js"></script>
|
||||
|
||||
<script src="js/cropper.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
<script src="js/cropper.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,362 @@
|
|||
{
|
||||
"prepare_queue": {
|
||||
"installed": [],
|
||||
"uninstalled": []
|
||||
},
|
||||
"config_munge": {
|
||||
"files": {
|
||||
"config.xml": {
|
||||
"parents": {
|
||||
"/*": [
|
||||
{
|
||||
"xml": "<feature name=\"Camera\"><param name=\"browser-package\" value=\"Camera\" /></feature>",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"xml": "<feature name=\"BarcodeScanner\"><param name=\"browser-package\" value=\"BarcodeScanner\" /></feature>",
|
||||
"count": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"installed_plugins": {
|
||||
"cordova-plugin-camera": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
},
|
||||
"cordova-plugin-dialogs": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
},
|
||||
"cordova-plugin-file": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
},
|
||||
"cordova-plugin-media-capture": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
},
|
||||
"cordova-plugin-whitelist": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
},
|
||||
"phonegap-plugin-barcodescanner": {
|
||||
"PACKAGE_NAME": "es.verdnatura.verdnaturafoto"
|
||||
}
|
||||
},
|
||||
"dependent_plugins": {},
|
||||
"modules": [
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraConstants.js",
|
||||
"id": "cordova-plugin-camera.Camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"Camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js",
|
||||
"id": "cordova-plugin-camera.CameraPopoverOptions",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"CameraPopoverOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/Camera.js",
|
||||
"id": "cordova-plugin-camera.camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"navigator.camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/src/browser/CameraProxy.js",
|
||||
"id": "cordova-plugin-camera.CameraProxy",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/browser/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification_browser",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/Preparing.js",
|
||||
"id": "cordova-plugin-file.Preparing",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/src/browser/FileProxy.js",
|
||||
"id": "cordova-plugin-file.browserFileProxy",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/FileSystem.js",
|
||||
"id": "cordova-plugin-file.firefoxFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureAudioOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureAudioOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureAudioOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureImageOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureImageOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureImageOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureVideoOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureVideoOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureVideoOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureError.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureError",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFileData.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFileData",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFileData"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFile.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFile",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/helpers.js",
|
||||
"id": "cordova-plugin-media-capture.helpers",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/capture.js",
|
||||
"id": "cordova-plugin-media-capture.capture",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"navigator.device.capture"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/src/browser/CaptureProxy.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureProxy",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/www/barcodescanner.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScanner",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"clobbers": [
|
||||
"cordova.plugins.barcodeScanner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/src/browser/BarcodeScannerProxy.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScannerProxy",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"runs": true
|
||||
}
|
||||
],
|
||||
"plugin_metadata": {
|
||||
"cordova-plugin-camera": "4.0.3",
|
||||
"cordova-plugin-dialogs": "2.0.1",
|
||||
"cordova-plugin-file": "6.0.1",
|
||||
"cordova-plugin-media-capture": "3.0.2",
|
||||
"cordova-plugin-whitelist": "1.3.3",
|
||||
"phonegap-plugin-barcodescanner": "8.0.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<widget id="es.verdnatura.verdnaturafoto" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
||||
<name>Nature Photo</name>
|
||||
<description>
|
||||
A sample Apache Cordova application that responds to the deviceready event.
|
||||
</description>
|
||||
<author email="dev@cordova.apache.org" href="http://cordova.io">
|
||||
Apache Cordova Team
|
||||
</author>
|
||||
<content src="index.html" />
|
||||
<access origin="*" />
|
||||
<allow-intent href="http://*/*" />
|
||||
<allow-intent href="https://*/*" />
|
||||
<allow-intent href="tel:*" />
|
||||
<allow-intent href="sms:*" />
|
||||
<allow-intent href="mailto:*" />
|
||||
<allow-intent href="geo:*" />
|
||||
</widget>
|
|
@ -0,0 +1,531 @@
|
|||
/**
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
'License'); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
this file is found by cordova-lib when you attempt to
|
||||
'cordova platform add PATH' where path is this repo.
|
||||
*/
|
||||
|
||||
var shell = require('shelljs');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
var cdvcmn = require('cordova-common');
|
||||
var CordovaLogger = cdvcmn.CordovaLogger;
|
||||
var ConfigParser = cdvcmn.ConfigParser;
|
||||
var ActionStack = cdvcmn.ActionStack;
|
||||
var selfEvents = cdvcmn.events;
|
||||
var xmlHelpers = cdvcmn.xmlHelpers;
|
||||
var PlatformJson = cdvcmn.PlatformJson;
|
||||
var PlatformMunger = cdvcmn.ConfigChanges.PlatformMunger;
|
||||
var PluginInfoProvider = cdvcmn.PluginInfoProvider;
|
||||
|
||||
var BrowserParser = require('./browser_parser');
|
||||
var PLATFORM_NAME = 'browser';
|
||||
|
||||
function setupEvents (externalEventEmitter) {
|
||||
if (externalEventEmitter) {
|
||||
// This will make the platform internal events visible outside
|
||||
selfEvents.forwardEventsTo(externalEventEmitter);
|
||||
return externalEventEmitter;
|
||||
}
|
||||
|
||||
// There is no logger if external emitter is not present,
|
||||
// so attach a console logger
|
||||
CordovaLogger.get().subscribe(selfEvents);
|
||||
return selfEvents;
|
||||
}
|
||||
|
||||
function Api (platform, platformRootDir, events) {
|
||||
|
||||
this.platform = platform || PLATFORM_NAME;
|
||||
|
||||
// MyApp/platforms/browser
|
||||
this.root = path.resolve(__dirname, '..');
|
||||
this.events = setupEvents(events);
|
||||
this.parser = new BrowserParser(this.root);
|
||||
this._handler = require('./browser_handler');
|
||||
|
||||
this.locations = {
|
||||
platformRootDir: platformRootDir,
|
||||
root: this.root,
|
||||
www: path.join(this.root, 'www'),
|
||||
res: path.join(this.root, 'res'),
|
||||
platformWww: path.join(this.root, 'platform_www'),
|
||||
configXml: path.join(this.root, 'config.xml'),
|
||||
defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'),
|
||||
build: path.join(this.root, 'build'),
|
||||
// NOTE: Due to platformApi spec we need to return relative paths here
|
||||
cordovaJs: 'bin/templates/project/assets/www/cordova.js',
|
||||
cordovaJsSrc: 'cordova-js-src'
|
||||
};
|
||||
|
||||
this._platformJson = PlatformJson.load(this.root, platform);
|
||||
this._pluginInfoProvider = new PluginInfoProvider();
|
||||
this._munger = new PlatformMunger(platform, this.root, this._platformJson, this._pluginInfoProvider);
|
||||
}
|
||||
|
||||
Api.createPlatform = function (dest, config, options, events) {
|
||||
|
||||
var creator = require('../../lib/create');
|
||||
events = setupEvents(events);
|
||||
|
||||
var name = 'HelloCordova';
|
||||
var id = 'io.cordova.hellocordova';
|
||||
if (config) {
|
||||
name = config.name();
|
||||
id = config.packageName();
|
||||
}
|
||||
|
||||
var result;
|
||||
try {
|
||||
// we create the project using our scripts in this platform
|
||||
result = creator.createProject(dest, id, name, options)
|
||||
.then(function () {
|
||||
// after platform is created we return Api instance based on new Api.js location
|
||||
// Api.js has been copied to the new project
|
||||
// This is required to correctly resolve paths in the future api calls
|
||||
var PlatformApi = require(path.resolve(dest, 'cordova/Api'));
|
||||
return new PlatformApi('browser', dest, events);
|
||||
});
|
||||
} catch (e) {
|
||||
events.emit('error', 'createPlatform is not callable from the browser project API.');
|
||||
throw (e);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
Api.updatePlatform = function (dest, options, events) {
|
||||
// console.log("test-platform:Api:updatePlatform");
|
||||
// todo?: create projectInstance and fulfill promise with it.
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
Api.prototype.getPlatformInfo = function () {
|
||||
// console.log("browser-platform:Api:getPlatformInfo");
|
||||
// return PlatformInfo object
|
||||
return {
|
||||
'locations': this.locations,
|
||||
'root': this.root,
|
||||
'name': this.platform,
|
||||
'version': { 'version': '1.0.0' }, // um, todo!
|
||||
'projectConfig': this.config
|
||||
};
|
||||
};
|
||||
|
||||
Api.prototype.prepare = function (cordovaProject, options) {
|
||||
|
||||
// First cleanup current config and merge project's one into own
|
||||
var defaultConfigPath = path.join(this.locations.platformRootDir, 'cordova',
|
||||
'defaults.xml');
|
||||
var ownConfigPath = this.locations.configXml;
|
||||
var sourceCfg = cordovaProject.projectConfig;
|
||||
|
||||
// If defaults.xml is present, overwrite platform config.xml with it.
|
||||
// Otherwise save whatever is there as defaults so it can be
|
||||
// restored or copy project config into platform if none exists.
|
||||
if (fs.existsSync(defaultConfigPath)) {
|
||||
this.events.emit('verbose', 'Generating config.xml from defaults for platform "' + this.platform + '"');
|
||||
shell.cp('-f', defaultConfigPath, ownConfigPath);
|
||||
} else if (fs.existsSync(ownConfigPath)) {
|
||||
this.events.emit('verbose', 'Generating defaults.xml from own config.xml for platform "' + this.platform + '"');
|
||||
shell.cp('-f', ownConfigPath, defaultConfigPath);
|
||||
} else {
|
||||
this.events.emit('verbose', 'case 3"' + this.platform + '"');
|
||||
shell.cp('-f', sourceCfg.path, ownConfigPath);
|
||||
}
|
||||
|
||||
// merge our configs
|
||||
this.config = new ConfigParser(ownConfigPath);
|
||||
xmlHelpers.mergeXml(cordovaProject.projectConfig.doc.getroot(),
|
||||
this.config.doc.getroot(),
|
||||
this.platform, true);
|
||||
this.config.write();
|
||||
|
||||
// Update own www dir with project's www assets and plugins' assets and js-files
|
||||
this.parser.update_www(cordovaProject, options);
|
||||
|
||||
// Copy or Create manifest.json
|
||||
// todo: move this to a manifest helper module
|
||||
// output path
|
||||
var manifestPath = path.join(this.locations.www, 'manifest.json');
|
||||
var srcManifestPath = path.join(cordovaProject.locations.www, 'manifest.json');
|
||||
if (fs.existsSync(srcManifestPath)) {
|
||||
// just blindly copy it to our output/www
|
||||
// todo: validate it? ensure all properties we expect exist?
|
||||
this.events.emit('verbose', 'copying ' + srcManifestPath + ' => ' + manifestPath);
|
||||
shell.cp('-f', srcManifestPath, manifestPath);
|
||||
} else {
|
||||
var manifestJson = {
|
||||
'background_color': '#FFF',
|
||||
'display': 'standalone'
|
||||
};
|
||||
if (this.config) {
|
||||
if (this.config.name()) {
|
||||
manifestJson.name = this.config.name();
|
||||
}
|
||||
if (this.config.shortName()) {
|
||||
manifestJson.short_name = this.config.shortName();
|
||||
}
|
||||
if (this.config.packageName()) {
|
||||
manifestJson.version = this.config.packageName();
|
||||
}
|
||||
if (this.config.description()) {
|
||||
manifestJson.description = this.config.description();
|
||||
}
|
||||
if (this.config.author()) {
|
||||
manifestJson.author = this.config.author();
|
||||
}
|
||||
// icons
|
||||
var icons = this.config.getStaticResources('browser', 'icon');
|
||||
var manifestIcons = icons.map(function (icon) {
|
||||
// given a tag like this :
|
||||
// <icon src="res/ios/icon.png" width="57" height="57" density="mdpi" />
|
||||
/* configParser returns icons that look like this :
|
||||
{ src: 'res/ios/icon.png',
|
||||
target: undefined,
|
||||
density: 'mdpi',
|
||||
platform: null,
|
||||
width: 57,
|
||||
height: 57
|
||||
} ******/
|
||||
/* manifest expects them to be like this :
|
||||
{ "src": "images/touch/icon-128x128.png",
|
||||
"type": "image/png",
|
||||
"sizes": "128x128"
|
||||
} ******/
|
||||
// ?Is it worth looking at file extentions?
|
||||
return { 'src': icon.src,
|
||||
'type': 'image/png',
|
||||
'sizes': (icon.width + 'x' + icon.height) };
|
||||
});
|
||||
manifestJson.icons = manifestIcons;
|
||||
|
||||
// orientation
|
||||
// <preference name="Orientation" value="landscape" />
|
||||
var oriPref = this.config.getGlobalPreference('Orientation');
|
||||
if (oriPref) {
|
||||
// if it's a supported value, use it
|
||||
if (['landscape', 'portrait'].indexOf(oriPref) > -1) {
|
||||
manifestJson.orientation = oriPref;
|
||||
} else { // anything else maps to 'any'
|
||||
manifestJson.orientation = 'any';
|
||||
}
|
||||
}
|
||||
|
||||
// get start_url
|
||||
var contentNode = this.config.doc.find('content') || { 'attrib': { 'src': 'index.html' } }; // sensible default
|
||||
manifestJson.start_url = contentNode.attrib.src;
|
||||
|
||||
// now we get some values from start_url page ...
|
||||
var startUrlPath = path.join(cordovaProject.locations.www, manifestJson.start_url);
|
||||
if (fs.existsSync(startUrlPath)) {
|
||||
var contents = fs.readFileSync(startUrlPath, 'utf-8');
|
||||
// matches <meta name="theme-color" content="#FF0044">
|
||||
var themeColorRegex = /<meta(?=[^>]*name="theme-color")\s[^>]*content="([^>]*)"/i;
|
||||
var result = themeColorRegex.exec(contents);
|
||||
var themeColor;
|
||||
if (result && result.length >= 2) {
|
||||
themeColor = result[1];
|
||||
} else { // see if there is a preference in config.xml
|
||||
// <preference name="StatusBarBackgroundColor" value="#000000" />
|
||||
themeColor = this.config.getGlobalPreference('StatusBarBackgroundColor');
|
||||
}
|
||||
if (themeColor) {
|
||||
manifestJson.theme_color = themeColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifestJson, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
// update project according to config.xml changes.
|
||||
return this.parser.update_project(this.config, options);
|
||||
};
|
||||
|
||||
Api.prototype.addPlugin = function (pluginInfo, installOptions) {
|
||||
|
||||
// console.log(new Error().stack);
|
||||
if (!pluginInfo) {
|
||||
return Promise.reject(new Error('The parameter is incorrect. The first parameter ' +
|
||||
'should be valid PluginInfo instance'));
|
||||
}
|
||||
|
||||
installOptions = installOptions || {};
|
||||
installOptions.variables = installOptions.variables || {};
|
||||
// CB-10108 platformVersion option is required for proper plugin installation
|
||||
installOptions.platformVersion = installOptions.platformVersion ||
|
||||
this.getPlatformInfo().version;
|
||||
|
||||
var self = this;
|
||||
var actions = new ActionStack();
|
||||
var projectFile = this._handler.parseProjectFile && this._handler.parseProjectFile(this.root);
|
||||
|
||||
// gather all files needs to be handled during install
|
||||
pluginInfo.getFilesAndFrameworks(this.platform)
|
||||
.concat(pluginInfo.getAssets(this.platform))
|
||||
.concat(pluginInfo.getJsModules(this.platform))
|
||||
.forEach(function (item) {
|
||||
actions.push(actions.createAction(
|
||||
self._getInstaller(item.itemType),
|
||||
[item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile],
|
||||
self._getUninstaller(item.itemType),
|
||||
[item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile]));
|
||||
});
|
||||
|
||||
// run through the action stack
|
||||
return actions.process(this.platform, this.root)
|
||||
.then(function () {
|
||||
if (projectFile) {
|
||||
projectFile.write();
|
||||
}
|
||||
|
||||
// Add PACKAGE_NAME variable into vars
|
||||
if (!installOptions.variables.PACKAGE_NAME) {
|
||||
installOptions.variables.PACKAGE_NAME = self._handler.package_name(self.root);
|
||||
}
|
||||
|
||||
self._munger
|
||||
// Ignore passed `is_top_level` option since platform itself doesn't know
|
||||
// anything about managing dependencies - it's responsibility of caller.
|
||||
.add_plugin_changes(pluginInfo, installOptions.variables, /* is_top_level= */true, /* should_increment= */true)
|
||||
.save_all();
|
||||
|
||||
var targetDir = installOptions.usePlatformWww ?
|
||||
self.getPlatformInfo().locations.platformWww :
|
||||
self.getPlatformInfo().locations.www;
|
||||
|
||||
self._addModulesInfo(pluginInfo, targetDir);
|
||||
});
|
||||
};
|
||||
|
||||
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
|
||||
// console.log("NotImplemented :: browser-platform:Api:removePlugin ",plugin, uninstallOptions);
|
||||
|
||||
uninstallOptions = uninstallOptions || {};
|
||||
// CB-10108 platformVersion option is required for proper plugin installation
|
||||
uninstallOptions.platformVersion = uninstallOptions.platformVersion ||
|
||||
this.getPlatformInfo().version;
|
||||
|
||||
var self = this;
|
||||
var actions = new ActionStack();
|
||||
var projectFile = this._handler.parseProjectFile && this._handler.parseProjectFile(this.root);
|
||||
|
||||
// queue up plugin files
|
||||
plugin.getFilesAndFrameworks(this.platform)
|
||||
.concat(plugin.getAssets(this.platform))
|
||||
.concat(plugin.getJsModules(this.platform))
|
||||
.forEach(function (item) {
|
||||
actions.push(actions.createAction(
|
||||
self._getUninstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile],
|
||||
self._getInstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile]));
|
||||
});
|
||||
|
||||
// run through the action stack
|
||||
return actions.process(this.platform, this.root)
|
||||
.then(function () {
|
||||
if (projectFile) {
|
||||
projectFile.write();
|
||||
}
|
||||
|
||||
self._munger
|
||||
// Ignore passed `is_top_level` option since platform itself doesn't know
|
||||
// anything about managing dependencies - it's responsibility of caller.
|
||||
.remove_plugin_changes(plugin, /* is_top_level= */true)
|
||||
.save_all();
|
||||
|
||||
var targetDir = uninstallOptions.usePlatformWww ?
|
||||
self.getPlatformInfo().locations.platformWww :
|
||||
self.getPlatformInfo().locations.www;
|
||||
|
||||
self._removeModulesInfo(plugin, targetDir);
|
||||
// Remove stale plugin directory
|
||||
// TODO: this should be done by plugin files uninstaller
|
||||
shell.rm('-rf', path.resolve(self.root, 'Plugins', plugin.id));
|
||||
});
|
||||
};
|
||||
|
||||
Api.prototype._getInstaller = function (type) {
|
||||
var self = this;
|
||||
return function (item, plugin_dir, plugin_id, options, project) {
|
||||
var installer = self._handler[type];
|
||||
|
||||
if (!installer) {
|
||||
console.log('unrecognized type ' + type);
|
||||
|
||||
} else {
|
||||
var wwwDest = options.usePlatformWww ?
|
||||
self.getPlatformInfo().locations.platformWww :
|
||||
self._handler.www_dir(self.root);
|
||||
|
||||
if (type === 'asset') {
|
||||
installer.install(item, plugin_dir, wwwDest);
|
||||
} else if (type === 'js-module') {
|
||||
installer.install(item, plugin_dir, plugin_id, wwwDest);
|
||||
} else {
|
||||
installer.install(item, plugin_dir, self.root, plugin_id, options, project);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Api.prototype._getUninstaller = function (type) {
|
||||
var self = this;
|
||||
return function (item, plugin_dir, plugin_id, options, project) {
|
||||
var installer = self._handler[type];
|
||||
|
||||
if (!installer) {
|
||||
console.log('browser plugin uninstall: unrecognized type, skipping : ' + type);
|
||||
|
||||
} else {
|
||||
var wwwDest = options.usePlatformWww ?
|
||||
self.getPlatformInfo().locations.platformWww :
|
||||
self._handler.www_dir(self.root);
|
||||
|
||||
if (['asset', 'js-module'].indexOf(type) > -1) {
|
||||
return installer.uninstall(item, wwwDest, plugin_id);
|
||||
} else {
|
||||
return installer.uninstall(item, self.root, plugin_id, options, project);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the specified modules from list of installed modules and updates
|
||||
* platform_json and cordova_plugins.js on disk.
|
||||
*
|
||||
* @param {PluginInfo} plugin PluginInfo instance for plugin, which modules
|
||||
* needs to be added.
|
||||
* @param {String} targetDir The directory, where updated cordova_plugins.js
|
||||
* should be written to.
|
||||
*/
|
||||
Api.prototype._addModulesInfo = function (plugin, targetDir) {
|
||||
var installedModules = this._platformJson.root.modules || [];
|
||||
|
||||
var installedPaths = installedModules.map(function (installedModule) {
|
||||
return installedModule.file;
|
||||
});
|
||||
|
||||
var modulesToInstall = plugin.getJsModules(this.platform)
|
||||
.filter(function (moduleToInstall) {
|
||||
return installedPaths.indexOf(moduleToInstall.file) === -1;
|
||||
}).map(function (moduleToInstall) {
|
||||
var moduleName = plugin.id + '.' + (moduleToInstall.name || moduleToInstall.src.match(/([^\/]+)\.js/)[1]);
|
||||
var obj = {
|
||||
file: ['plugins', plugin.id, moduleToInstall.src].join('/'), /* eslint no-useless-escape : 0 */
|
||||
id: moduleName,
|
||||
pluginId: plugin.id
|
||||
};
|
||||
if (moduleToInstall.clobbers.length > 0) {
|
||||
obj.clobbers = moduleToInstall.clobbers.map(function (o) { return o.target; });
|
||||
}
|
||||
if (moduleToInstall.merges.length > 0) {
|
||||
obj.merges = moduleToInstall.merges.map(function (o) { return o.target; });
|
||||
}
|
||||
if (moduleToInstall.runs) {
|
||||
obj.runs = true;
|
||||
}
|
||||
|
||||
return obj;
|
||||
});
|
||||
|
||||
this._platformJson.root.modules = installedModules.concat(modulesToInstall);
|
||||
if (!this._platformJson.root.plugin_metadata) {
|
||||
this._platformJson.root.plugin_metadata = {};
|
||||
}
|
||||
this._platformJson.root.plugin_metadata[plugin.id] = plugin.version;
|
||||
|
||||
this._writePluginModules(targetDir);
|
||||
this._platformJson.save();
|
||||
};
|
||||
/**
|
||||
* Fetches all installed modules, generates cordova_plugins contents and writes
|
||||
* it to file.
|
||||
*
|
||||
* @param {String} targetDir Directory, where write cordova_plugins.js to.
|
||||
* Ususally it is either <platform>/www or <platform>/platform_www
|
||||
* directories.
|
||||
*/
|
||||
Api.prototype._writePluginModules = function (targetDir) {
|
||||
// Write out moduleObjects as JSON wrapped in a cordova module to cordova_plugins.js
|
||||
var final_contents = 'cordova.define(\'cordova/plugin_list\', function(require, exports, module) {\n';
|
||||
final_contents += 'module.exports = ' + JSON.stringify(this._platformJson.root.modules, null, ' ') + ';\n';
|
||||
final_contents += 'module.exports.metadata = \n';
|
||||
final_contents += '// TOP OF METADATA\n';
|
||||
final_contents += JSON.stringify(this._platformJson.root.plugin_metadata || {}, null, ' ') + '\n';
|
||||
final_contents += '// BOTTOM OF METADATA\n';
|
||||
final_contents += '});'; // Close cordova.define.
|
||||
|
||||
shell.mkdir('-p', targetDir);
|
||||
fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8');
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the specified modules from list of installed modules and updates
|
||||
* platform_json and cordova_plugins.js on disk.
|
||||
*
|
||||
* @param {PluginInfo} plugin PluginInfo instance for plugin, which modules
|
||||
* needs to be removed.
|
||||
* @param {String} targetDir The directory, where updated cordova_plugins.js
|
||||
* should be written to.
|
||||
*/
|
||||
Api.prototype._removeModulesInfo = function (plugin, targetDir) {
|
||||
var installedModules = this._platformJson.root.modules || [];
|
||||
var modulesToRemove = plugin.getJsModules(this.platform)
|
||||
.map(function (jsModule) {
|
||||
return ['plugins', plugin.id, jsModule.src].join('/');
|
||||
});
|
||||
|
||||
var updatedModules = installedModules
|
||||
.filter(function (installedModule) {
|
||||
return (modulesToRemove.indexOf(installedModule.file) === -1);
|
||||
});
|
||||
|
||||
this._platformJson.root.modules = updatedModules;
|
||||
if (this._platformJson.root.plugin_metadata) {
|
||||
delete this._platformJson.root.plugin_metadata[plugin.id];
|
||||
}
|
||||
|
||||
this._writePluginModules(targetDir);
|
||||
this._platformJson.save();
|
||||
};
|
||||
|
||||
Api.prototype.build = function (buildOptions) {
|
||||
var self = this;
|
||||
return require('./lib/check_reqs').run()
|
||||
.then(function () {
|
||||
return require('./lib/build').run.call(self, buildOptions);
|
||||
});
|
||||
};
|
||||
|
||||
Api.prototype.run = function (runOptions) {
|
||||
return require('./lib/run').run(runOptions);
|
||||
};
|
||||
|
||||
Api.prototype.clean = function (cleanOptions) {
|
||||
return require('./lib/clean').run(cleanOptions);
|
||||
};
|
||||
|
||||
Api.prototype.requirements = function () {
|
||||
return require('./lib/check_reqs').run();
|
||||
};
|
||||
|
||||
module.exports = Api;
|
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var shell = require('shelljs');
|
||||
var events = require('cordova-common').events;
|
||||
|
||||
module.exports = {
|
||||
www_dir: function (project_dir) {
|
||||
return path.join(project_dir, 'www');
|
||||
},
|
||||
package_name: function (project_dir) {
|
||||
// this method should the id from root config.xml => <widget id=xxx
|
||||
// return common.package_name(project_dir, this.www_dir(project_dir));
|
||||
// console.log('package_name called with ' + project_dir);
|
||||
var pkgName = 'io.cordova.hellocordova';
|
||||
var widget_id_regex = /(?:<widget\s+id=['"])(\S+)(?:['"])/;
|
||||
|
||||
var configPath = path.join(project_dir, 'config.xml');
|
||||
if (fs.existsSync(configPath)) {
|
||||
var configStr = fs.readFileSync(configPath, 'utf8');
|
||||
var res = configStr.match(widget_id_regex);
|
||||
if (res && res.length > 1) {
|
||||
pkgName = res[1];
|
||||
}
|
||||
}
|
||||
return pkgName;
|
||||
},
|
||||
'js-module': {
|
||||
install: function (jsModule, plugin_dir, plugin_id, www_dir) {
|
||||
// Copy the plugin's files into the www directory.
|
||||
var moduleSource = path.resolve(plugin_dir, jsModule.src);
|
||||
// Get module name based on existing 'name' attribute or filename
|
||||
// Must use path.extname/path.basename instead of path.parse due to CB-9981
|
||||
var moduleName = plugin_id + '.' + (jsModule.name || path.basename(jsModule.src, path.extname(jsModule.src)));
|
||||
|
||||
// Read in the file, prepend the cordova.define, and write it back out.
|
||||
var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
|
||||
if (moduleSource.match(/.*\.json$/)) {
|
||||
scriptContent = 'module.exports = ' + scriptContent;
|
||||
}
|
||||
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) { ' + scriptContent + '\n});\n';
|
||||
|
||||
var moduleDestination = path.resolve(www_dir, 'plugins', plugin_id, jsModule.src);
|
||||
shell.mkdir('-p', path.dirname(moduleDestination));
|
||||
fs.writeFileSync(moduleDestination, scriptContent, 'utf-8');
|
||||
},
|
||||
uninstall: function (jsModule, www_dir, plugin_id) {
|
||||
var pluginRelativePath = path.join('plugins', plugin_id, jsModule.src);
|
||||
// common.removeFileAndParents(www_dir, pluginRelativePath);
|
||||
console.log('js-module uninstall called : ' + pluginRelativePath);
|
||||
}
|
||||
},
|
||||
'source-file': {
|
||||
install: function (obj, plugin_dir, project_dir, plugin_id, options) {
|
||||
// var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||
// common.copyFile(plugin_dir, obj.src, project_dir, dest);
|
||||
console.log('install called');
|
||||
},
|
||||
uninstall: function (obj, project_dir, plugin_id, options) {
|
||||
// var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||
// common.removeFile(project_dir, dest);
|
||||
console.log('uninstall called');
|
||||
}
|
||||
},
|
||||
'header-file': {
|
||||
install: function (obj, plugin_dir, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'header-fileinstall is not supported for browser');
|
||||
},
|
||||
uninstall: function (obj, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'header-file.uninstall is not supported for browser');
|
||||
}
|
||||
},
|
||||
'resource-file': {
|
||||
install: function (obj, plugin_dir, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'resource-file.install is not supported for browser');
|
||||
},
|
||||
uninstall: function (obj, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'resource-file.uninstall is not supported for browser');
|
||||
}
|
||||
},
|
||||
'framework': {
|
||||
install: function (obj, plugin_dir, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'framework.install is not supported for browser');
|
||||
},
|
||||
uninstall: function (obj, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'framework.uninstall is not supported for browser');
|
||||
}
|
||||
},
|
||||
'lib-file': {
|
||||
install: function (obj, plugin_dir, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'lib-file.install is not supported for browser');
|
||||
},
|
||||
uninstall: function (obj, project_dir, plugin_id, options) {
|
||||
events.emit('verbose', 'lib-file.uninstall is not supported for browser');
|
||||
}
|
||||
},
|
||||
asset: {
|
||||
install: function (asset, plugin_dir, wwwDest) {
|
||||
var src = path.join(plugin_dir, asset.src);
|
||||
var dest = path.join(wwwDest, asset.target);
|
||||
var destDir = path.parse(dest).dir;
|
||||
if (destDir !== '' && !fs.existsSync(destDir)) {
|
||||
shell.mkdir('-p', destDir);
|
||||
}
|
||||
|
||||
if (fs.statSync(src).isDirectory()) {
|
||||
shell.cp('-Rf', src + '/*', dest);
|
||||
} else {
|
||||
shell.cp('-f', src, dest);
|
||||
}
|
||||
},
|
||||
uninstall: function (asset, wwwDest, plugin_id) {
|
||||
shell.rm('-rf', path.join(wwwDest, asset.target));
|
||||
shell.rm('-rf', path.join(wwwDest, 'plugins', plugin_id));
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var shell = require('shelljs');
|
||||
var CordovaError = require('cordova-common').CordovaError;
|
||||
var events = require('cordova-common').events;
|
||||
var FileUpdater = require('cordova-common').FileUpdater;
|
||||
|
||||
function dirExists (dir) {
|
||||
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
||||
}
|
||||
|
||||
function browser_parser (project) {
|
||||
if (!dirExists(project) || !dirExists(path.join(project, 'cordova'))) {
|
||||
throw new CordovaError('The provided path "' + project + '" is not a valid browser project.');
|
||||
}
|
||||
this.path = project;
|
||||
}
|
||||
|
||||
module.exports = browser_parser;
|
||||
|
||||
// Returns a promise.
|
||||
browser_parser.prototype.update_from_config = function () {
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
browser_parser.prototype.www_dir = function () {
|
||||
return path.join(this.path, 'www');
|
||||
};
|
||||
|
||||
// Used for creating platform_www in projects created by older versions.
|
||||
browser_parser.prototype.cordovajs_path = function (libDir) {
|
||||
var jsPath = path.join(libDir, 'cordova-lib', 'cordova.js');
|
||||
return path.resolve(jsPath);
|
||||
};
|
||||
|
||||
browser_parser.prototype.cordovajs_src_path = function (libDir) {
|
||||
// console.log("cordovajs_src_path");
|
||||
var jsPath = path.join(libDir, 'cordova-js-src');
|
||||
return path.resolve(jsPath);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs all file operations via the verbose event stream, indented.
|
||||
*/
|
||||
function logFileOp (message) {
|
||||
events.emit('verbose', ' ' + message);
|
||||
}
|
||||
|
||||
// Replace the www dir with contents of platform_www and app www.
|
||||
browser_parser.prototype.update_www = function (cordovaProject, opts) {
|
||||
var platform_www = path.join(this.path, 'platform_www');
|
||||
var my_www = this.www_dir();
|
||||
// add cordova www and platform_www to sourceDirs
|
||||
var sourceDirs = [
|
||||
path.relative(cordovaProject.root, cordovaProject.locations.www),
|
||||
path.relative(cordovaProject.root, platform_www)
|
||||
];
|
||||
|
||||
// If project contains 'merges' for our platform, use them as another overrides
|
||||
var merges_path = path.join(cordovaProject.root, 'merges', 'browser');
|
||||
if (fs.existsSync(merges_path)) {
|
||||
events.emit('verbose', 'Found "merges/browser" folder. Copying its contents into the browser project.');
|
||||
// add merges/browser to sourceDirs
|
||||
sourceDirs.push(path.join('merges', 'browser'));
|
||||
}
|
||||
|
||||
// targetDir points to browser/www
|
||||
var targetDir = path.relative(cordovaProject.root, my_www);
|
||||
events.emit('verbose', 'Merging and updating files from [' + sourceDirs.join(', ') + '] to ' + targetDir);
|
||||
FileUpdater.mergeAndUpdateDir(sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);
|
||||
};
|
||||
|
||||
browser_parser.prototype.update_overrides = function () {
|
||||
// console.log("update_overrides");
|
||||
|
||||
// TODO: ?
|
||||
// var projectRoot = util.isCordova(this.path);
|
||||
// var mergesPath = path.join(util.appDir(projectRoot), 'merges', 'browser');
|
||||
// if(fs.existsSync(mergesPath)) {
|
||||
// var overrides = path.join(mergesPath, '*');
|
||||
// shell.cp('-rf', overrides, this.www_dir());
|
||||
// }
|
||||
};
|
||||
|
||||
browser_parser.prototype.config_xml = function () {
|
||||
return path.join(this.path, 'config.xml');
|
||||
};
|
||||
|
||||
// Returns a promise.
|
||||
browser_parser.prototype.update_project = function (cfg) {
|
||||
// console.log("update_project ",cfg);
|
||||
var defer = this.update_from_config();
|
||||
var self = this;
|
||||
var www_dir = self.www_dir();
|
||||
defer.then(function () {
|
||||
self.update_overrides();
|
||||
// Copy munged config.xml to platform www dir
|
||||
shell.cp('-rf', path.join(www_dir, '..', 'config.xml'), www_dir);
|
||||
});
|
||||
return defer;
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
|
||||
var build = require('./lib/build'),
|
||||
args = process.argv;
|
||||
|
||||
// provide help
|
||||
if ( args[2] == '--help' || args[2] == '/?' || args[2] == '-h' || args[2] == '/h' ||
|
||||
args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
|
||||
build.help();
|
||||
process.exit(0);
|
||||
} else {
|
||||
|
||||
build.run();
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
|
||||
@ECHO OFF
|
||||
SET script_path="%~dp0build"
|
||||
IF EXIST %script_path% (
|
||||
node %script_path% %*
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'build' script in 'cordova' folder, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
|
||||
var path = require('path'),
|
||||
clean = require('./lib/clean'),
|
||||
args = process.argv;
|
||||
|
||||
// Support basic help commands
|
||||
if ( args.length > 2
|
||||
|| args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
|
||||
args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
|
||||
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'clean')) );
|
||||
process.exit(0);
|
||||
} else {
|
||||
clean.run();
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
|
||||
@ECHO OFF
|
||||
SET script_path="%~dp0clean"
|
||||
IF EXIST %script_path% (
|
||||
node %script_path% %*
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'clean' script in 'cordova' folder, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
||||
|
||||
</widget>
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var check_reqs = require('./check_reqs');
|
||||
|
||||
/**
|
||||
* run
|
||||
* Creates a zip file int platform/build folder
|
||||
*/
|
||||
module.exports.run = function () {
|
||||
return check_reqs.run();
|
||||
};
|
||||
|
||||
module.exports.help = function () {
|
||||
console.log('Usage: cordova build browser');
|
||||
var wwwPath = path.resolve(path.join(__dirname, '../../www'));
|
||||
console.log("Build will create the packaged app in '" + wwwPath + "'.");
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
// add methods as we determine what are the requirements
|
||||
|
||||
module.exports.run = function () {
|
||||
// caller expects a promise resolved with an array of conditions
|
||||
return Promise.resolve([]);
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var shell = require('shelljs');
|
||||
var path = require('path');
|
||||
var check_reqs = require('./check_reqs');
|
||||
var platformBuildDir = path.join('platforms', 'browser', 'www');
|
||||
|
||||
var run = function () {
|
||||
|
||||
// TODO: everything calls check_reqs ... why?
|
||||
// Check that requirements are (still) met
|
||||
if (!check_reqs.run()) {
|
||||
console.error('Please make sure you meet the software requirements in order to clean an browser cordova project');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
try {
|
||||
if (fs.existsSync(platformBuildDir)) {
|
||||
shell.rm('-r', platformBuildDir);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('could not remove ' + platformBuildDir + ' : ' + err.message);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.run = run;
|
||||
// just on the off chance something is still calling cleanProject, we will leave this here for a while
|
||||
module.exports.cleanProject = function () {
|
||||
console.log('lib/clean will soon only export a `run` command, please update to not call `cleanProject`.');
|
||||
return run();
|
||||
};
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
var cordovaServe = require('cordova-serve');
|
||||
|
||||
module.exports.run = function (args) {
|
||||
// defaults
|
||||
args.port = args.port || 8000;
|
||||
args.target = args.target || 'default'; // make default the system browser
|
||||
args.noLogOutput = args.silent || false;
|
||||
|
||||
var wwwPath = path.join(__dirname, '../../www');
|
||||
var manifestFilePath = path.resolve(path.join(wwwPath, 'manifest.json'));
|
||||
|
||||
var startPage;
|
||||
|
||||
// get start page from manifest
|
||||
if (fs.existsSync(manifestFilePath)) {
|
||||
try {
|
||||
var manifest = require(manifestFilePath);
|
||||
startPage = manifest.start_url;
|
||||
} catch (err) {
|
||||
console.log('failed to require manifest ... ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
var server = cordovaServe();
|
||||
server.servePlatform('browser', { port: args.port, noServerInfo: true, noLogOutput: args.noLogOutput })
|
||||
.then(function () {
|
||||
if (!startPage) {
|
||||
// failing all else, set the default
|
||||
startPage = 'index.html';
|
||||
}
|
||||
|
||||
var projectUrl = (new url.URL(`http://localhost:${server.port}/${startPage}`)).href;
|
||||
|
||||
console.log('startPage = ' + startPage);
|
||||
console.log('Static file server running @ ' + projectUrl + '\nCTRL + C to shut down');
|
||||
return server.launchBrowser({ 'target': args.target, 'url': projectUrl });
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error.message || error.toString());
|
||||
if (server.server) {
|
||||
server.server.close();
|
||||
}
|
||||
});
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
console.log("cordova/log");
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
nopt = require('nopt'),
|
||||
url = require('url'),
|
||||
runForrest = require('./lib/run'),
|
||||
cordovaServe = require('cordova-serve');
|
||||
|
||||
var args = process.argv;
|
||||
|
||||
start(args);
|
||||
|
||||
function start(argv) {
|
||||
var args = nopt({'help': Boolean, 'target': String, 'port': Number}, {'help': ['/?', '-h', 'help', '-help', '/help']}, argv);
|
||||
if(args.help) {
|
||||
help();
|
||||
}
|
||||
else {
|
||||
return runForrest.run(args);
|
||||
}
|
||||
}
|
||||
|
||||
function help() {
|
||||
console.log("\nUsage: run [ --target=<browser> ] [ --port=<number> ]");
|
||||
console.log(" --target=<browser> : Launches the specified browser. Chrome is default.");
|
||||
console.log(" --port=<number> : Http server uses specified port number.");
|
||||
console.log("Examples:");
|
||||
console.log(" run");
|
||||
console.log(" run -- --target=ie");
|
||||
console.log(" run -- --target=chrome --port=8000");
|
||||
console.log("");
|
||||
process.exit(0);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
|
||||
@ECHO OFF
|
||||
SET script_path="%~dp0run"
|
||||
IF EXIST %script_path% (
|
||||
node %script_path% %*
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'run' script in 'cordova' folder, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
// Coho updates this line:
|
||||
var VERSION = "6.0.0";
|
||||
|
||||
console.log(VERSION);
|
|
@ -0,0 +1,26 @@
|
|||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
|
||||
@ECHO OFF
|
||||
SET script_path="%~dp0version"
|
||||
IF EXIST %script_path% (
|
||||
node %script_path% %*
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'version' script in 'cordova' folder, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var config;
|
||||
|
||||
function Config(xhr) {
|
||||
function loadPreferences(xhr) {
|
||||
var parser = new DOMParser();
|
||||
var doc = parser.parseFromString(xhr.responseText, "application/xml");
|
||||
|
||||
var preferences = doc.getElementsByTagName("preference");
|
||||
return Array.prototype.slice.call(preferences);
|
||||
}
|
||||
|
||||
this.xhr = xhr;
|
||||
this.preferences = loadPreferences(this.xhr);
|
||||
}
|
||||
|
||||
function readConfig(success, error) {
|
||||
var xhr;
|
||||
|
||||
if(typeof config != 'undefined') {
|
||||
success(config);
|
||||
}
|
||||
|
||||
function fail(msg) {
|
||||
console.error(msg);
|
||||
|
||||
if(error) {
|
||||
error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
var xhrStatusChangeHandler = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 /* file:// */) {
|
||||
config = new Config(xhr);
|
||||
success(config);
|
||||
}
|
||||
else {
|
||||
fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", xhrStatusChangeHandler);
|
||||
|
||||
|
||||
try {
|
||||
xhr.open("get", "config.xml", true);
|
||||
xhr.send();
|
||||
} catch(e) {
|
||||
fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a preference value from config.xml.
|
||||
* Returns preference value or undefined if it does not exist.
|
||||
* @param {String} preferenceName Preference name to read */
|
||||
Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) {
|
||||
var preferenceItem = this.preferences && this.preferences.filter(function(item) {
|
||||
return item.attributes.name && item.attributes.name.value === preferenceName;
|
||||
});
|
||||
|
||||
if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
|
||||
return preferenceItem[0].attributes.value.value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.readConfig = readConfig;
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*jslint sloppy:true, plusplus:true*/
|
||||
/*global require, module, console */
|
||||
|
||||
var cordova = require('cordova');
|
||||
var execProxy = require('cordova/exec/proxy');
|
||||
|
||||
/**
|
||||
* Execute a cordova command. It is up to the native side whether this action
|
||||
* is synchronous or asynchronous. The native side can return:
|
||||
* Synchronous: PluginResult object as a JSON string
|
||||
* Asynchronous: Empty string ""
|
||||
* If async, the native side will cordova.callbackSuccess or cordova.callbackError,
|
||||
* depending upon the result of the action.
|
||||
*
|
||||
* @param {Function} success The success callback
|
||||
* @param {Function} fail The fail callback
|
||||
* @param {String} service The name of the service to use
|
||||
* @param {String} action Action to be run in cordova
|
||||
* @param {String[]} [args] Zero or more arguments to pass to the method
|
||||
*/
|
||||
module.exports = function (success, fail, service, action, args) {
|
||||
|
||||
var proxy = execProxy.get(service, action);
|
||||
|
||||
args = args || [];
|
||||
|
||||
if (proxy) {
|
||||
|
||||
var callbackId = service + cordova.callbackId++;
|
||||
|
||||
if (typeof success === "function" || typeof fail === "function") {
|
||||
cordova.callbacks[callbackId] = {success: success, fail: fail};
|
||||
}
|
||||
try {
|
||||
|
||||
|
||||
|
||||
// callbackOptions param represents additional optional parameters command could pass back, like keepCallback or
|
||||
// custom callbackId, for example {callbackId: id, keepCallback: true, status: cordova.callbackStatus.JSON_EXCEPTION }
|
||||
var onSuccess = function (result, callbackOptions) {
|
||||
callbackOptions = callbackOptions || {};
|
||||
var callbackStatus;
|
||||
// covering both undefined and null.
|
||||
// strict null comparison was causing callbackStatus to be undefined
|
||||
// and then no callback was called because of the check in cordova.callbackFromNative
|
||||
// see CB-8996 Mobilespec app hang on windows
|
||||
if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
|
||||
callbackStatus = callbackOptions.status;
|
||||
}
|
||||
else {
|
||||
callbackStatus = cordova.callbackStatus.OK;
|
||||
}
|
||||
cordova.callbackSuccess(callbackOptions.callbackId || callbackId,
|
||||
{
|
||||
status: callbackStatus,
|
||||
message: result,
|
||||
keepCallback: callbackOptions.keepCallback || false
|
||||
});
|
||||
};
|
||||
var onError = function (err, callbackOptions) {
|
||||
callbackOptions = callbackOptions || {};
|
||||
var callbackStatus;
|
||||
// covering both undefined and null.
|
||||
// strict null comparison was causing callbackStatus to be undefined
|
||||
// and then no callback was called because of the check in cordova.callbackFromNative
|
||||
// note: status can be 0
|
||||
if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
|
||||
callbackStatus = callbackOptions.status;
|
||||
}
|
||||
else {
|
||||
callbackStatus = cordova.callbackStatus.OK;
|
||||
}
|
||||
cordova.callbackError(callbackOptions.callbackId || callbackId,
|
||||
{
|
||||
status: callbackStatus,
|
||||
message: err,
|
||||
keepCallback: callbackOptions.keepCallback || false
|
||||
});
|
||||
};
|
||||
proxy(onSuccess, onError, args);
|
||||
|
||||
} catch (e) {
|
||||
console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);
|
||||
}
|
||||
} else {
|
||||
|
||||
console.log("Error: exec proxy not found for :: " + service + " :: " + action);
|
||||
|
||||
if(typeof fail === "function" ) {
|
||||
fail("Missing Command Error");
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
id: 'browser',
|
||||
cordovaVersion: '4.2.0', // cordova-js
|
||||
|
||||
bootstrap: function() {
|
||||
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var channel = require('cordova/channel');
|
||||
|
||||
modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
|
||||
|
||||
channel.onNativeReady.fire();
|
||||
|
||||
document.addEventListener("visibilitychange", function(){
|
||||
if(document.hidden) {
|
||||
channel.onPause.fire();
|
||||
}
|
||||
else {
|
||||
channel.onResume.fire();
|
||||
}
|
||||
});
|
||||
|
||||
// End of bootstrap
|
||||
}
|
||||
};
|
|
@ -0,0 +1,322 @@
|
|||
cordova.define('cordova/plugin_list', function(require, exports, module) {
|
||||
module.exports = [
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraConstants.js",
|
||||
"id": "cordova-plugin-camera.Camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"Camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js",
|
||||
"id": "cordova-plugin-camera.CameraPopoverOptions",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"CameraPopoverOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/Camera.js",
|
||||
"id": "cordova-plugin-camera.camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"navigator.camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/src/browser/CameraProxy.js",
|
||||
"id": "cordova-plugin-camera.CameraProxy",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/browser/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification_browser",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/Preparing.js",
|
||||
"id": "cordova-plugin-file.Preparing",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/src/browser/FileProxy.js",
|
||||
"id": "cordova-plugin-file.browserFileProxy",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/FileSystem.js",
|
||||
"id": "cordova-plugin-file.firefoxFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureAudioOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureAudioOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureAudioOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureImageOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureImageOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureImageOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureVideoOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureVideoOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureVideoOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureError.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureError",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFileData.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFileData",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFileData"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFile.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFile",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/helpers.js",
|
||||
"id": "cordova-plugin-media-capture.helpers",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/capture.js",
|
||||
"id": "cordova-plugin-media-capture.capture",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"navigator.device.capture"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/src/browser/CaptureProxy.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureProxy",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/www/barcodescanner.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScanner",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"clobbers": [
|
||||
"cordova.plugins.barcodeScanner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/src/browser/BarcodeScannerProxy.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScannerProxy",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
// TOP OF METADATA
|
||||
{
|
||||
"cordova-plugin-camera": "4.0.3",
|
||||
"cordova-plugin-dialogs": "2.0.1",
|
||||
"cordova-plugin-file": "6.0.1",
|
||||
"cordova-plugin-media-capture": "3.0.2",
|
||||
"cordova-plugin-whitelist": "1.3.3",
|
||||
"phonegap-plugin-barcodescanner": "8.0.1"
|
||||
}
|
||||
// BOTTOM OF METADATA
|
||||
});
|
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "Nature Photo",
|
||||
"short_name": "Nature Photo",
|
||||
"description": "Description of your app from template",
|
||||
"start_url": "index.html",
|
||||
"scope": "index.html",
|
||||
"icons": [
|
||||
{
|
||||
"src": "img/logo.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "img/splash.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"default_locale": "en",
|
||||
"display": "standalone",
|
||||
"background_color": "#FFF",
|
||||
"theme_color": "#000",
|
||||
"orientation": "landscape"
|
||||
}
|
125
platforms/browser/platform_www/plugins/cordova-plugin-camera/src/browser/CameraProxy.js
vendored
Normal file
|
@ -0,0 +1,125 @@
|
|||
cordova.define("cordova-plugin-camera.CameraProxy", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var 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');
|
||||
input.style.position = 'relative';
|
||||
input.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX;
|
||||
input.className = 'cordova-camera-select';
|
||||
input.type = 'file';
|
||||
input.name = 'files[]';
|
||||
|
||||
input.onchange = function (inputEvent) {
|
||||
var reader = new FileReader(); /* eslint no-undef : 0 */
|
||||
reader.onload = function (readerEvent) {
|
||||
input.parentNode.removeChild(input);
|
||||
|
||||
var imageData = readerEvent.target.result;
|
||||
|
||||
return success(imageData.substr(imageData.indexOf(',') + 1));
|
||||
};
|
||||
|
||||
reader.readAsDataURL(inputEvent.target.files[0]);
|
||||
};
|
||||
|
||||
document.body.appendChild(input);
|
||||
}
|
||||
}
|
||||
|
||||
function capture (success, errorCallback, opts) {
|
||||
var localMediaStream;
|
||||
var targetWidth = opts[3];
|
||||
var 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');
|
||||
parent.style.position = 'relative';
|
||||
parent.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX;
|
||||
parent.className = 'cordova-camera-capture';
|
||||
parent.appendChild(video);
|
||||
parent.appendChild(button);
|
||||
|
||||
video.width = targetWidth;
|
||||
video.height = targetHeight;
|
||||
button.innerHTML = 'Capture!';
|
||||
|
||||
button.onclick = function () {
|
||||
// create a canvas and capture a frame from video stream
|
||||
var 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');
|
||||
imageData = imageData.replace('data:image/png;base64,', '');
|
||||
|
||||
// stop video stream, remove video and button.
|
||||
// Note that MediaStream.stop() is deprecated as of Chrome 47.
|
||||
if (localMediaStream.stop) {
|
||||
localMediaStream.stop();
|
||||
} else {
|
||||
localMediaStream.getTracks().forEach(function (track) {
|
||||
track.stop();
|
||||
});
|
||||
}
|
||||
parent.parentNode.removeChild(parent);
|
||||
|
||||
return success(imageData);
|
||||
};
|
||||
|
||||
navigator.getUserMedia = navigator.getUserMedia ||
|
||||
navigator.webkitGetUserMedia ||
|
||||
navigator.mozGetUserMedia ||
|
||||
navigator.msGetUserMedia;
|
||||
|
||||
var successCallback = function (stream) {
|
||||
localMediaStream = stream;
|
||||
video.src = window.URL.createObjectURL(localMediaStream);
|
||||
video.play();
|
||||
|
||||
document.body.appendChild(parent);
|
||||
};
|
||||
|
||||
if (navigator.getUserMedia) {
|
||||
navigator.getUserMedia({video: true, audio: true}, successCallback, errorCallback);
|
||||
} else {
|
||||
alert('Browser does not support camera :(');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
takePicture: takePicture,
|
||||
cleanup: function () {}
|
||||
};
|
||||
|
||||
require('cordova/exec/proxy').add('Camera', module.exports);
|
||||
|
||||
});
|
|
@ -0,0 +1,187 @@
|
|||
cordova.define("cordova-plugin-camera.camera", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck');
|
||||
var exec = require('cordova/exec');
|
||||
var Camera = require('./Camera');
|
||||
// XXX: commented out
|
||||
// CameraPopoverHandle = require('./CameraPopoverHandle');
|
||||
|
||||
/**
|
||||
* @namespace navigator
|
||||
*/
|
||||
|
||||
/**
|
||||
* @exports camera
|
||||
*/
|
||||
var cameraExport = {};
|
||||
|
||||
// Tack on the Camera Constants to the base camera plugin.
|
||||
for (var key in Camera) {
|
||||
cameraExport[key] = Camera[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function that provides an error message.
|
||||
* @callback module:camera.onError
|
||||
* @param {string} message - The message is provided by the device's native code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback function that provides the image data.
|
||||
* @callback module:camera.onSuccess
|
||||
* @param {string} imageData - Base64 encoding of the image data, _or_ the image file URI, depending on [`cameraOptions`]{@link module:camera.CameraOptions} in effect.
|
||||
* @example
|
||||
* // Show image
|
||||
* //
|
||||
* function cameraCallback(imageData) {
|
||||
* var image = document.getElementById('myImage');
|
||||
* image.src = "data:image/jpeg;base64," + imageData;
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Optional parameters to customize the camera settings.
|
||||
* * [Quirks](#CameraOptions-quirks)
|
||||
* @typedef module:camera.CameraOptions
|
||||
* @type {Object}
|
||||
* @property {number} [quality=50] - Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera's resolution is unavailable.)
|
||||
* @property {module:Camera.DestinationType} [destinationType=FILE_URI] - Choose the format of the return value.
|
||||
* @property {module:Camera.PictureSourceType} [sourceType=CAMERA] - Set the source of the picture.
|
||||
* @property {Boolean} [allowEdit=false] - Allow simple editing of image before selection.
|
||||
* @property {module:Camera.EncodingType} [encodingType=JPEG] - Choose the returned image file's encoding.
|
||||
* @property {number} [targetWidth] - Width in pixels to scale image. Must be used with `targetHeight`. Aspect ratio remains constant.
|
||||
* @property {number} [targetHeight] - Height in pixels to scale image. Must be used with `targetWidth`. Aspect ratio remains constant.
|
||||
* @property {module:Camera.MediaType} [mediaType=PICTURE] - Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`.
|
||||
* @property {Boolean} [correctOrientation] - Rotate the image to correct for the orientation of the device during capture.
|
||||
* @property {Boolean} [saveToPhotoAlbum] - Save the image to the photo album on the device after capture.
|
||||
* @property {module:CameraPopoverOptions} [popoverOptions] - iOS-only options that specify popover location in iPad.
|
||||
* @property {module:Camera.Direction} [cameraDirection=BACK] - Choose the camera to use (front- or back-facing).
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Takes a photo using the camera, or retrieves a photo from the device's
|
||||
* image gallery. The image is passed to the success callback as a
|
||||
* Base64-encoded `String`, or as the URI for the image file.
|
||||
*
|
||||
* The `camera.getPicture` function opens the device's default camera
|
||||
* application that allows users to snap pictures by default - this behavior occurs,
|
||||
* when `Camera.sourceType` equals [`Camera.PictureSourceType.CAMERA`]{@link module:Camera.PictureSourceType}.
|
||||
* Once the user snaps the photo, the camera application closes and the application is restored.
|
||||
*
|
||||
* If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or
|
||||
* `Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays
|
||||
* that allows users to select an existing image.
|
||||
*
|
||||
* The return value is sent to the [`cameraSuccess`]{@link module:camera.onSuccess} callback function, in
|
||||
* one of the following formats, depending on the specified
|
||||
* `cameraOptions`:
|
||||
*
|
||||
* - A `String` containing the Base64-encoded photo image.
|
||||
* - A `String` representing the image file location on local storage (default).
|
||||
*
|
||||
* You can do whatever you want with the encoded image or URI, for
|
||||
* example:
|
||||
*
|
||||
* - Render the image in an `<img>` tag, as in the example below
|
||||
* - Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.)
|
||||
* - Post the data to a remote server
|
||||
*
|
||||
* __NOTE__: Photo resolution on newer devices is quite good. Photos
|
||||
* selected from the device's gallery are not downscaled to a lower
|
||||
* quality, even if a `quality` parameter is specified. To avoid common
|
||||
* memory problems, set `Camera.destinationType` to `FILE_URI` rather
|
||||
* than `DATA_URL`.
|
||||
*
|
||||
* __Supported Platforms__
|
||||
*
|
||||
* - Android
|
||||
* - BlackBerry
|
||||
* - Browser
|
||||
* - Firefox
|
||||
* - FireOS
|
||||
* - iOS
|
||||
* - Windows
|
||||
* - WP8
|
||||
* - Ubuntu
|
||||
*
|
||||
* More examples [here](#camera-getPicture-examples). Quirks [here](#camera-getPicture-quirks).
|
||||
*
|
||||
* @example
|
||||
* navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
|
||||
* @param {module:camera.onSuccess} successCallback
|
||||
* @param {module:camera.onError} errorCallback
|
||||
* @param {module:camera.CameraOptions} options CameraOptions
|
||||
*/
|
||||
cameraExport.getPicture = function (successCallback, errorCallback, options) {
|
||||
argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);
|
||||
options = options || {};
|
||||
var 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);
|
||||
|
||||
var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
|
||||
mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection];
|
||||
|
||||
exec(successCallback, errorCallback, 'Camera', 'takePicture', args);
|
||||
// XXX: commented out
|
||||
// return new CameraPopoverHandle();
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes intermediate image files that are kept in temporary storage
|
||||
* after calling [`camera.getPicture`]{@link module:camera.getPicture}. Applies only when the value of
|
||||
* `Camera.sourceType` equals `Camera.PictureSourceType.CAMERA` and the
|
||||
* `Camera.destinationType` equals `Camera.DestinationType.FILE_URI`.
|
||||
*
|
||||
* __Supported Platforms__
|
||||
*
|
||||
* - iOS
|
||||
*
|
||||
* @example
|
||||
* navigator.camera.cleanup(onSuccess, onFail);
|
||||
*
|
||||
* function onSuccess() {
|
||||
* console.log("Camera cleanup success.")
|
||||
* }
|
||||
*
|
||||
* function onFail(message) {
|
||||
* alert('Failed because: ' + message);
|
||||
* }
|
||||
*/
|
||||
cameraExport.cleanup = function (successCallback, errorCallback) {
|
||||
exec(successCallback, errorCallback, 'Camera', 'cleanup', []);
|
||||
};
|
||||
|
||||
module.exports = cameraExport;
|
||||
|
||||
});
|
103
platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraConstants.js
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
cordova.define("cordova-plugin-camera.Camera", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module Camera
|
||||
*/
|
||||
module.exports = {
|
||||
/**
|
||||
* @description
|
||||
* Defines the output format of `Camera.getPicture` call.
|
||||
* _Note:_ On iOS passing `DestinationType.NATIVE_URI` along with
|
||||
* `PictureSourceType.PHOTOLIBRARY` or `PictureSourceType.SAVEDPHOTOALBUM` will
|
||||
* disable any image modifications (resize, quality change, cropping, etc.) due
|
||||
* to implementation specific.
|
||||
*
|
||||
* @enum {number}
|
||||
*/
|
||||
DestinationType: {
|
||||
/** Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible */
|
||||
DATA_URL: 0,
|
||||
/** Return file uri (content://media/external/images/media/2 for Android) */
|
||||
FILE_URI: 1,
|
||||
/** Return native uri (eg. asset-library://... for iOS) */
|
||||
NATIVE_URI: 2
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
EncodingType: {
|
||||
/** Return JPEG encoded image */
|
||||
JPEG: 0,
|
||||
/** Return PNG encoded image */
|
||||
PNG: 1
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
MediaType: {
|
||||
/** Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType */
|
||||
PICTURE: 0,
|
||||
/** Allow selection of video only, ONLY RETURNS URL */
|
||||
VIDEO: 1,
|
||||
/** Allow selection from all media types */
|
||||
ALLMEDIA: 2
|
||||
},
|
||||
/**
|
||||
* @description
|
||||
* Defines the output format of `Camera.getPicture` call.
|
||||
* _Note:_ On iOS passing `PictureSourceType.PHOTOLIBRARY` or `PictureSourceType.SAVEDPHOTOALBUM`
|
||||
* along with `DestinationType.NATIVE_URI` will disable any image modifications (resize, quality
|
||||
* change, cropping, etc.) due to implementation specific.
|
||||
*
|
||||
* @enum {number}
|
||||
*/
|
||||
PictureSourceType: {
|
||||
/** Choose image from the device's photo library (same as SAVEDPHOTOALBUM for Android) */
|
||||
PHOTOLIBRARY: 0,
|
||||
/** Take picture from camera */
|
||||
CAMERA: 1,
|
||||
/** Choose image only from the device's Camera Roll album (same as PHOTOLIBRARY for Android) */
|
||||
SAVEDPHOTOALBUM: 2
|
||||
},
|
||||
/**
|
||||
* Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover.
|
||||
* @enum {number}
|
||||
*/
|
||||
PopoverArrowDirection: {
|
||||
ARROW_UP: 1,
|
||||
ARROW_DOWN: 2,
|
||||
ARROW_LEFT: 4,
|
||||
ARROW_RIGHT: 8,
|
||||
ARROW_ANY: 15
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
Direction: {
|
||||
/** Use the back-facing camera */
|
||||
BACK: 0,
|
||||
/** Use the front-facing camera */
|
||||
FRONT: 1
|
||||
}
|
||||
};
|
||||
|
||||
});
|
54
platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraPopoverOptions.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
cordova.define("cordova-plugin-camera.CameraPopoverOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var Camera = require('./Camera');
|
||||
|
||||
/**
|
||||
* @namespace navigator
|
||||
*/
|
||||
|
||||
/**
|
||||
* iOS-only parameters that specify the anchor element location and arrow
|
||||
* direction of the popover when selecting images from an iPad's library
|
||||
* or album.
|
||||
* Note that the size of the popover may change to adjust to the
|
||||
* direction of the arrow and orientation of the screen. Make sure to
|
||||
* account for orientation changes when specifying the anchor element
|
||||
* location.
|
||||
* @module CameraPopoverOptions
|
||||
* @param {Number} [x=0] - x pixel coordinate of screen element onto which to anchor the popover.
|
||||
* @param {Number} [y=32] - y pixel coordinate of screen element onto which to anchor the popover.
|
||||
* @param {Number} [width=320] - width, in pixels, of the screen element onto which to anchor the popover.
|
||||
* @param {Number} [height=480] - height, in pixels, of the screen element onto which to anchor the popover.
|
||||
* @param {module:Camera.PopoverArrowDirection} [arrowDir=ARROW_ANY] - Direction the arrow on the popover should point.
|
||||
*/
|
||||
var CameraPopoverOptions = function (x, y, width, height, arrowDir) {
|
||||
// information of rectangle that popover should be anchored to
|
||||
this.x = x || 0;
|
||||
this.y = y || 32;
|
||||
this.width = width || 320;
|
||||
this.height = height || 480;
|
||||
this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY;
|
||||
};
|
||||
|
||||
module.exports = CameraPopoverOptions;
|
||||
|
||||
});
|
112
platforms/browser/platform_www/plugins/cordova-plugin-dialogs/www/browser/notification.js
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
cordova.define("cordova-plugin-dialogs.notification_browser", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Platform: browser
|
||||
window.navigator.notification = window.navigator.notification || {};
|
||||
|
||||
module.exports.alert = window.navigator.notification.alert = function (message, callback) {
|
||||
// `notification.alert` executes asynchronously
|
||||
setTimeout(function () {
|
||||
window.alert(message);
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
|
||||
module.exports.confirm = window.navigator.notification.confirm = function (message, callback) {
|
||||
// `notification.confirm` executes asynchronously
|
||||
/* eslint-disable standard/no-callback-literal */
|
||||
setTimeout(function () {
|
||||
var result = window.confirm(message);
|
||||
if (callback) {
|
||||
if (result) {
|
||||
callback(1); // OK
|
||||
} else {
|
||||
callback(2); // Cancel
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
|
||||
module.exports.prompt = window.navigator.notification.prompt = function (message, callback, title, buttonLabels, defaultText) {
|
||||
// `notification.prompt` executes asynchronously
|
||||
setTimeout(function () {
|
||||
var result = window.prompt(message, defaultText || '');
|
||||
if (callback) {
|
||||
if (result === null) {
|
||||
callback({ buttonIndex: 2, input1: '' }); // Cancel
|
||||
} else {
|
||||
callback({ buttonIndex: 1, input1: result }); // OK
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
/* eslint-enable standard/no-callback-literal */
|
||||
var audioContext = (function () {
|
||||
// Determine if the Audio API is supported by this browser
|
||||
var AudioApi = window.AudioContext;
|
||||
if (!AudioApi) {
|
||||
AudioApi = window.webkitAudioContext;
|
||||
}
|
||||
|
||||
if (AudioApi) {
|
||||
// The Audio API is supported, so create a singleton instance of the AudioContext
|
||||
return new AudioApi();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}());
|
||||
|
||||
module.exports.beep = window.navigator.notification.beep = function (times) {
|
||||
if (times > 0) {
|
||||
var BEEP_DURATION = 700;
|
||||
var BEEP_INTERVAL = 300;
|
||||
|
||||
if (audioContext) {
|
||||
// Start a beep, using the Audio API
|
||||
var osc = audioContext.createOscillator();
|
||||
osc.type = 0; // sounds like a "beep"
|
||||
osc.connect(audioContext.destination);
|
||||
osc.start(0);
|
||||
|
||||
setTimeout(function () {
|
||||
// Stop the beep after the BEEP_DURATION
|
||||
osc.stop(0);
|
||||
|
||||
if (--times > 0) {
|
||||
// Beep again, after a pause
|
||||
setTimeout(function () {
|
||||
navigator.notification.beep(times);
|
||||
}, BEEP_INTERVAL);
|
||||
}
|
||||
|
||||
}, BEEP_DURATION);
|
||||
} else if (typeof (console) !== 'undefined' && typeof (console.log) === 'function') {
|
||||
// Audio API isn't supported, so just write `beep` to the console
|
||||
for (var i = 0; i < times; i++) {
|
||||
console.log('Beep!');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
132
platforms/browser/platform_www/plugins/cordova-plugin-dialogs/www/notification.js
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
cordova.define("cordova-plugin-dialogs.notification", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var platform = require('cordova/platform');
|
||||
|
||||
/**
|
||||
* Provides access to notifications on the device.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* Open a native alert dialog, with a customizable title and button text.
|
||||
*
|
||||
* @param {String} message Message to print in the body of the alert
|
||||
* @param {Function} completeCallback The callback that is called when user clicks on a button.
|
||||
* @param {String} title Title of the alert dialog (default: Alert)
|
||||
* @param {String} buttonLabel Label of the close button (default: OK)
|
||||
*/
|
||||
alert: function (message, completeCallback, title, buttonLabel) {
|
||||
var _message = (typeof message === 'string' ? message : JSON.stringify(message));
|
||||
var _title = (typeof title === 'string' ? title : 'Alert');
|
||||
var _buttonLabel = (buttonLabel && typeof buttonLabel === 'string' ? buttonLabel : 'OK');
|
||||
exec(completeCallback, null, 'Notification', 'alert', [_message, _title, _buttonLabel]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Open a native confirm dialog, with a customizable title and button text.
|
||||
* The result that the user selects is returned to the result callback.
|
||||
*
|
||||
* @param {String} message Message to print in the body of the alert
|
||||
* @param {Function} resultCallback The callback that is called when user clicks on a button.
|
||||
* @param {String} title Title of the alert dialog (default: Confirm)
|
||||
* @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel'])
|
||||
*/
|
||||
confirm: function (message, resultCallback, title, buttonLabels) {
|
||||
var _message = (typeof message === 'string' ? message : JSON.stringify(message));
|
||||
var _title = (typeof title === 'string' ? title : 'Confirm');
|
||||
var _buttonLabels = (buttonLabels || ['OK', 'Cancel']);
|
||||
|
||||
// Strings are deprecated!
|
||||
if (typeof _buttonLabels === 'string') {
|
||||
console.log('Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).');
|
||||
}
|
||||
|
||||
_buttonLabels = convertButtonLabels(_buttonLabels);
|
||||
|
||||
exec(resultCallback, null, 'Notification', 'confirm', [_message, _title, _buttonLabels]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Open a native prompt dialog, with a customizable title and button text.
|
||||
* The following results are returned to the result callback:
|
||||
* buttonIndex Index number of the button selected.
|
||||
* input1 The text entered in the prompt dialog box.
|
||||
*
|
||||
* @param {String} message Dialog message to display (default: "Prompt message")
|
||||
* @param {Function} resultCallback The callback that is called when user clicks on a button.
|
||||
* @param {String} title Title of the dialog (default: "Prompt")
|
||||
* @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
|
||||
* @param {String} defaultText Textbox input value (default: empty string)
|
||||
*/
|
||||
prompt: function (message, resultCallback, title, buttonLabels, defaultText) {
|
||||
var _message = (typeof message === 'string' ? message : JSON.stringify(message));
|
||||
var _title = (typeof title === 'string' ? title : 'Prompt');
|
||||
var _buttonLabels = (buttonLabels || ['OK', 'Cancel']);
|
||||
|
||||
// Strings are deprecated!
|
||||
if (typeof _buttonLabels === 'string') {
|
||||
console.log('Notification.prompt(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).');
|
||||
}
|
||||
|
||||
_buttonLabels = convertButtonLabels(_buttonLabels);
|
||||
|
||||
var _defaultText = (defaultText || '');
|
||||
exec(resultCallback, null, 'Notification', 'prompt', [_message, _title, _buttonLabels, _defaultText]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Causes the device to beep.
|
||||
* On Android, the default notification ringtone is played "count" times.
|
||||
*
|
||||
* @param {Integer} count The number of beeps.
|
||||
*/
|
||||
beep: function (count) {
|
||||
var defaultedCount = count || 1;
|
||||
exec(null, null, 'Notification', 'beep', [ defaultedCount ]);
|
||||
}
|
||||
};
|
||||
|
||||
function convertButtonLabels (buttonLabels) {
|
||||
|
||||
// Some platforms take an array of button label names.
|
||||
// Other platforms take a comma separated list.
|
||||
// For compatibility, we convert to the desired type based on the platform.
|
||||
if (platform.id === 'amazon-fireos' || platform.id === 'android' || platform.id === 'ios' ||
|
||||
platform.id === 'windowsphone' || platform.id === 'firefoxos' || platform.id === 'ubuntu' ||
|
||||
platform.id === 'windows8' || platform.id === 'windows') {
|
||||
|
||||
if (typeof buttonLabels === 'string') {
|
||||
buttonLabels = buttonLabels.split(','); // not crazy about changing the var type here
|
||||
}
|
||||
} else {
|
||||
if (Array.isArray(buttonLabels)) {
|
||||
var buttonLabelArray = buttonLabels;
|
||||
buttonLabels = buttonLabelArray.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return buttonLabels;
|
||||
}
|
||||
|
||||
});
|
986
platforms/browser/platform_www/plugins/cordova-plugin-file/src/browser/FileProxy.js
vendored
Normal file
|
@ -0,0 +1,986 @@
|
|||
cordova.define("cordova-plugin-file.browserFileProxy", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
/* global require, exports, module */
|
||||
/* global FILESYSTEM_PREFIX */
|
||||
/* global IDBKeyRange */
|
||||
|
||||
/* Heavily based on https://github.com/ebidel/idb.filesystem.js */
|
||||
|
||||
// For chrome we don't need to implement proxy methods
|
||||
// All functionality can be accessed natively.
|
||||
if (require('./isChrome')()) {
|
||||
var pathsPrefix = {
|
||||
// Read-only directory where the application is installed.
|
||||
applicationDirectory: location.origin + '/', // eslint-disable-line no-undef
|
||||
// Where to put app-specific data files.
|
||||
dataDirectory: 'filesystem:file:///persistent/',
|
||||
// Cached files that should survive app restarts.
|
||||
// Apps should not rely on the OS to delete files in here.
|
||||
cacheDirectory: 'filesystem:file:///temporary/'
|
||||
};
|
||||
|
||||
exports.requestAllPaths = function (successCallback) {
|
||||
successCallback(pathsPrefix);
|
||||
};
|
||||
|
||||
require('cordova/exec/proxy').add('File', module.exports);
|
||||
return;
|
||||
}
|
||||
|
||||
var LocalFileSystem = require('./LocalFileSystem');
|
||||
var FileSystem = require('./FileSystem');
|
||||
var FileEntry = require('./FileEntry');
|
||||
var FileError = require('./FileError');
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
var File = require('./File');
|
||||
|
||||
(function (exports, global) {
|
||||
var indexedDB = global.indexedDB || global.mozIndexedDB;
|
||||
if (!indexedDB) {
|
||||
throw 'Firefox OS File plugin: indexedDB not supported';
|
||||
}
|
||||
|
||||
var fs_ = null;
|
||||
|
||||
var idb_ = {};
|
||||
idb_.db = null;
|
||||
var FILE_STORE_ = 'entries';
|
||||
|
||||
var DIR_SEPARATOR = '/';
|
||||
|
||||
var pathsPrefix = {
|
||||
// Read-only directory where the application is installed.
|
||||
applicationDirectory: location.origin + '/', // eslint-disable-line no-undef
|
||||
// Where to put app-specific data files.
|
||||
dataDirectory: 'file:///persistent/',
|
||||
// Cached files that should survive app restarts.
|
||||
// Apps should not rely on the OS to delete files in here.
|
||||
cacheDirectory: 'file:///temporary/'
|
||||
};
|
||||
|
||||
var unicodeLastChar = 65535;
|
||||
|
||||
/** * Exported functionality ***/
|
||||
|
||||
exports.requestFileSystem = function (successCallback, errorCallback, args) {
|
||||
var type = args[0];
|
||||
// Size is ignored since IDB filesystem size depends
|
||||
// on browser implementation and can't be set up by user
|
||||
var size = args[1]; // eslint-disable-line no-unused-vars
|
||||
|
||||
if (type !== LocalFileSystem.TEMPORARY && type !== LocalFileSystem.PERSISTENT) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var name = type === LocalFileSystem.TEMPORARY ? 'temporary' : 'persistent';
|
||||
var storageName = (location.protocol + location.host).replace(/:/g, '_'); // eslint-disable-line no-undef
|
||||
|
||||
var root = new DirectoryEntry('', DIR_SEPARATOR);
|
||||
fs_ = new FileSystem(name, root);
|
||||
|
||||
idb_.open(storageName, function () {
|
||||
successCallback(fs_);
|
||||
}, errorCallback);
|
||||
};
|
||||
|
||||
// Overridden by Android, BlackBerry 10 and iOS to populate fsMap
|
||||
require('./fileSystems').getFs = function (name, callback) {
|
||||
callback(new FileSystem(name, fs_.root));
|
||||
};
|
||||
|
||||
// list a directory's contents (files and folders).
|
||||
exports.readEntries = function (successCallback, errorCallback, args) {
|
||||
var fullPath = args[0];
|
||||
|
||||
if (typeof successCallback !== 'function') {
|
||||
throw Error('Expected successCallback argument.');
|
||||
}
|
||||
|
||||
var path = resolveToFullPath_(fullPath);
|
||||
|
||||
exports.getDirectory(function () {
|
||||
idb_.getAllEntries(path.fullPath + DIR_SEPARATOR, path.storagePath, function (entries) {
|
||||
successCallback(entries);
|
||||
}, errorCallback);
|
||||
}, function () {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
}, [path.storagePath, path.fullPath, {create: false}]);
|
||||
};
|
||||
|
||||
exports.getFile = function (successCallback, errorCallback, args) {
|
||||
var fullPath = args[0];
|
||||
var path = args[1];
|
||||
var options = args[2] || {};
|
||||
|
||||
// Create an absolute path if we were handed a relative one.
|
||||
path = resolveToFullPath_(fullPath, path);
|
||||
|
||||
idb_.get(path.storagePath, function (fileEntry) {
|
||||
if (options.create === true && options.exclusive === true && fileEntry) {
|
||||
// If create and exclusive are both true, and the path already exists,
|
||||
// getFile must fail.
|
||||
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.PATH_EXISTS_ERR);
|
||||
}
|
||||
} else if (options.create === true && !fileEntry) {
|
||||
// If create is true, the path doesn't exist, and no other error occurs,
|
||||
// getFile must create it as a zero-length file and return a corresponding
|
||||
// FileEntry.
|
||||
var newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
|
||||
|
||||
newFileEntry.file_ = new MyFile({
|
||||
size: 0,
|
||||
name: newFileEntry.name,
|
||||
lastModifiedDate: new Date(),
|
||||
storagePath: path.storagePath
|
||||
});
|
||||
|
||||
idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback);
|
||||
} else if (options.create === true && fileEntry) {
|
||||
if (fileEntry.isFile) {
|
||||
// Overwrite file, delete then create new.
|
||||
idb_['delete'](path.storagePath, function () {
|
||||
var newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
|
||||
|
||||
newFileEntry.file_ = new MyFile({
|
||||
size: 0,
|
||||
name: newFileEntry.name,
|
||||
lastModifiedDate: new Date(),
|
||||
storagePath: path.storagePath
|
||||
});
|
||||
|
||||
idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback);
|
||||
}, errorCallback);
|
||||
} else {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
}
|
||||
} else if ((!options.create || options.create === false) && !fileEntry) {
|
||||
// If create is not true and the path doesn't exist, getFile must fail.
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
} else if ((!options.create || options.create === false) && fileEntry &&
|
||||
fileEntry.isDirectory) {
|
||||
// If create is not true and the path exists, but is a directory, getFile
|
||||
// must fail.
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.TYPE_MISMATCH_ERR);
|
||||
}
|
||||
} else {
|
||||
// Otherwise, if no other error occurs, getFile must return a FileEntry
|
||||
// corresponding to path.
|
||||
|
||||
successCallback(fileEntryFromIdbEntry(fileEntry));
|
||||
}
|
||||
}, errorCallback);
|
||||
};
|
||||
|
||||
exports.getFileMetadata = function (successCallback, errorCallback, args) {
|
||||
var fullPath = args[0];
|
||||
|
||||
exports.getFile(function (fileEntry) {
|
||||
successCallback(new File(fileEntry.file_.name, fileEntry.fullPath, '', fileEntry.file_.lastModifiedDate,
|
||||
fileEntry.file_.size));
|
||||
}, errorCallback, [fullPath, null]);
|
||||
};
|
||||
|
||||
exports.getMetadata = function (successCallback, errorCallback, args) {
|
||||
exports.getFile(function (fileEntry) {
|
||||
successCallback(
|
||||
{
|
||||
modificationTime: fileEntry.file_.lastModifiedDate,
|
||||
size: fileEntry.file_.lastModifiedDate
|
||||
});
|
||||
}, errorCallback, args);
|
||||
};
|
||||
|
||||
exports.setMetadata = function (successCallback, errorCallback, args) {
|
||||
var fullPath = args[0];
|
||||
var metadataObject = args[1];
|
||||
|
||||
exports.getFile(function (fileEntry) {
|
||||
fileEntry.file_.lastModifiedDate = metadataObject.modificationTime;
|
||||
idb_.put(fileEntry, fileEntry.file_.storagePath, successCallback, errorCallback);
|
||||
}, errorCallback, [fullPath, null]);
|
||||
};
|
||||
|
||||
exports.write = function (successCallback, errorCallback, args) {
|
||||
var fileName = args[0];
|
||||
var data = args[1];
|
||||
var position = args[2];
|
||||
var isBinary = args[3]; // eslint-disable-line no-unused-vars
|
||||
|
||||
if (!data) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof data === 'string' || data instanceof String) {
|
||||
data = new Blob([data]); // eslint-disable-line no-undef
|
||||
}
|
||||
|
||||
exports.getFile(function (fileEntry) {
|
||||
var blob_ = fileEntry.file_.blob_;
|
||||
|
||||
if (!blob_) {
|
||||
blob_ = new Blob([data], {type: data.type}); // eslint-disable-line no-undef
|
||||
} else {
|
||||
// Calc the head and tail fragments
|
||||
var head = blob_.slice(0, position);
|
||||
var tail = blob_.slice(position + (data.size || data.byteLength));
|
||||
|
||||
// Calc the padding
|
||||
var padding = position - head.size;
|
||||
if (padding < 0) {
|
||||
padding = 0;
|
||||
}
|
||||
|
||||
// Do the "write". In fact, a full overwrite of the Blob.
|
||||
blob_ = new Blob([head, new Uint8Array(padding), data, tail], // eslint-disable-line no-undef
|
||||
{type: data.type});
|
||||
}
|
||||
|
||||
// Set the blob we're writing on this file entry so we can recall it later.
|
||||
fileEntry.file_.blob_ = blob_;
|
||||
fileEntry.file_.lastModifiedDate = new Date() || null;
|
||||
fileEntry.file_.size = blob_.size;
|
||||
fileEntry.file_.name = blob_.name;
|
||||
fileEntry.file_.type = blob_.type;
|
||||
|
||||
idb_.put(fileEntry, fileEntry.file_.storagePath, function () {
|
||||
successCallback(data.size || data.byteLength);
|
||||
}, errorCallback);
|
||||
}, errorCallback, [fileName, null]);
|
||||
};
|
||||
|
||||
exports.readAsText = function (successCallback, errorCallback, args) {
|
||||
var fileName = args[0];
|
||||
var enc = args[1];
|
||||
var startPos = args[2];
|
||||
var endPos = args[3];
|
||||
|
||||
readAs('text', fileName, enc, startPos, endPos, successCallback, errorCallback);
|
||||
};
|
||||
|
||||
exports.readAsDataURL = function (successCallback, errorCallback, args) {
|
||||
var fileName = args[0];
|
||||
var startPos = args[1];
|
||||
var endPos = args[2];
|
||||
|
||||
readAs('dataURL', fileName, null, startPos, endPos, successCallback, errorCallback);
|
||||
};
|
||||
|
||||
exports.readAsBinaryString = function (successCallback, errorCallback, args) {
|
||||
var fileName = args[0];
|
||||
var startPos = args[1];
|
||||
var endPos = args[2];
|
||||
|
||||
readAs('binaryString', fileName, null, startPos, endPos, successCallback, errorCallback);
|
||||
};
|
||||
|
||||
exports.readAsArrayBuffer = function (successCallback, errorCallback, args) {
|
||||
var fileName = args[0];
|
||||
var startPos = args[1];
|
||||
var endPos = args[2];
|
||||
|
||||
readAs('arrayBuffer', fileName, null, startPos, endPos, successCallback, errorCallback);
|
||||
};
|
||||
|
||||
exports.removeRecursively = exports.remove = function (successCallback, errorCallback, args) {
|
||||
if (typeof successCallback !== 'function') {
|
||||
throw Error('Expected successCallback argument.');
|
||||
}
|
||||
|
||||
var fullPath = resolveToFullPath_(args[0]).storagePath;
|
||||
if (fullPath === pathsPrefix.cacheDirectory || fullPath === pathsPrefix.dataDirectory) {
|
||||
errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
function deleteEntry (isDirectory) {
|
||||
// TODO: This doesn't protect against directories that have content in it.
|
||||
// Should throw an error instead if the dirEntry is not empty.
|
||||
idb_['delete'](fullPath, function () {
|
||||
successCallback();
|
||||
}, function () {
|
||||
if (errorCallback) { errorCallback(); }
|
||||
}, isDirectory);
|
||||
}
|
||||
|
||||
// We need to to understand what we are deleting:
|
||||
exports.getDirectory(function (entry) {
|
||||
deleteEntry(entry.isDirectory);
|
||||
}, function () {
|
||||
// DirectoryEntry was already deleted or entry is FileEntry
|
||||
deleteEntry(false);
|
||||
}, [fullPath, null, {create: false}]);
|
||||
};
|
||||
|
||||
exports.getDirectory = function (successCallback, errorCallback, args) {
|
||||
var fullPath = args[0];
|
||||
var path = args[1];
|
||||
var options = args[2];
|
||||
|
||||
// Create an absolute path if we were handed a relative one.
|
||||
path = resolveToFullPath_(fullPath, path);
|
||||
|
||||
idb_.get(path.storagePath, function (folderEntry) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (options.create === true && options.exclusive === true && folderEntry) {
|
||||
// If create and exclusive are both true, and the path already exists,
|
||||
// getDirectory must fail.
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.PATH_EXISTS_ERR);
|
||||
}
|
||||
// There is a strange bug in mobilespec + FF, which results in coming to multiple else-if's
|
||||
// so we are shielding from it with returns.
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.create === true && !folderEntry) {
|
||||
// If create is true, the path doesn't exist, and no other error occurs,
|
||||
// getDirectory must create it as a zero-length file and return a corresponding
|
||||
// MyDirectoryEntry.
|
||||
var dirEntry = new DirectoryEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
|
||||
|
||||
idb_.put(dirEntry, path.storagePath, successCallback, errorCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.create === true && folderEntry) {
|
||||
|
||||
if (folderEntry.isDirectory) {
|
||||
// IDB won't save methods, so we need re-create the MyDirectoryEntry.
|
||||
successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem));
|
||||
} else {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!options.create || options.create === false) && !folderEntry) {
|
||||
// Handle root special. It should always exist.
|
||||
if (path.fullPath === DIR_SEPARATOR) {
|
||||
successCallback(fs_.root);
|
||||
return;
|
||||
}
|
||||
|
||||
// If create is not true and the path doesn't exist, getDirectory must fail.
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if ((!options.create || options.create === false) && folderEntry && folderEntry.isFile) {
|
||||
// If create is not true and the path exists, but is a file, getDirectory
|
||||
// must fail.
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.TYPE_MISMATCH_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, if no other error occurs, getDirectory must return a
|
||||
// MyDirectoryEntry corresponding to path.
|
||||
|
||||
// IDB won't' save methods, so we need re-create MyDirectoryEntry.
|
||||
successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem));
|
||||
}, errorCallback);
|
||||
};
|
||||
|
||||
exports.getParent = function (successCallback, errorCallback, args) {
|
||||
if (typeof successCallback !== 'function') {
|
||||
throw Error('Expected successCallback argument.');
|
||||
}
|
||||
|
||||
var fullPath = args[0];
|
||||
// fullPath is like this:
|
||||
// file:///persistent/path/to/file or
|
||||
// file:///persistent/path/to/directory/
|
||||
|
||||
if (fullPath === DIR_SEPARATOR || fullPath === pathsPrefix.cacheDirectory ||
|
||||
fullPath === pathsPrefix.dataDirectory) {
|
||||
successCallback(fs_.root);
|
||||
return;
|
||||
}
|
||||
|
||||
// To delete all slashes at the end
|
||||
while (fullPath[fullPath.length - 1] === '/') {
|
||||
fullPath = fullPath.substr(0, fullPath.length - 1);
|
||||
}
|
||||
|
||||
var pathArr = fullPath.split(DIR_SEPARATOR);
|
||||
pathArr.pop();
|
||||
var parentName = pathArr.pop();
|
||||
var path = pathArr.join(DIR_SEPARATOR) + DIR_SEPARATOR;
|
||||
|
||||
// To get parent of root files
|
||||
var joined = path + parentName + DIR_SEPARATOR;// is like this: file:///persistent/
|
||||
if (joined === pathsPrefix.cacheDirectory || joined === pathsPrefix.dataDirectory) {
|
||||
exports.getDirectory(successCallback, errorCallback, [joined, DIR_SEPARATOR, {create: false}]);
|
||||
return;
|
||||
}
|
||||
|
||||
exports.getDirectory(successCallback, errorCallback, [path, parentName, {create: false}]);
|
||||
};
|
||||
|
||||
exports.copyTo = function (successCallback, errorCallback, args) {
|
||||
var srcPath = args[0];
|
||||
var parentFullPath = args[1];
|
||||
var name = args[2];
|
||||
|
||||
if (name.indexOf('/') !== -1 || srcPath === parentFullPath + name) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Read src file
|
||||
exports.getFile(function (srcFileEntry) {
|
||||
|
||||
var path = resolveToFullPath_(parentFullPath);
|
||||
// Check directory
|
||||
exports.getDirectory(function () {
|
||||
|
||||
// Create dest file
|
||||
exports.getFile(function (dstFileEntry) {
|
||||
|
||||
exports.write(function () {
|
||||
successCallback(dstFileEntry);
|
||||
}, errorCallback, [dstFileEntry.file_.storagePath, srcFileEntry.file_.blob_, 0]);
|
||||
|
||||
}, errorCallback, [parentFullPath, name, {create: true}]);
|
||||
|
||||
}, function () { if (errorCallback) { errorCallback(FileError.NOT_FOUND_ERR); } },
|
||||
[path.storagePath, null, {create: false}]);
|
||||
|
||||
}, errorCallback, [srcPath, null]);
|
||||
};
|
||||
|
||||
exports.moveTo = function (successCallback, errorCallback, args) {
|
||||
var srcPath = args[0];
|
||||
// parentFullPath and name parameters is ignored because
|
||||
// args is being passed downstream to exports.copyTo method
|
||||
var parentFullPath = args[1]; // eslint-disable-line
|
||||
var name = args[2]; // eslint-disable-line
|
||||
|
||||
exports.copyTo(function (fileEntry) {
|
||||
|
||||
exports.remove(function () {
|
||||
successCallback(fileEntry);
|
||||
}, errorCallback, [srcPath]);
|
||||
|
||||
}, errorCallback, args);
|
||||
};
|
||||
|
||||
exports.resolveLocalFileSystemURI = function (successCallback, errorCallback, args) {
|
||||
var path = args[0];
|
||||
|
||||
// Ignore parameters
|
||||
if (path.indexOf('?') !== -1) {
|
||||
path = String(path).split('?')[0];
|
||||
}
|
||||
|
||||
// support for encodeURI
|
||||
if (/\%5/g.test(path) || /\%20/g.test(path)) { // eslint-disable-line no-useless-escape
|
||||
path = decodeURI(path);
|
||||
}
|
||||
|
||||
if (path.trim()[0] === '/') {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.ENCODING_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// support for cdvfile
|
||||
if (path.trim().substr(0, 7) === 'cdvfile') {
|
||||
if (path.indexOf('cdvfile://localhost') === -1) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.ENCODING_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var indexPersistent = path.indexOf('persistent');
|
||||
var indexTemporary = path.indexOf('temporary');
|
||||
|
||||
// cdvfile://localhost/persistent/path/to/file
|
||||
if (indexPersistent !== -1) {
|
||||
path = 'file:///persistent' + path.substr(indexPersistent + 10);
|
||||
} else if (indexTemporary !== -1) {
|
||||
path = 'file:///temporary' + path.substr(indexTemporary + 9);
|
||||
} else {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.ENCODING_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// to avoid path form of '///path/to/file'
|
||||
function handlePathSlashes (path) {
|
||||
var cutIndex = 0;
|
||||
for (var i = 0; i < path.length - 1; i++) {
|
||||
if (path[i] === DIR_SEPARATOR && path[i + 1] === DIR_SEPARATOR) {
|
||||
cutIndex = i + 1;
|
||||
} else break;
|
||||
}
|
||||
|
||||
return path.substr(cutIndex);
|
||||
}
|
||||
|
||||
// Handle localhost containing paths (see specs )
|
||||
if (path.indexOf('file://localhost/') === 0) {
|
||||
path = path.replace('file://localhost/', 'file:///');
|
||||
}
|
||||
|
||||
if (path.indexOf(pathsPrefix.dataDirectory) === 0) {
|
||||
path = path.substring(pathsPrefix.dataDirectory.length - 1);
|
||||
path = handlePathSlashes(path);
|
||||
|
||||
exports.requestFileSystem(function () {
|
||||
exports.getFile(successCallback, function () {
|
||||
exports.getDirectory(successCallback, errorCallback, [pathsPrefix.dataDirectory, path,
|
||||
{create: false}]);
|
||||
}, [pathsPrefix.dataDirectory, path, {create: false}]);
|
||||
}, errorCallback, [LocalFileSystem.PERSISTENT]);
|
||||
} else if (path.indexOf(pathsPrefix.cacheDirectory) === 0) {
|
||||
path = path.substring(pathsPrefix.cacheDirectory.length - 1);
|
||||
path = handlePathSlashes(path);
|
||||
|
||||
exports.requestFileSystem(function () {
|
||||
exports.getFile(successCallback, function () {
|
||||
exports.getDirectory(successCallback, errorCallback, [pathsPrefix.cacheDirectory, path,
|
||||
{create: false}]);
|
||||
}, [pathsPrefix.cacheDirectory, path, {create: false}]);
|
||||
}, errorCallback, [LocalFileSystem.TEMPORARY]);
|
||||
} else if (path.indexOf(pathsPrefix.applicationDirectory) === 0) {
|
||||
path = path.substring(pathsPrefix.applicationDirectory.length);
|
||||
// TODO: need to cut out redundant slashes?
|
||||
|
||||
var xhr = new XMLHttpRequest(); // eslint-disable-line no-undef
|
||||
xhr.open('GET', path, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.status === 200 && xhr.readyState === 4) {
|
||||
exports.requestFileSystem(function (fs) {
|
||||
fs.name = location.hostname; // eslint-disable-line no-undef
|
||||
|
||||
// TODO: need to call exports.getFile(...) to handle errors correct
|
||||
fs.root.getFile(path, {create: true}, writeFile, errorCallback);
|
||||
}, errorCallback, [LocalFileSystem.PERSISTENT]);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_READABLE_ERR);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
} else {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
function writeFile (entry) {
|
||||
entry.createWriter(function (fileWriter) {
|
||||
fileWriter.onwriteend = function (evt) {
|
||||
if (!evt.target.error) {
|
||||
entry.filesystemName = location.hostname; // eslint-disable-line no-undef
|
||||
successCallback(entry);
|
||||
}
|
||||
};
|
||||
fileWriter.onerror = function () {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.NOT_READABLE_ERR);
|
||||
}
|
||||
};
|
||||
fileWriter.write(new Blob([xhr.response])); // eslint-disable-line no-undef
|
||||
}, errorCallback); // eslint-disable-line no-undef
|
||||
}
|
||||
};
|
||||
|
||||
exports.requestAllPaths = function (successCallback) {
|
||||
successCallback(pathsPrefix);
|
||||
};
|
||||
|
||||
/** * Helpers ***/
|
||||
|
||||
/**
|
||||
* Interface to wrap the native File interface.
|
||||
*
|
||||
* This interface is necessary for creating zero-length (empty) files,
|
||||
* something the Filesystem API allows you to do. Unfortunately, File's
|
||||
* constructor cannot be called directly, making it impossible to instantiate
|
||||
* an empty File in JS.
|
||||
*
|
||||
* @param {Object} opts Initial values.
|
||||
* @constructor
|
||||
*/
|
||||
function MyFile (opts) {
|
||||
var blob_ = new Blob(); // eslint-disable-line no-undef
|
||||
|
||||
this.size = opts.size || 0;
|
||||
this.name = opts.name || '';
|
||||
this.type = opts.type || '';
|
||||
this.lastModifiedDate = opts.lastModifiedDate || null;
|
||||
this.storagePath = opts.storagePath || '';
|
||||
|
||||
// Need some black magic to correct the object's size/name/type based on the
|
||||
// blob that is saved.
|
||||
Object.defineProperty(this, 'blob_', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return blob_;
|
||||
},
|
||||
set: function (val) {
|
||||
blob_ = val;
|
||||
this.size = blob_.size;
|
||||
this.name = blob_.name;
|
||||
this.type = blob_.type;
|
||||
this.lastModifiedDate = blob_.lastModifiedDate;
|
||||
}.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
MyFile.prototype.constructor = MyFile;
|
||||
|
||||
// When saving an entry, the fullPath should always lead with a slash and never
|
||||
// end with one (e.g. a directory). Also, resolve '.' and '..' to an absolute
|
||||
// one. This method ensures path is legit!
|
||||
function resolveToFullPath_ (cwdFullPath, path) {
|
||||
path = path || '';
|
||||
var fullPath = path;
|
||||
var prefix = '';
|
||||
|
||||
cwdFullPath = cwdFullPath || DIR_SEPARATOR;
|
||||
if (cwdFullPath.indexOf(FILESYSTEM_PREFIX) === 0) {
|
||||
prefix = cwdFullPath.substring(0, cwdFullPath.indexOf(DIR_SEPARATOR, FILESYSTEM_PREFIX.length));
|
||||
cwdFullPath = cwdFullPath.substring(cwdFullPath.indexOf(DIR_SEPARATOR, FILESYSTEM_PREFIX.length));
|
||||
}
|
||||
|
||||
var relativePath = path[0] !== DIR_SEPARATOR;
|
||||
if (relativePath) {
|
||||
fullPath = cwdFullPath;
|
||||
if (cwdFullPath !== DIR_SEPARATOR) {
|
||||
fullPath += DIR_SEPARATOR + path;
|
||||
} else {
|
||||
fullPath += path;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove doubled separator substrings
|
||||
var re = new RegExp(DIR_SEPARATOR + DIR_SEPARATOR, 'g');
|
||||
fullPath = fullPath.replace(re, DIR_SEPARATOR);
|
||||
|
||||
// Adjust '..'s by removing parent directories when '..' flows in path.
|
||||
var parts = fullPath.split(DIR_SEPARATOR);
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
var part = parts[i];
|
||||
if (part === '..') {
|
||||
parts[i - 1] = '';
|
||||
parts[i] = '';
|
||||
}
|
||||
}
|
||||
fullPath = parts.filter(function (el) {
|
||||
return el;
|
||||
}).join(DIR_SEPARATOR);
|
||||
|
||||
// Add back in leading slash.
|
||||
if (fullPath[0] !== DIR_SEPARATOR) {
|
||||
fullPath = DIR_SEPARATOR + fullPath;
|
||||
}
|
||||
|
||||
// Replace './' by current dir. ('./one/./two' -> one/two)
|
||||
fullPath = fullPath.replace(/\.\//g, DIR_SEPARATOR);
|
||||
|
||||
// Replace '//' with '/'.
|
||||
fullPath = fullPath.replace(/\/\//g, DIR_SEPARATOR);
|
||||
|
||||
// Replace '/.' with '/'.
|
||||
fullPath = fullPath.replace(/\/\./g, DIR_SEPARATOR);
|
||||
|
||||
// Remove '/' if it appears on the end.
|
||||
if (fullPath[fullPath.length - 1] === DIR_SEPARATOR &&
|
||||
fullPath !== DIR_SEPARATOR) {
|
||||
fullPath = fullPath.substring(0, fullPath.length - 1);
|
||||
}
|
||||
|
||||
var storagePath = prefix + fullPath;
|
||||
storagePath = decodeURI(storagePath);
|
||||
fullPath = decodeURI(fullPath);
|
||||
|
||||
return {
|
||||
storagePath: storagePath,
|
||||
fullPath: fullPath,
|
||||
fileName: fullPath.split(DIR_SEPARATOR).pop(),
|
||||
fsName: prefix.split(DIR_SEPARATOR).pop()
|
||||
};
|
||||
}
|
||||
|
||||
function fileEntryFromIdbEntry (fileEntry) {
|
||||
// IDB won't save methods, so we need re-create the FileEntry.
|
||||
var clonedFileEntry = new FileEntry(fileEntry.name, fileEntry.fullPath, fileEntry.filesystem);
|
||||
clonedFileEntry.file_ = fileEntry.file_;
|
||||
|
||||
return clonedFileEntry;
|
||||
}
|
||||
|
||||
function readAs (what, fullPath, encoding, startPos, endPos, successCallback, errorCallback) {
|
||||
exports.getFile(function (fileEntry) {
|
||||
var fileReader = new FileReader(); // eslint-disable-line no-undef
|
||||
var blob = fileEntry.file_.blob_.slice(startPos, endPos);
|
||||
|
||||
fileReader.onload = function (e) {
|
||||
successCallback(e.target.result);
|
||||
};
|
||||
|
||||
fileReader.onerror = errorCallback;
|
||||
|
||||
switch (what) {
|
||||
case 'text':
|
||||
fileReader.readAsText(blob, encoding);
|
||||
break;
|
||||
case 'dataURL':
|
||||
fileReader.readAsDataURL(blob);
|
||||
break;
|
||||
case 'arrayBuffer':
|
||||
fileReader.readAsArrayBuffer(blob);
|
||||
break;
|
||||
case 'binaryString':
|
||||
fileReader.readAsBinaryString(blob);
|
||||
break;
|
||||
}
|
||||
|
||||
}, errorCallback, [fullPath, null]);
|
||||
}
|
||||
|
||||
/** * Core logic to handle IDB operations ***/
|
||||
|
||||
idb_.open = function (dbName, successCallback, errorCallback) {
|
||||
var self = this;
|
||||
|
||||
// TODO: FF 12.0a1 isn't liking a db name with : in it.
|
||||
var request = indexedDB.open(dbName.replace(':', '_')/*, 1 /*version */);
|
||||
|
||||
request.onerror = errorCallback || onError;
|
||||
|
||||
request.onupgradeneeded = function (e) {
|
||||
// First open was called or higher db version was used.
|
||||
|
||||
// console.log('onupgradeneeded: oldVersion:' + e.oldVersion,
|
||||
// 'newVersion:' + e.newVersion);
|
||||
|
||||
self.db = e.target.result;
|
||||
self.db.onerror = onError;
|
||||
|
||||
if (!self.db.objectStoreNames.contains(FILE_STORE_)) {
|
||||
self.db.createObjectStore(FILE_STORE_/*, {keyPath: 'id', autoIncrement: true} */);
|
||||
}
|
||||
};
|
||||
|
||||
request.onsuccess = function (e) {
|
||||
self.db = e.target.result;
|
||||
self.db.onerror = onError;
|
||||
successCallback(e);
|
||||
};
|
||||
|
||||
request.onblocked = errorCallback || onError;
|
||||
};
|
||||
|
||||
idb_.close = function () {
|
||||
this.db.close();
|
||||
this.db = null;
|
||||
};
|
||||
|
||||
idb_.get = function (fullPath, successCallback, errorCallback) {
|
||||
if (!this.db) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var tx = this.db.transaction([FILE_STORE_], 'readonly');
|
||||
|
||||
var request = tx.objectStore(FILE_STORE_).get(fullPath);
|
||||
|
||||
tx.onabort = errorCallback || onError;
|
||||
tx.oncomplete = function () {
|
||||
successCallback(request.result);
|
||||
};
|
||||
};
|
||||
|
||||
idb_.getAllEntries = function (fullPath, storagePath, successCallback, errorCallback) {
|
||||
if (!this.db) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var results = [];
|
||||
|
||||
if (storagePath[storagePath.length - 1] === DIR_SEPARATOR) {
|
||||
storagePath = storagePath.substring(0, storagePath.length - 1);
|
||||
}
|
||||
|
||||
var range = IDBKeyRange.bound(storagePath + DIR_SEPARATOR + ' ',
|
||||
storagePath + DIR_SEPARATOR + String.fromCharCode(unicodeLastChar));
|
||||
|
||||
var tx = this.db.transaction([FILE_STORE_], 'readonly');
|
||||
tx.onabort = errorCallback || onError;
|
||||
tx.oncomplete = function () {
|
||||
results = results.filter(function (val) {
|
||||
var pathWithoutSlash = val.fullPath;
|
||||
|
||||
if (val.fullPath[val.fullPath.length - 1] === DIR_SEPARATOR) {
|
||||
pathWithoutSlash = pathWithoutSlash.substr(0, pathWithoutSlash.length - 1);
|
||||
}
|
||||
|
||||
var valPartsLen = pathWithoutSlash.split(DIR_SEPARATOR).length;
|
||||
var fullPathPartsLen = fullPath.split(DIR_SEPARATOR).length;
|
||||
|
||||
/* Input fullPath parameter equals '//' for root folder */
|
||||
/* Entries in root folder has valPartsLen equals 2 (see below) */
|
||||
if (fullPath[fullPath.length - 1] === DIR_SEPARATOR && fullPath.trim().length === 2) {
|
||||
fullPathPartsLen = 1;
|
||||
} else if (fullPath[fullPath.length - 1] === DIR_SEPARATOR) {
|
||||
fullPathPartsLen = fullPath.substr(0, fullPath.length - 1).split(DIR_SEPARATOR).length;
|
||||
} else {
|
||||
fullPathPartsLen = fullPath.split(DIR_SEPARATOR).length;
|
||||
}
|
||||
|
||||
if (valPartsLen === fullPathPartsLen + 1) {
|
||||
// If this a subfolder and entry is a direct child, include it in
|
||||
// the results. Otherwise, it's not an entry of this folder.
|
||||
return val;
|
||||
} else return false;
|
||||
});
|
||||
|
||||
successCallback(results);
|
||||
};
|
||||
|
||||
var request = tx.objectStore(FILE_STORE_).openCursor(range);
|
||||
|
||||
request.onsuccess = function (e) {
|
||||
var cursor = e.target.result;
|
||||
if (cursor) {
|
||||
var val = cursor.value;
|
||||
|
||||
results.push(val.isFile ? fileEntryFromIdbEntry(val) : new DirectoryEntry(val.name, val.fullPath, val.filesystem));
|
||||
cursor['continue']();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
idb_['delete'] = function (fullPath, successCallback, errorCallback, isDirectory) {
|
||||
if (!idb_.db) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var tx = this.db.transaction([FILE_STORE_], 'readwrite');
|
||||
tx.oncomplete = successCallback;
|
||||
tx.onabort = errorCallback || onError;
|
||||
tx.oncomplete = function () {
|
||||
if (isDirectory) {
|
||||
// We delete nested files and folders after deleting parent folder
|
||||
// We use ranges: https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange
|
||||
fullPath = fullPath + DIR_SEPARATOR;
|
||||
|
||||
// Range contains all entries in the form fullPath<symbol> where
|
||||
// symbol in the range from ' ' to symbol which has code `unicodeLastChar`
|
||||
var range = IDBKeyRange.bound(fullPath + ' ', fullPath + String.fromCharCode(unicodeLastChar));
|
||||
|
||||
var newTx = this.db.transaction([FILE_STORE_], 'readwrite');
|
||||
newTx.oncomplete = successCallback;
|
||||
newTx.onabort = errorCallback || onError;
|
||||
newTx.objectStore(FILE_STORE_)['delete'](range);
|
||||
} else {
|
||||
successCallback();
|
||||
}
|
||||
};
|
||||
tx.objectStore(FILE_STORE_)['delete'](fullPath);
|
||||
};
|
||||
|
||||
idb_.put = function (entry, storagePath, successCallback, errorCallback) {
|
||||
if (!this.db) {
|
||||
if (errorCallback) {
|
||||
errorCallback(FileError.INVALID_MODIFICATION_ERR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var tx = this.db.transaction([FILE_STORE_], 'readwrite');
|
||||
tx.onabort = errorCallback || onError;
|
||||
tx.oncomplete = function () {
|
||||
// TODO: Error is thrown if we pass the request event back instead.
|
||||
successCallback(entry);
|
||||
};
|
||||
|
||||
tx.objectStore(FILE_STORE_).put(entry, storagePath);
|
||||
};
|
||||
|
||||
// Global error handler. Errors bubble from request, to transaction, to db.
|
||||
function onError (e) {
|
||||
switch (e.target.errorCode) {
|
||||
case 12:
|
||||
console.log('Error - Attempt to open db with a lower version than the ' +
|
||||
'current one.');
|
||||
break;
|
||||
default:
|
||||
console.log('errorCode: ' + e.target.errorCode);
|
||||
}
|
||||
|
||||
console.log(e, e.code, e.message);
|
||||
}
|
||||
|
||||
})(module.exports, window);
|
||||
|
||||
require('cordova/exec/proxy').add('File', module.exports);
|
||||
})();
|
||||
|
||||
});
|
119
platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryEntry.js
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
cordova.define("cordova-plugin-file.DirectoryEntry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck');
|
||||
var utils = require('cordova/utils');
|
||||
var exec = require('cordova/exec');
|
||||
var Entry = require('./Entry');
|
||||
var FileError = require('./FileError');
|
||||
var DirectoryReader = require('./DirectoryReader');
|
||||
|
||||
/**
|
||||
* An interface representing a directory on the file system.
|
||||
*
|
||||
* {boolean} isFile always false (readonly)
|
||||
* {boolean} isDirectory always true (readonly)
|
||||
* {DOMString} name of the directory, excluding the path leading to it (readonly)
|
||||
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||
*/
|
||||
var DirectoryEntry = function (name, fullPath, fileSystem, nativeURL) {
|
||||
|
||||
// add trailing slash if it is missing
|
||||
if ((fullPath) && !/\/$/.test(fullPath)) {
|
||||
fullPath += '/';
|
||||
}
|
||||
// add trailing slash if it is missing
|
||||
if (nativeURL && !/\/$/.test(nativeURL)) {
|
||||
nativeURL += '/';
|
||||
}
|
||||
DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL);
|
||||
};
|
||||
|
||||
utils.extend(DirectoryEntry, Entry);
|
||||
|
||||
/**
|
||||
* Creates a new DirectoryReader to read entries from this directory
|
||||
*/
|
||||
DirectoryEntry.prototype.createReader = function () {
|
||||
return new DirectoryReader(this.toInternalURL());
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates or looks up a directory
|
||||
*
|
||||
* @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
|
||||
* @param {Flags} options to create or exclusively create the directory
|
||||
* @param {Function} successCallback is called with the new entry
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function (result) {
|
||||
var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, 'File', 'getDirectory', [this.toInternalURL(), path, options]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a directory and all of it's contents
|
||||
*
|
||||
* @param {Function} successCallback is called with no parameters
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.removeRecursively = function (successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments);
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, 'File', 'removeRecursively', [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates or looks up a file
|
||||
*
|
||||
* @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
|
||||
* @param {Flags} options to create or exclusively create the file
|
||||
* @param {Function} successCallback is called with the new entry
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getFile = function (path, options, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function (result) {
|
||||
var FileEntry = require('./FileEntry');
|
||||
var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, 'File', 'getFile', [this.toInternalURL(), path, options]);
|
||||
};
|
||||
|
||||
module.exports = DirectoryEntry;
|
||||
|
||||
});
|
74
platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryReader.js
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var FileError = require('./FileError');
|
||||
|
||||
/**
|
||||
* An interface that lists the files and directories in a directory.
|
||||
*/
|
||||
function DirectoryReader (localURL) {
|
||||
this.localURL = localURL || null;
|
||||
this.hasReadEntries = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of entries from a directory.
|
||||
*
|
||||
* @param {Function} successCallback is called with a list of entries
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryReader.prototype.readEntries = function (successCallback, errorCallback) {
|
||||
// If we've already read and passed on this directory's entries, return an empty list.
|
||||
if (this.hasReadEntries) {
|
||||
successCallback([]);
|
||||
return;
|
||||
}
|
||||
var reader = this;
|
||||
var win = typeof successCallback !== 'function' ? null : function (result) {
|
||||
var retVal = [];
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
var entry = null;
|
||||
if (result[i].isDirectory) {
|
||||
entry = new (require('./DirectoryEntry'))();
|
||||
} else if (result[i].isFile) {
|
||||
entry = new (require('./FileEntry'))();
|
||||
}
|
||||
entry.isDirectory = result[i].isDirectory;
|
||||
entry.isFile = result[i].isFile;
|
||||
entry.name = result[i].name;
|
||||
entry.fullPath = result[i].fullPath;
|
||||
entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
|
||||
entry.nativeURL = result[i].nativeURL;
|
||||
retVal.push(entry);
|
||||
}
|
||||
reader.hasReadEntries = true;
|
||||
successCallback(retVal);
|
||||
};
|
||||
var fail = typeof errorCallback !== 'function' ? null : function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, 'File', 'readEntries', [this.localURL]);
|
||||
};
|
||||
|
||||
module.exports = DirectoryReader;
|
||||
|
||||
});
|
|
@ -0,0 +1,262 @@
|
|||
cordova.define("cordova-plugin-file.Entry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck');
|
||||
var exec = require('cordova/exec');
|
||||
var FileError = require('./FileError');
|
||||
var Metadata = require('./Metadata');
|
||||
|
||||
/**
|
||||
* Represents a file or directory on the local file system.
|
||||
*
|
||||
* @param isFile
|
||||
* {boolean} true if Entry is a file (readonly)
|
||||
* @param isDirectory
|
||||
* {boolean} true if Entry is a directory (readonly)
|
||||
* @param name
|
||||
* {DOMString} name of the file or directory, excluding the path
|
||||
* leading to it (readonly)
|
||||
* @param fullPath
|
||||
* {DOMString} the absolute full path to the file or directory
|
||||
* (readonly)
|
||||
* @param fileSystem
|
||||
* {FileSystem} the filesystem on which this entry resides
|
||||
* (readonly)
|
||||
* @param nativeURL
|
||||
* {DOMString} an alternate URL which can be used by native
|
||||
* webview controls, for example media players.
|
||||
* (optional, readonly)
|
||||
*/
|
||||
function Entry (isFile, isDirectory, name, fullPath, fileSystem, nativeURL) {
|
||||
this.isFile = !!isFile;
|
||||
this.isDirectory = !!isDirectory;
|
||||
this.name = name || '';
|
||||
this.fullPath = fullPath || '';
|
||||
this.filesystem = fileSystem || null;
|
||||
this.nativeURL = nativeURL || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the metadata of the entry.
|
||||
*
|
||||
* @param successCallback
|
||||
* {Function} is called with a Metadata object
|
||||
* @param errorCallback
|
||||
* {Function} is called with a FileError
|
||||
*/
|
||||
Entry.prototype.getMetadata = function (successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
|
||||
var success = successCallback && function (entryMetadata) {
|
||||
var metadata = new Metadata({
|
||||
size: entryMetadata.size,
|
||||
modificationTime: entryMetadata.lastModifiedDate
|
||||
});
|
||||
successCallback(metadata);
|
||||
};
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(success, fail, 'File', 'getFileMetadata', [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the metadata of the entry.
|
||||
*
|
||||
* @param successCallback
|
||||
* {Function} is called with a Metadata object
|
||||
* @param errorCallback
|
||||
* {Function} is called with a FileError
|
||||
* @param metadataObject
|
||||
* {Object} keys and values to set
|
||||
*/
|
||||
Entry.prototype.setMetadata = function (successCallback, errorCallback, metadataObject) {
|
||||
argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments);
|
||||
exec(successCallback, errorCallback, 'File', 'setMetadata', [this.toInternalURL(), metadataObject]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Move a file or directory to a new location.
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to move this entry
|
||||
* @param newName
|
||||
* {DOMString} new name of the entry, defaults to the current name
|
||||
* @param successCallback
|
||||
* {Function} called with the new DirectoryEntry object
|
||||
* @param errorCallback
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.moveTo = function (parent, newName, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('oSFF', 'Entry.moveTo', arguments);
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
var srcURL = this.toInternalURL();
|
||||
// entry name
|
||||
var name = newName || this.name;
|
||||
var success = function (entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
|
||||
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef
|
||||
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
}
|
||||
} else {
|
||||
// no Entry object returned
|
||||
if (fail) {
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// copy
|
||||
exec(success, fail, 'File', 'moveTo', [srcURL, parent.toInternalURL(), name]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy a directory to a different location.
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to copy the entry
|
||||
* @param newName
|
||||
* {DOMString} new name of the entry, defaults to the current name
|
||||
* @param successCallback
|
||||
* {Function} called with the new Entry object
|
||||
* @param errorCallback
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.copyTo = function (parent, newName, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('oSFF', 'Entry.copyTo', arguments);
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
var srcURL = this.toInternalURL();
|
||||
// entry name
|
||||
var name = newName || this.name;
|
||||
// success callback
|
||||
var success = function (entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
|
||||
var fs = newFSName ? new FileSystem(newFSName, { name: '', fullPath: '/' }) : new FileSystem(parent.filesystem.name, { name: '', fullPath: '/' }); // eslint-disable-line no-undef
|
||||
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
}
|
||||
} else {
|
||||
// no Entry object returned
|
||||
if (fail) {
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// copy
|
||||
exec(success, fail, 'File', 'copyTo', [srcURL, parent.toInternalURL(), name]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a URL that can be passed across the bridge to identify this entry.
|
||||
*/
|
||||
Entry.prototype.toInternalURL = function () {
|
||||
if (this.filesystem && this.filesystem.__format__) {
|
||||
return this.filesystem.__format__(this.fullPath, this.nativeURL);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a URL that can be used to identify this entry.
|
||||
* Use a URL that can be used to as the src attribute of a <video> or
|
||||
* <audio> tag. If that is not possible, construct a cdvfile:// URL.
|
||||
*/
|
||||
Entry.prototype.toURL = function () {
|
||||
if (this.nativeURL) {
|
||||
return this.nativeURL;
|
||||
}
|
||||
// fullPath attribute may contain the full URL in the case that
|
||||
// toInternalURL fails.
|
||||
return this.toInternalURL() || 'file://localhost' + this.fullPath;
|
||||
};
|
||||
|
||||
/**
|
||||
* Backwards-compatibility: In v1.0.0 - 1.0.2, .toURL would only return a
|
||||
* cdvfile:// URL, and this method was necessary to obtain URLs usable by the
|
||||
* webview.
|
||||
* See CB-6051, CB-6106, CB-6117, CB-6152, CB-6199, CB-6201, CB-6243, CB-6249,
|
||||
* and CB-6300.
|
||||
*/
|
||||
Entry.prototype.toNativeURL = function () {
|
||||
console.log("DEPRECATED: Update your code to use 'toURL'");
|
||||
return this.toURL();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a URI that can be used to identify this entry.
|
||||
*
|
||||
* @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
|
||||
* @return uri
|
||||
*/
|
||||
Entry.prototype.toURI = function (mimeType) {
|
||||
console.log("DEPRECATED: Update your code to use 'toURL'");
|
||||
return this.toURL();
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a file or directory. It is an error to attempt to delete a
|
||||
* directory that is not empty. It is an error to attempt to delete a
|
||||
* root directory of a file system.
|
||||
*
|
||||
* @param successCallback {Function} called with no parameters
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.remove = function (successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.remove', arguments);
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, 'File', 'remove', [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Look up the parent DirectoryEntry of this entry.
|
||||
*
|
||||
* @param successCallback {Function} called with the parent DirectoryEntry object
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.getParent = function (successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.getParent', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function (result) {
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, 'File', 'getParent', [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
module.exports = Entry;
|
||||
|
||||
});
|
|
@ -0,0 +1,80 @@
|
|||
cordova.define("cordova-plugin-file.File", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* name {DOMString} name of the file, without path information
|
||||
* fullPath {DOMString} the full path of the file, including the name
|
||||
* type {DOMString} mime type
|
||||
* lastModifiedDate {Date} last modified date
|
||||
* size {Number} size of the file in bytes
|
||||
*/
|
||||
|
||||
var File = function (name, localURL, type, lastModifiedDate, size) {
|
||||
this.name = name || '';
|
||||
this.localURL = localURL || null;
|
||||
this.type = type || null;
|
||||
this.lastModified = lastModifiedDate || null;
|
||||
// For backwards compatibility, store the timestamp in lastModifiedDate as well
|
||||
this.lastModifiedDate = lastModifiedDate || null;
|
||||
this.size = size || 0;
|
||||
|
||||
// These store the absolute start and end for slicing the file.
|
||||
this.start = 0;
|
||||
this.end = this.size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a "slice" of the file. Since Cordova Files don't contain the actual
|
||||
* content, this really returns a File with adjusted start and end.
|
||||
* Slices of slices are supported.
|
||||
* start {Number} The index at which to start the slice (inclusive).
|
||||
* end {Number} The index at which to end the slice (exclusive).
|
||||
*/
|
||||
File.prototype.slice = function (start, end) {
|
||||
var size = this.end - this.start;
|
||||
var newStart = 0;
|
||||
var newEnd = size;
|
||||
if (arguments.length) {
|
||||
if (start < 0) {
|
||||
newStart = Math.max(size + start, 0);
|
||||
} else {
|
||||
newStart = Math.min(size, start);
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.length >= 2) {
|
||||
if (end < 0) {
|
||||
newEnd = Math.max(size + end, 0);
|
||||
} else {
|
||||
newEnd = Math.min(end, size);
|
||||
}
|
||||
}
|
||||
|
||||
var newFile = new File(this.name, this.localURL, this.type, this.lastModified, this.size);
|
||||
newFile.start = this.start + newStart;
|
||||
newFile.end = this.start + newEnd;
|
||||
return newFile;
|
||||
};
|
||||
|
||||
module.exports = File;
|
||||
|
||||
});
|
|
@ -0,0 +1,94 @@
|
|||
cordova.define("cordova-plugin-file.FileEntry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var utils = require('cordova/utils');
|
||||
var exec = require('cordova/exec');
|
||||
var Entry = require('./Entry');
|
||||
var FileWriter = require('./FileWriter');
|
||||
var File = require('./File');
|
||||
var FileError = require('./FileError');
|
||||
|
||||
/**
|
||||
* An interface representing a file on the file system.
|
||||
*
|
||||
* {boolean} isFile always true (readonly)
|
||||
* {boolean} isDirectory always false (readonly)
|
||||
* {DOMString} name of the file, excluding the path leading to it (readonly)
|
||||
* {DOMString} fullPath the absolute full path to the file (readonly)
|
||||
* {FileSystem} filesystem on which the file resides (readonly)
|
||||
*/
|
||||
var FileEntry = function (name, fullPath, fileSystem, nativeURL) {
|
||||
// remove trailing slash if it is present
|
||||
if (fullPath && /\/$/.test(fullPath)) {
|
||||
fullPath = fullPath.substring(0, fullPath.length - 1);
|
||||
}
|
||||
if (nativeURL && /\/$/.test(nativeURL)) {
|
||||
nativeURL = nativeURL.substring(0, nativeURL.length - 1);
|
||||
}
|
||||
|
||||
FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
|
||||
};
|
||||
|
||||
utils.extend(FileEntry, Entry);
|
||||
|
||||
/**
|
||||
* Creates a new FileWriter associated with the file that this FileEntry represents.
|
||||
*
|
||||
* @param {Function} successCallback is called with the new FileWriter
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.createWriter = function (successCallback, errorCallback) {
|
||||
this.file(function (filePointer) {
|
||||
var writer = new FileWriter(filePointer);
|
||||
|
||||
if (writer.localURL === null || writer.localURL === '') {
|
||||
if (errorCallback) {
|
||||
errorCallback(new FileError(FileError.INVALID_STATE_ERR));
|
||||
}
|
||||
} else {
|
||||
if (successCallback) {
|
||||
successCallback(writer);
|
||||
}
|
||||
}
|
||||
}, errorCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a File that represents the current state of the file that this FileEntry represents.
|
||||
*
|
||||
* @param {Function} successCallback is called with the new File object
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.file = function (successCallback, errorCallback) {
|
||||
var localURL = this.toInternalURL();
|
||||
var win = successCallback && function (f) {
|
||||
var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
|
||||
successCallback(file);
|
||||
};
|
||||
var fail = errorCallback && function (code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, 'File', 'getFileMetadata', [localURL]);
|
||||
};
|
||||
|
||||
module.exports = FileEntry;
|
||||
|
||||
});
|
|
@ -0,0 +1,48 @@
|
|||
cordova.define("cordova-plugin-file.FileError", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileError
|
||||
*/
|
||||
function FileError (error) {
|
||||
this.code = error || null;
|
||||
}
|
||||
|
||||
// File error codes
|
||||
// Found in DOMException
|
||||
FileError.NOT_FOUND_ERR = 1;
|
||||
FileError.SECURITY_ERR = 2;
|
||||
FileError.ABORT_ERR = 3;
|
||||
|
||||
// Added by File API specification
|
||||
FileError.NOT_READABLE_ERR = 4;
|
||||
FileError.ENCODING_ERR = 5;
|
||||
FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
|
||||
FileError.INVALID_STATE_ERR = 7;
|
||||
FileError.SYNTAX_ERR = 8;
|
||||
FileError.INVALID_MODIFICATION_ERR = 9;
|
||||
FileError.QUOTA_EXCEEDED_ERR = 10;
|
||||
FileError.TYPE_MISMATCH_ERR = 11;
|
||||
FileError.PATH_EXISTS_ERR = 12;
|
||||
|
||||
module.exports = FileError;
|
||||
|
||||
});
|
300
platforms/browser/platform_www/plugins/cordova-plugin-file/www/FileReader.js
vendored
Normal file
|
@ -0,0 +1,300 @@
|
|||
cordova.define("cordova-plugin-file.FileReader", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var utils = require('cordova/utils');
|
||||
var FileError = require('./FileError');
|
||||
var ProgressEvent = require('./ProgressEvent');
|
||||
var origFileReader = modulemapper.getOriginalSymbol(window, 'FileReader');
|
||||
|
||||
/**
|
||||
* This class reads the mobile device file system.
|
||||
*
|
||||
* For Android:
|
||||
* The root directory is the root of the file system.
|
||||
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
||||
* @constructor
|
||||
*/
|
||||
var FileReader = function () {
|
||||
this._readyState = 0;
|
||||
this._error = null;
|
||||
this._result = null;
|
||||
this._progress = null;
|
||||
this._localURL = '';
|
||||
this._realReader = origFileReader ? new origFileReader() : {}; // eslint-disable-line new-cap
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the maximum size to read at a time via the native API. The default value is a compromise between
|
||||
* minimizing the overhead of many exec() calls while still reporting progress frequently enough for large files.
|
||||
* (Note attempts to allocate more than a few MB of contiguous memory on the native side are likely to cause
|
||||
* OOM exceptions, while the JS engine seems to have fewer problems managing large strings or ArrayBuffers.)
|
||||
*/
|
||||
FileReader.READ_CHUNK_SIZE = 256 * 1024;
|
||||
|
||||
// States
|
||||
FileReader.EMPTY = 0;
|
||||
FileReader.LOADING = 1;
|
||||
FileReader.DONE = 2;
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'readyState', function () {
|
||||
return this._localURL ? this._readyState : this._realReader.readyState;
|
||||
});
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'error', function () {
|
||||
return this._localURL ? this._error : this._realReader.error;
|
||||
});
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'result', function () {
|
||||
return this._localURL ? this._result : this._realReader.result;
|
||||
});
|
||||
|
||||
function defineEvent (eventName) {
|
||||
utils.defineGetterSetter(FileReader.prototype, eventName, function () {
|
||||
return this._realReader[eventName] || null;
|
||||
}, function (value) {
|
||||
this._realReader[eventName] = value;
|
||||
});
|
||||
}
|
||||
defineEvent('onloadstart'); // When the read starts.
|
||||
defineEvent('onprogress'); // While reading (and decoding) file or fileBlob data, and reporting partial file data (progress.loaded/progress.total)
|
||||
defineEvent('onload'); // When the read has successfully completed.
|
||||
defineEvent('onerror'); // When the read has failed (see errors).
|
||||
defineEvent('onloadend'); // When the request has completed (either in success or failure).
|
||||
defineEvent('onabort'); // When the read has been aborted. For instance, by invoking the abort() method.
|
||||
|
||||
function initRead (reader, file) {
|
||||
// Already loading something
|
||||
if (reader.readyState === FileReader.LOADING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
reader._result = null;
|
||||
reader._error = null;
|
||||
reader._progress = 0;
|
||||
reader._readyState = FileReader.LOADING;
|
||||
|
||||
if (typeof file.localURL === 'string') {
|
||||
reader._localURL = file.localURL;
|
||||
} else {
|
||||
reader._localURL = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
if (reader.onloadstart) {
|
||||
reader.onloadstart(new ProgressEvent('loadstart', {target: reader}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used by the following read* functions to handle incremental or final success.
|
||||
* Must be bound to the FileReader's this along with all but the last parameter,
|
||||
* e.g. readSuccessCallback.bind(this, "readAsText", "UTF-8", offset, totalSize, accumulate)
|
||||
* @param readType The name of the read function to call.
|
||||
* @param encoding Text encoding, or null if this is not a text type read.
|
||||
* @param offset Starting offset of the read.
|
||||
* @param totalSize Total number of bytes or chars to read.
|
||||
* @param accumulate A function that takes the callback result and accumulates it in this._result.
|
||||
* @param r Callback result returned by the last read exec() call, or null to begin reading.
|
||||
*/
|
||||
function readSuccessCallback (readType, encoding, offset, totalSize, accumulate, r) {
|
||||
if (this._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
var CHUNK_SIZE = FileReader.READ_CHUNK_SIZE;
|
||||
if (readType === 'readAsDataURL') {
|
||||
// Windows proxy does not support reading file slices as Data URLs
|
||||
// so read the whole file at once.
|
||||
CHUNK_SIZE = cordova.platformId === 'windows' ? totalSize : // eslint-disable-line no-undef
|
||||
// Calculate new chunk size for data URLs to be multiply of 3
|
||||
// Otherwise concatenated base64 chunks won't be valid base64 data
|
||||
FileReader.READ_CHUNK_SIZE - (FileReader.READ_CHUNK_SIZE % 3) + 3;
|
||||
}
|
||||
|
||||
if (typeof r !== 'undefined') {
|
||||
accumulate(r);
|
||||
this._progress = Math.min(this._progress + CHUNK_SIZE, totalSize);
|
||||
|
||||
if (typeof this.onprogress === 'function') {
|
||||
this.onprogress(new ProgressEvent('progress', {loaded: this._progress, total: totalSize}));
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof r === 'undefined' || this._progress < totalSize) {
|
||||
var execArgs = [
|
||||
this._localURL,
|
||||
offset + this._progress,
|
||||
offset + this._progress + Math.min(totalSize - this._progress, CHUNK_SIZE)];
|
||||
if (encoding) {
|
||||
execArgs.splice(1, 0, encoding);
|
||||
}
|
||||
exec(
|
||||
readSuccessCallback.bind(this, readType, encoding, offset, totalSize, accumulate),
|
||||
readFailureCallback.bind(this),
|
||||
'File', readType, execArgs);
|
||||
} else {
|
||||
this._readyState = FileReader.DONE;
|
||||
|
||||
if (typeof this.onload === 'function') {
|
||||
this.onload(new ProgressEvent('load', {target: this}));
|
||||
}
|
||||
|
||||
if (typeof this.onloadend === 'function') {
|
||||
this.onloadend(new ProgressEvent('loadend', {target: this}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback used by the following read* functions to handle errors.
|
||||
* Must be bound to the FileReader's this, e.g. readFailureCallback.bind(this)
|
||||
*/
|
||||
function readFailureCallback (e) {
|
||||
if (this._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._readyState = FileReader.DONE;
|
||||
this._result = null;
|
||||
this._error = new FileError(e);
|
||||
|
||||
if (typeof this.onerror === 'function') {
|
||||
this.onerror(new ProgressEvent('error', {target: this}));
|
||||
}
|
||||
|
||||
if (typeof this.onloadend === 'function') {
|
||||
this.onloadend(new ProgressEvent('loadend', {target: this}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort reading file.
|
||||
*/
|
||||
FileReader.prototype.abort = function () {
|
||||
if (origFileReader && !this._localURL) {
|
||||
return this._realReader.abort();
|
||||
}
|
||||
this._result = null;
|
||||
|
||||
if (this._readyState === FileReader.DONE || this._readyState === FileReader.EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._readyState = FileReader.DONE;
|
||||
|
||||
// If abort callback
|
||||
if (typeof this.onabort === 'function') {
|
||||
this.onabort(new ProgressEvent('abort', {target: this}));
|
||||
}
|
||||
// If load end callback
|
||||
if (typeof this.onloadend === 'function') {
|
||||
this.onloadend(new ProgressEvent('loadend', {target: this}));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Read text file.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
* @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
|
||||
*/
|
||||
FileReader.prototype.readAsText = function (file, encoding) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsText(file, encoding);
|
||||
}
|
||||
|
||||
// Default encoding is UTF-8
|
||||
var enc = encoding || 'UTF-8';
|
||||
|
||||
var totalSize = file.end - file.start;
|
||||
readSuccessCallback.bind(this)('readAsText', enc, file.start, totalSize, function (r) {
|
||||
if (this._progress === 0) {
|
||||
this._result = '';
|
||||
}
|
||||
this._result += r;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Read file and return data as a base64 encoded data url.
|
||||
* A data url is of the form:
|
||||
* data:[<mediatype>][;base64],<data>
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsDataURL = function (file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
var totalSize = file.end - file.start;
|
||||
readSuccessCallback.bind(this)('readAsDataURL', null, file.start, totalSize, function (r) {
|
||||
var commaIndex = r.indexOf(',');
|
||||
if (this._progress === 0) {
|
||||
this._result = r;
|
||||
} else {
|
||||
this._result += r.substring(commaIndex + 1);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Read file and return data as a binary data.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsBinaryString = function (file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsBinaryString(file);
|
||||
}
|
||||
|
||||
var totalSize = file.end - file.start;
|
||||
readSuccessCallback.bind(this)('readAsBinaryString', null, file.start, totalSize, function (r) {
|
||||
if (this._progress === 0) {
|
||||
this._result = '';
|
||||
}
|
||||
this._result += r;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Read file and return data as a binary data.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsArrayBuffer = function (file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
var totalSize = file.end - file.start;
|
||||
readSuccessCallback.bind(this)('readAsArrayBuffer', null, file.start, totalSize, function (r) {
|
||||
var resultArray = (this._progress === 0 ? new Uint8Array(totalSize) : new Uint8Array(this._result));
|
||||
resultArray.set(new Uint8Array(r), this._progress);
|
||||
this._result = resultArray.buffer;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
module.exports = FileReader;
|
||||
|
||||
});
|
57
platforms/browser/platform_www/plugins/cordova-plugin-file/www/FileSystem.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
cordova.define("cordova-plugin-file.FileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
|
||||
/**
|
||||
* An interface representing a file system
|
||||
*
|
||||
* @constructor
|
||||
* {DOMString} name the unique name of the file system (readonly)
|
||||
* {DirectoryEntry} root directory of the file system (readonly)
|
||||
*/
|
||||
var FileSystem = function (name, root) {
|
||||
this.name = name;
|
||||
if (root) {
|
||||
this.root = new DirectoryEntry(root.name, root.fullPath, this, root.nativeURL);
|
||||
} else {
|
||||
this.root = new DirectoryEntry(this.name, '/', this);
|
||||
}
|
||||
};
|
||||
|
||||
FileSystem.prototype.__format__ = function (fullPath, nativeUrl) {
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
FileSystem.prototype.toJSON = function () {
|
||||
return '<FileSystem: ' + this.name + '>';
|
||||
};
|
||||
|
||||
// Use instead of encodeURI() when encoding just the path part of a URI rather than an entire URI.
|
||||
FileSystem.encodeURIPath = function (path) {
|
||||
// Because # is a valid filename character, it must be encoded to prevent part of the
|
||||
// path from being parsed as a URI fragment.
|
||||
return encodeURI(path).replace(/#/g, '%23');
|
||||
};
|
||||
|
||||
module.exports = FileSystem;
|
||||
|
||||
});
|
43
platforms/browser/platform_www/plugins/cordova-plugin-file/www/FileUploadOptions.js
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
cordova.define("cordova-plugin-file.FileUploadOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Options to customize the HTTP request used to upload files.
|
||||
* @constructor
|
||||
* @param fileKey {String} Name of file request parameter.
|
||||
* @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
|
||||
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
||||
* @param params {Object} Object with key: value params to send to the server.
|
||||
* @param headers {Object} Keys are header names, values are header values. Multiple
|
||||
* headers of the same name are not supported.
|
||||
*/
|
||||
var FileUploadOptions = function (fileKey, fileName, mimeType, params, headers, httpMethod) {
|
||||
this.fileKey = fileKey || null;
|
||||
this.fileName = fileName || null;
|
||||
this.mimeType = mimeType || null;
|
||||
this.params = params || null;
|
||||
this.headers = headers || null;
|
||||
this.httpMethod = httpMethod || null;
|
||||
};
|
||||
|
||||
module.exports = FileUploadOptions;
|
||||
|
||||
});
|
32
platforms/browser/platform_www/plugins/cordova-plugin-file/www/FileUploadResult.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
cordova.define("cordova-plugin-file.FileUploadResult", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileUploadResult
|
||||
* @constructor
|
||||
*/
|
||||
module.exports = function FileUploadResult (size, code, content) {
|
||||
this.bytesSent = size;
|
||||
this.responseCode = code;
|
||||
this.response = content;
|
||||
};
|
||||
|
||||
});
|
326
platforms/browser/platform_www/plugins/cordova-plugin-file/www/FileWriter.js
vendored
Normal file
|
@ -0,0 +1,326 @@
|
|||
cordova.define("cordova-plugin-file.FileWriter", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var FileError = require('./FileError');
|
||||
var ProgressEvent = require('./ProgressEvent');
|
||||
|
||||
/**
|
||||
* This class writes to the mobile device file system.
|
||||
*
|
||||
* For Android:
|
||||
* The root directory is the root of the file system.
|
||||
* To write to the SD card, the file name is "sdcard/my_file.txt"
|
||||
*
|
||||
* @constructor
|
||||
* @param file {File} File object containing file properties
|
||||
* @param append if true write to the end of the file, otherwise overwrite the file
|
||||
*/
|
||||
var FileWriter = function (file) {
|
||||
this.fileName = '';
|
||||
this.length = 0;
|
||||
if (file) {
|
||||
this.localURL = file.localURL || file;
|
||||
this.length = file.size || 0;
|
||||
}
|
||||
// default is to write at the beginning of the file
|
||||
this.position = 0;
|
||||
|
||||
this.readyState = 0; // EMPTY
|
||||
|
||||
this.result = null;
|
||||
|
||||
// Error
|
||||
this.error = null;
|
||||
|
||||
// Event handlers
|
||||
this.onwritestart = null; // When writing starts
|
||||
this.onprogress = null; // While writing the file, and reporting partial file data
|
||||
this.onwrite = null; // When the write has successfully completed.
|
||||
this.onwriteend = null; // When the request has completed (either in success or failure).
|
||||
this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
|
||||
this.onerror = null; // When the write has failed (see errors).
|
||||
};
|
||||
|
||||
// States
|
||||
FileWriter.INIT = 0;
|
||||
FileWriter.WRITING = 1;
|
||||
FileWriter.DONE = 2;
|
||||
|
||||
/**
|
||||
* Abort writing file.
|
||||
*/
|
||||
FileWriter.prototype.abort = function () {
|
||||
// check for invalid state
|
||||
if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// set error
|
||||
this.error = new FileError(FileError.ABORT_ERR);
|
||||
|
||||
this.readyState = FileWriter.DONE;
|
||||
|
||||
// If abort callback
|
||||
if (typeof this.onabort === 'function') {
|
||||
this.onabort(new ProgressEvent('abort', {'target': this}));
|
||||
}
|
||||
|
||||
// If write end callback
|
||||
if (typeof this.onwriteend === 'function') {
|
||||
this.onwriteend(new ProgressEvent('writeend', {'target': this}));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes data to the file
|
||||
*
|
||||
* @param data text or blob to be written
|
||||
* @param isPendingBlobReadResult {Boolean} true if the data is the pending blob read operation result
|
||||
*/
|
||||
FileWriter.prototype.write = function (data, isPendingBlobReadResult) {
|
||||
|
||||
var that = this;
|
||||
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
|
||||
/* eslint-disable no-undef */
|
||||
var isProxySupportBlobNatively = (cordova.platformId === 'windows8' || cordova.platformId === 'windows');
|
||||
var isBinary;
|
||||
|
||||
// Check to see if the incoming data is a blob
|
||||
if (data instanceof File || (!isProxySupportBlobNatively && supportsBinary && data instanceof Blob)) {
|
||||
var fileReader = new FileReader();
|
||||
/* eslint-enable no-undef */
|
||||
fileReader.onload = function () {
|
||||
// Call this method again, with the arraybuffer as argument
|
||||
FileWriter.prototype.write.call(that, this.result, true /* isPendingBlobReadResult */);
|
||||
};
|
||||
fileReader.onerror = function () {
|
||||
// DONE state
|
||||
that.readyState = FileWriter.DONE;
|
||||
|
||||
// Save error
|
||||
that.error = this.error;
|
||||
|
||||
// If onerror callback
|
||||
if (typeof that.onerror === 'function') {
|
||||
that.onerror(new ProgressEvent('error', {'target': that}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof that.onwriteend === 'function') {
|
||||
that.onwriteend(new ProgressEvent('writeend', {'target': that}));
|
||||
}
|
||||
};
|
||||
|
||||
// WRITING state
|
||||
this.readyState = FileWriter.WRITING;
|
||||
|
||||
if (supportsBinary) {
|
||||
fileReader.readAsArrayBuffer(data);
|
||||
} else {
|
||||
fileReader.readAsText(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark data type for safer transport over the binary bridge
|
||||
isBinary = supportsBinary && (data instanceof ArrayBuffer);
|
||||
if (isBinary && cordova.platformId === 'windowsphone') { // eslint-disable-line no-undef
|
||||
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
|
||||
data = Array.apply(null, new Uint8Array(data));
|
||||
}
|
||||
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING && !isPendingBlobReadResult) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// WRITING state
|
||||
this.readyState = FileWriter.WRITING;
|
||||
|
||||
var me = this;
|
||||
|
||||
// If onwritestart callback
|
||||
if (typeof me.onwritestart === 'function') {
|
||||
me.onwritestart(new ProgressEvent('writestart', {'target': me}));
|
||||
}
|
||||
|
||||
// Write file
|
||||
exec(
|
||||
// Success callback
|
||||
function (r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// position always increases by bytes written because file would be extended
|
||||
me.position += r;
|
||||
// The length of the file is now where we are done writing.
|
||||
|
||||
me.length = me.position;
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// If onwrite callback
|
||||
if (typeof me.onwrite === 'function') {
|
||||
me.onwrite(new ProgressEvent('write', {'target': me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === 'function') {
|
||||
me.onwriteend(new ProgressEvent('writeend', {'target': me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function (e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Save error
|
||||
me.error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === 'function') {
|
||||
me.onerror(new ProgressEvent('error', {'target': me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === 'function') {
|
||||
me.onwriteend(new ProgressEvent('writeend', {'target': me}));
|
||||
}
|
||||
}, 'File', 'write', [this.localURL, data, this.position, isBinary]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves the file pointer to the location specified.
|
||||
*
|
||||
* If the offset is a negative number the position of the file
|
||||
* pointer is rewound. If the offset is greater than the file
|
||||
* size the position is set to the end of the file.
|
||||
*
|
||||
* @param offset is the location to move the file pointer to.
|
||||
*/
|
||||
FileWriter.prototype.seek = function (offset) {
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
if (!offset && offset !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// See back from end of file.
|
||||
if (offset < 0) {
|
||||
this.position = Math.max(offset + this.length, 0);
|
||||
// Offset is bigger than file size so set position
|
||||
// to the end of the file.
|
||||
} else if (offset > this.length) {
|
||||
this.position = this.length;
|
||||
// Offset is between 0 and file size so set the position
|
||||
// to start writing.
|
||||
} else {
|
||||
this.position = offset;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Truncates the file to the size specified.
|
||||
*
|
||||
* @param size to chop the file at.
|
||||
*/
|
||||
FileWriter.prototype.truncate = function (size) {
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// WRITING state
|
||||
this.readyState = FileWriter.WRITING;
|
||||
|
||||
var me = this;
|
||||
|
||||
// If onwritestart callback
|
||||
if (typeof me.onwritestart === 'function') {
|
||||
me.onwritestart(new ProgressEvent('writestart', {'target': this}));
|
||||
}
|
||||
|
||||
// Write file
|
||||
exec(
|
||||
// Success callback
|
||||
function (r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Update the length of the file
|
||||
me.length = r;
|
||||
me.position = Math.min(me.position, r);
|
||||
|
||||
// If onwrite callback
|
||||
if (typeof me.onwrite === 'function') {
|
||||
me.onwrite(new ProgressEvent('write', {'target': me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === 'function') {
|
||||
me.onwriteend(new ProgressEvent('writeend', {'target': me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function (e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Save error
|
||||
me.error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === 'function') {
|
||||
me.onerror(new ProgressEvent('error', {'target': me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === 'function') {
|
||||
me.onwriteend(new ProgressEvent('writeend', {'target': me}));
|
||||
}
|
||||
}, 'File', 'truncate', [this.localURL, size]);
|
||||
};
|
||||
|
||||
module.exports = FileWriter;
|
||||
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
cordova.define("cordova-plugin-file.Flags", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Supplies arguments to methods that lookup or create files and directories.
|
||||
*
|
||||
* @param create
|
||||
* {boolean} file or directory if it doesn't exist
|
||||
* @param exclusive
|
||||
* {boolean} used with create; if true the command will fail if
|
||||
* target path exists
|
||||
*/
|
||||
function Flags (create, exclusive) {
|
||||
this.create = create || false;
|
||||
this.exclusive = exclusive || false;
|
||||
}
|
||||
|
||||
module.exports = Flags;
|
||||
|
||||
});
|
25
platforms/browser/platform_www/plugins/cordova-plugin-file/www/LocalFileSystem.js
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
cordova.define("cordova-plugin-file.LocalFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
exports.TEMPORARY = 0;
|
||||
exports.PERSISTENT = 1;
|
||||
|
||||
});
|
|
@ -0,0 +1,42 @@
|
|||
cordova.define("cordova-plugin-file.Metadata", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Information about the state of the file or directory
|
||||
*
|
||||
* {Date} modificationTime (readonly)
|
||||
*/
|
||||
var Metadata = function (metadata) {
|
||||
if (typeof metadata === 'object') {
|
||||
this.modificationTime = new Date(metadata.modificationTime);
|
||||
this.size = metadata.size || 0;
|
||||
} else if (typeof metadata === 'undefined') {
|
||||
this.modificationTime = null;
|
||||
this.size = 0;
|
||||
} else {
|
||||
/* Backwards compatiblity with platforms that only return a timestamp */
|
||||
this.modificationTime = new Date(metadata);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Metadata;
|
||||
|
||||
});
|
69
platforms/browser/platform_www/plugins/cordova-plugin-file/www/ProgressEvent.js
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
cordova.define("cordova-plugin-file.ProgressEvent", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
|
||||
// Feature test: See if we can instantiate a native ProgressEvent;
|
||||
// if so, use that approach,
|
||||
// otherwise fill-in with our own implementation.
|
||||
//
|
||||
// NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
|
||||
var ProgressEvent = (function () {
|
||||
/*
|
||||
var createEvent = function(data) {
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('ProgressEvent', false, false);
|
||||
if (data) {
|
||||
for (var i in data) {
|
||||
if (data.hasOwnProperty(i)) {
|
||||
event[i] = data[i];
|
||||
}
|
||||
}
|
||||
if (data.target) {
|
||||
// TODO: cannot call <some_custom_object>.dispatchEvent
|
||||
// need to first figure out how to implement EventTarget
|
||||
}
|
||||
}
|
||||
return event;
|
||||
};
|
||||
try {
|
||||
var ev = createEvent({type:"abort",target:document});
|
||||
return function ProgressEvent(type, data) {
|
||||
data.type = type;
|
||||
return createEvent(data);
|
||||
};
|
||||
} catch(e){
|
||||
*/
|
||||
return function ProgressEvent (type, dict) {
|
||||
this.type = type;
|
||||
this.bubbles = false;
|
||||
this.cancelBubble = false;
|
||||
this.cancelable = false;
|
||||
this.lengthComputable = false;
|
||||
this.loaded = dict && dict.loaded ? dict.loaded : 0;
|
||||
this.total = dict && dict.total ? dict.total : 0;
|
||||
this.target = dict && dict.target ? dict.target : null;
|
||||
};
|
||||
// }
|
||||
})();
|
||||
|
||||
module.exports = ProgressEvent;
|
||||
|
||||
});
|
32
platforms/browser/platform_www/plugins/cordova-plugin-file/www/browser/FileSystem.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
cordova.define("cordova-plugin-file.firefoxFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* global FILESYSTEM_PREFIX: true, module */
|
||||
|
||||
FILESYSTEM_PREFIX = 'file:///';
|
||||
|
||||
module.exports = {
|
||||
__format__: function (fullPath) {
|
||||
return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : '/') + FileSystem.encodeURIPath(fullPath)); // eslint-disable-line no-undef
|
||||
}
|
||||
};
|
||||
|
||||
});
|
194
platforms/browser/platform_www/plugins/cordova-plugin-file/www/browser/Preparing.js
vendored
Normal file
|
@ -0,0 +1,194 @@
|
|||
cordova.define("cordova-plugin-file.Preparing", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
(function () {
|
||||
/* global require */
|
||||
|
||||
// Only Chrome uses this file.
|
||||
if (!require('./isChrome')()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = require('cordova/channel');
|
||||
var FileError = require('./FileError');
|
||||
var PERSISTENT_FS_QUOTA = 5 * 1024 * 1024;
|
||||
var filePluginIsReadyEvent = new Event('filePluginIsReady'); // eslint-disable-line no-undef
|
||||
|
||||
var entryFunctionsCreated = false;
|
||||
var quotaWasRequested = false;
|
||||
var eventWasThrown = false;
|
||||
|
||||
if (!window.requestFileSystem) {
|
||||
window.requestFileSystem = function (type, size, win, fail) {
|
||||
if (fail) {
|
||||
fail('Not supported');
|
||||
}
|
||||
};
|
||||
} else {
|
||||
window.requestFileSystem(window.TEMPORARY, 1, createFileEntryFunctions, function () {});
|
||||
}
|
||||
|
||||
if (!window.resolveLocalFileSystemURL) {
|
||||
window.resolveLocalFileSystemURL = function (url, win, fail) {
|
||||
if (fail) {
|
||||
fail('Not supported');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Resolves a filesystem entry by its path - which is passed either in standard (filesystem:file://) or
|
||||
// Cordova-specific (cdvfile://) universal way.
|
||||
// Aligns with specification: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#widl-LocalFileSystem-resolveLocalFileSystemURL
|
||||
var nativeResolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
|
||||
window.resolveLocalFileSystemURL = function (url, win, fail) {
|
||||
/* If url starts with `cdvfile` then we need convert it to Chrome real url first:
|
||||
cdvfile://localhost/persistent/path/to/file -> filesystem:file://persistent/path/to/file */
|
||||
if (url.trim().substr(0, 7) === 'cdvfile') {
|
||||
/* Quirk:
|
||||
Plugin supports cdvfile://localhost (local resources) only.
|
||||
I.e. external resources are not supported via cdvfile. */
|
||||
if (url.indexOf('cdvfile://localhost') !== -1) {
|
||||
// Browser supports temporary and persistent only
|
||||
var indexPersistent = url.indexOf('persistent');
|
||||
var indexTemporary = url.indexOf('temporary');
|
||||
|
||||
/* Chrome urls start with 'filesystem:' prefix. See quirk:
|
||||
toURL function in Chrome returns filesystem:-prefixed path depending on application host.
|
||||
For example, filesystem:file:///persistent/somefile.txt,
|
||||
filesystem:http://localhost:8080/persistent/somefile.txt. */
|
||||
var prefix = 'filesystem:file:///';
|
||||
if (location.protocol !== 'file:') { // eslint-disable-line no-undef
|
||||
prefix = 'filesystem:' + location.origin + '/'; // eslint-disable-line no-undef
|
||||
}
|
||||
|
||||
var result;
|
||||
if (indexPersistent !== -1) {
|
||||
// cdvfile://localhost/persistent/path/to/file -> filesystem:file://persistent/path/to/file
|
||||
// or filesystem:http://localhost:8080/persistent/path/to/file
|
||||
result = prefix + 'persistent' + url.substr(indexPersistent + 10);
|
||||
nativeResolveLocalFileSystemURL(result, win, fail);
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexTemporary !== -1) {
|
||||
// cdvfile://localhost/temporary/path/to/file -> filesystem:file://temporary/path/to/file
|
||||
// or filesystem:http://localhost:8080/temporary/path/to/file
|
||||
result = prefix + 'temporary' + url.substr(indexTemporary + 9);
|
||||
nativeResolveLocalFileSystemURL(result, win, fail);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// cdvfile other than local file resource is not supported
|
||||
if (fail) {
|
||||
fail(new FileError(FileError.ENCODING_ERR));
|
||||
}
|
||||
} else {
|
||||
nativeResolveLocalFileSystemURL(url, win, fail);
|
||||
}
|
||||
};
|
||||
|
||||
function createFileEntryFunctions (fs) {
|
||||
fs.root.getFile('todelete_658674_833_4_cdv', {create: true}, function (fileEntry) {
|
||||
var fileEntryType = Object.getPrototypeOf(fileEntry);
|
||||
var entryType = Object.getPrototypeOf(fileEntryType);
|
||||
|
||||
// Save the original method
|
||||
var origToURL = entryType.toURL;
|
||||
entryType.toURL = function () {
|
||||
var origURL = origToURL.call(this);
|
||||
if (this.isDirectory && origURL.substr(-1) !== '/') {
|
||||
return origURL + '/';
|
||||
}
|
||||
return origURL;
|
||||
};
|
||||
|
||||
entryType.toNativeURL = function () {
|
||||
console.warn("DEPRECATED: Update your code to use 'toURL'");
|
||||
return this.toURL();
|
||||
};
|
||||
|
||||
entryType.toInternalURL = function () {
|
||||
if (this.toURL().indexOf('persistent') > -1) {
|
||||
return 'cdvfile://localhost/persistent' + this.fullPath;
|
||||
}
|
||||
|
||||
if (this.toURL().indexOf('temporary') > -1) {
|
||||
return 'cdvfile://localhost/temporary' + this.fullPath;
|
||||
}
|
||||
};
|
||||
|
||||
entryType.setMetadata = function (win, fail /*, metadata */) {
|
||||
if (fail) {
|
||||
fail('Not supported');
|
||||
}
|
||||
};
|
||||
|
||||
fileEntry.createWriter(function (writer) {
|
||||
var originalWrite = writer.write;
|
||||
var writerProto = Object.getPrototypeOf(writer);
|
||||
writerProto.write = function (blob) {
|
||||
if (blob instanceof Blob) { // eslint-disable-line no-undef
|
||||
originalWrite.apply(this, [blob]);
|
||||
} else {
|
||||
var realBlob = new Blob([blob]); // eslint-disable-line no-undef
|
||||
originalWrite.apply(this, [realBlob]);
|
||||
}
|
||||
};
|
||||
|
||||
fileEntry.remove(function () { entryFunctionsCreated = true; }, function () { /* empty callback */ });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
window.initPersistentFileSystem = function (size, win, fail) {
|
||||
if (navigator.webkitPersistentStorage) {
|
||||
navigator.webkitPersistentStorage.requestQuota(size, win, fail);
|
||||
return;
|
||||
}
|
||||
|
||||
fail('This browser does not support this function');
|
||||
};
|
||||
|
||||
window.isFilePluginReadyRaised = function () { return eventWasThrown; };
|
||||
|
||||
window.initPersistentFileSystem(PERSISTENT_FS_QUOTA, function () {
|
||||
console.log('Persistent fs quota granted');
|
||||
quotaWasRequested = true;
|
||||
}, function (e) {
|
||||
console.log('Error occured while trying to request Persistent fs quota: ' + JSON.stringify(e));
|
||||
});
|
||||
|
||||
channel.onCordovaReady.subscribe(function () {
|
||||
function dispatchEventIfReady () {
|
||||
if (entryFunctionsCreated && quotaWasRequested) {
|
||||
window.dispatchEvent(filePluginIsReadyEvent);
|
||||
eventWasThrown = true;
|
||||
} else {
|
||||
setTimeout(dispatchEventIfReady, 100);
|
||||
}
|
||||
}
|
||||
|
||||
dispatchEventIfReady();
|
||||
}, false);
|
||||
})();
|
||||
|
||||
});
|
28
platforms/browser/platform_www/plugins/cordova-plugin-file/www/browser/isChrome.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
cordova.define("cordova-plugin-file.isChrome", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = function () {
|
||||
// window.webkitRequestFileSystem and window.webkitResolveLocalFileSystemURL are available only in Chrome and
|
||||
// possibly a good flag to indicate that we're running in Chrome
|
||||
return window.webkitRequestFileSystem && window.webkitResolveLocalFileSystemURL;
|
||||
};
|
||||
|
||||
});
|
64
platforms/browser/platform_www/plugins/cordova-plugin-file/www/fileSystemPaths.js
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
cordova.define("cordova-plugin-file.fileSystemPaths", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var channel = require('cordova/channel');
|
||||
|
||||
exports.file = {
|
||||
// Read-only directory where the application is installed.
|
||||
applicationDirectory: null,
|
||||
// Root of app's private writable storage
|
||||
applicationStorageDirectory: null,
|
||||
// Where to put app-specific data files.
|
||||
dataDirectory: null,
|
||||
// Cached files that should survive app restarts.
|
||||
// Apps should not rely on the OS to delete files in here.
|
||||
cacheDirectory: null,
|
||||
// Android: the application space on external storage.
|
||||
externalApplicationStorageDirectory: null,
|
||||
// Android: Where to put app-specific data files on external storage.
|
||||
externalDataDirectory: null,
|
||||
// Android: the application cache on external storage.
|
||||
externalCacheDirectory: null,
|
||||
// Android: the external storage (SD card) root.
|
||||
externalRootDirectory: null,
|
||||
// iOS: Temp directory that the OS can clear at will.
|
||||
tempDirectory: null,
|
||||
// iOS: Holds app-specific files that should be synced (e.g. to iCloud).
|
||||
syncedDataDirectory: null,
|
||||
// iOS: Files private to the app, but that are meaningful to other applications (e.g. Office files)
|
||||
documentsDirectory: null,
|
||||
// BlackBerry10: Files globally available to all apps
|
||||
sharedDirectory: null
|
||||
};
|
||||
|
||||
channel.waitForInitialization('onFileSystemPathsReady');
|
||||
channel.onCordovaReady.subscribe(function () {
|
||||
function after (paths) {
|
||||
for (var k in paths) {
|
||||
exports.file[k] = paths[k];
|
||||
}
|
||||
channel.initializationComplete('onFileSystemPathsReady');
|
||||
}
|
||||
exec(after, null, 'File', 'requestAllPaths', []);
|
||||
});
|
||||
|
||||
});
|
27
platforms/browser/platform_www/plugins/cordova-plugin-file/www/fileSystems.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
cordova.define("cordova-plugin-file.fileSystems", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
|
||||
module.exports.getFs = function (name, callback) {
|
||||
callback(null);
|
||||
};
|
||||
|
||||
});
|
83
platforms/browser/platform_www/plugins/cordova-plugin-file/www/requestFileSystem.js
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
cordova.define("cordova-plugin-file.requestFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// For browser platform: not all browsers use this file.
|
||||
function checkBrowser () {
|
||||
if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
|
||||
module.exports = window.requestFileSystem || window.webkitRequestFileSystem;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (checkBrowser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var argscheck = require('cordova/argscheck');
|
||||
var FileError = require('./FileError');
|
||||
var FileSystem = require('./FileSystem');
|
||||
var exec = require('cordova/exec');
|
||||
var fileSystems = require('./fileSystems');
|
||||
|
||||
/**
|
||||
* Request a file system in which to store application data.
|
||||
* @param type local file system type
|
||||
* @param size indicates how much storage space, in bytes, the application expects to need
|
||||
* @param successCallback invoked with a FileSystem object
|
||||
* @param errorCallback invoked if error occurs retrieving file system
|
||||
*/
|
||||
var requestFileSystem = function (type, size, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
|
||||
var fail = function (code) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
|
||||
if (type < 0) {
|
||||
fail(FileError.SYNTAX_ERR);
|
||||
} else {
|
||||
// if successful, return a FileSystem object
|
||||
var success = function (file_system) {
|
||||
if (file_system) {
|
||||
if (successCallback) {
|
||||
fileSystems.getFs(file_system.name, function (fs) {
|
||||
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
|
||||
if (!fs) {
|
||||
fs = new FileSystem(file_system.name, file_system.root);
|
||||
}
|
||||
successCallback(fs);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// no FileSystem object returned
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
exec(success, fail, 'File', 'requestFileSystem', [type, size]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = requestFileSystem;
|
||||
})();
|
||||
|
||||
});
|
93
platforms/browser/platform_www/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
cordova.define("cordova-plugin-file.resolveLocalFileSystemURI", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
// For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
|
||||
function checkBrowser () {
|
||||
if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
|
||||
module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (checkBrowser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var argscheck = require('cordova/argscheck');
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
var FileEntry = require('./FileEntry');
|
||||
var FileError = require('./FileError');
|
||||
var exec = require('cordova/exec');
|
||||
var fileSystems = require('./fileSystems');
|
||||
|
||||
/**
|
||||
* Look up file system Entry referred to by local URI.
|
||||
* @param {DOMString} uri URI referring to a local file or directory
|
||||
* @param successCallback invoked with Entry object corresponding to URI
|
||||
* @param errorCallback invoked if error occurs retrieving file system entry
|
||||
*/
|
||||
module.exports.resolveLocalFileSystemURL = module.exports.resolveLocalFileSystemURL || function (uri, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
|
||||
// error callback
|
||||
var fail = function (error) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new FileError(error));
|
||||
}
|
||||
};
|
||||
// sanity check for 'not:valid:filename' or '/not:valid:filename'
|
||||
// file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
|
||||
if (!uri || uri.split(':').length > 2) {
|
||||
setTimeout(function () {
|
||||
fail(FileError.ENCODING_ERR);
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
// if successful, return either a file or directory entry
|
||||
var success = function (entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem === window.PERSISTENT ? 'persistent' : 'temporary'); // eslint-disable-line no-undef
|
||||
fileSystems.getFs(fsName, function (fs) {
|
||||
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
|
||||
if (!fs) {
|
||||
fs = new FileSystem(fsName, {name: '', fullPath: '/'}); // eslint-disable-line no-undef
|
||||
}
|
||||
var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// no Entry object returned
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
|
||||
exec(success, fail, 'File', 'resolveLocalFileSystemURI', [uri]);
|
||||
};
|
||||
|
||||
module.exports.resolveLocalFileSystemURI = function () {
|
||||
console.log('resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.');
|
||||
module.exports.resolveLocalFileSystemURL.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
});
|
235
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/src/browser/CaptureProxy.js
vendored
Normal file
|
@ -0,0 +1,235 @@
|
|||
cordova.define("cordova-plugin-media-capture.CaptureProxy", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* global require, module */
|
||||
|
||||
var MediaFile = require('cordova-plugin-media-capture.MediaFile');
|
||||
var MediaFileData = require('cordova-plugin-media-capture.MediaFileData');
|
||||
var CaptureError = require('cordova-plugin-media-capture.CaptureError');
|
||||
|
||||
/**
|
||||
* Helper function that converts data URI to Blob
|
||||
* @param {String} dataURI Data URI to convert
|
||||
* @return {Blob} Blob, covnerted from DataURI String
|
||||
*/
|
||||
function dataURItoBlob (dataURI) {
|
||||
// convert base64 to raw binary data held in a string
|
||||
// doesn't handle URLEncoded DataURIs
|
||||
var byteString = atob(dataURI.split(',')[1]); // eslint-disable-line no-undef
|
||||
|
||||
// separate out the mime component
|
||||
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
||||
|
||||
// write the bytes of the string to an ArrayBuffer
|
||||
var ab = new ArrayBuffer(byteString.length);
|
||||
var ia = new Uint8Array(ab);
|
||||
for (var i = 0; i < byteString.length; i++) {
|
||||
ia[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
|
||||
// write the ArrayBuffer to a blob, and you're done
|
||||
return new Blob([ab], { type: mimeString }); // eslint-disable-line no-undef
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates basic camera UI with preview 'video' element and 'Cancel' button
|
||||
* Capture starts, when you clicking on preview.
|
||||
*/
|
||||
function CameraUI () {
|
||||
|
||||
// Root element for preview
|
||||
var container = document.createElement('div');
|
||||
container.style.cssText = 'left: 0px; top: 0px; width: 100%; height: 100%; position: fixed; z-index:9999;' +
|
||||
'padding: 40px; background-color: rgba(0,0,0,0.75);' +
|
||||
'text-align:center; visibility: hidden';
|
||||
|
||||
// Set up root element contetnts
|
||||
container.innerHTML =
|
||||
'<div id="captureHint" style="height:100%; position:relative; display:inline-flex; align-content:flex-start;">' +
|
||||
'<h2 style="position: absolute; width: 100%; background-color: rgba(255,255,255,0.25); margin: 0">' +
|
||||
'Click on preview to capture image. Click outside of preview to cancel.</h1>' +
|
||||
'<video id="capturePreview" style="height: 100%"></video>' +
|
||||
'</div>';
|
||||
|
||||
// Add container element to DOM but do not display it since visibility == hidden
|
||||
document.body.appendChild(container);
|
||||
|
||||
// Create fullscreen preview
|
||||
var preview = document.getElementById('capturePreview');
|
||||
preview.autoplay = true;
|
||||
// We'll show preview only when video element content
|
||||
// is fully loaded to avoid glitches
|
||||
preview.onplay = function () {
|
||||
container.style.visibility = 'visible';
|
||||
};
|
||||
|
||||
this.container = container;
|
||||
this.preview = preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays capture preview
|
||||
* @param {Number} count Number of images to take
|
||||
* @param {Function} successCB Success callback, that accepts data URL of captured image
|
||||
* @param {Function} errorCB Error callback
|
||||
*/
|
||||
CameraUI.prototype.startPreview = function (count, successCB, errorCB) {
|
||||
var that = this;
|
||||
|
||||
this.preview.onclick = function (e) {
|
||||
// proceed with capture here
|
||||
// We don't need to propagate click event to parent elements.
|
||||
// Otherwise click on vieo element will trigger click event handler
|
||||
// for preview root element and cause preview cancellation
|
||||
e.stopPropagation();
|
||||
// Create canvas element, put video frame on it
|
||||
// and save its contant as Data URL
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = this.videoWidth;
|
||||
canvas.height = this.videoHeight;
|
||||
canvas.getContext('2d').drawImage(that.preview, 0, 0);
|
||||
successCB(canvas.toDataURL('image/jpeg'));
|
||||
};
|
||||
|
||||
this.container.onclick = function () {
|
||||
// Cancel capture here
|
||||
errorCB(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
|
||||
};
|
||||
|
||||
navigator.getUserMedia({video: true}, function (previewStream) {
|
||||
// Save video stream to be able to stop it later
|
||||
that._previewStream = previewStream;
|
||||
that.preview.src = URL.createObjectURL(previewStream); // eslint-disable-line no-undef
|
||||
// We don't need to set visibility = true for preview element
|
||||
// since this will be done automatically in onplay event handler
|
||||
}, function (/* err */) {
|
||||
errorCB(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys camera preview, removes all elements created
|
||||
*/
|
||||
CameraUI.prototype.destroyPreview = function () {
|
||||
this.preview.pause();
|
||||
this.preview.src = null;
|
||||
this._previewStream.stop();
|
||||
this._previewStream = null;
|
||||
if (this.container) {
|
||||
document.body.removeChild(this.container);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
captureAudio: function (successCallback, errorCallback) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new CaptureError(CaptureError.CAPTURE_NOT_SUPPORTED));
|
||||
}
|
||||
},
|
||||
|
||||
captureVideo: function (successCallback, errorCallback) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new CaptureError(CaptureError.CAPTURE_NOT_SUPPORTED));
|
||||
}
|
||||
},
|
||||
|
||||
captureImage: function (successCallback, errorCallback, args) {
|
||||
|
||||
var fail = function (code) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new CaptureError(code || CaptureError.CAPTURE_INTERNAL_ERR));
|
||||
}
|
||||
};
|
||||
|
||||
var options = args[0];
|
||||
|
||||
var limit = options.limit || 1;
|
||||
if (typeof limit !== 'number' || limit < 1) {
|
||||
fail(CaptureError.CAPTURE_INVALID_ARGUMENT);
|
||||
return;
|
||||
}
|
||||
|
||||
// Counter for already taken images
|
||||
var imagesTaken = 0;
|
||||
|
||||
navigator.getUserMedia = navigator.getUserMedia ||
|
||||
navigator.webkitGetUserMedia ||
|
||||
navigator.mozGetUserMedia ||
|
||||
navigator.msGetUserMedia;
|
||||
|
||||
if (!navigator.getUserMedia) {
|
||||
fail(CaptureError.CAPTURE_NOT_SUPPORTED);
|
||||
return;
|
||||
}
|
||||
|
||||
var ui = new CameraUI();
|
||||
ui.startPreview(limit, function (data) {
|
||||
// Check if we're done with capture. If so, then destroy UI
|
||||
if (++imagesTaken >= limit) {
|
||||
ui.destroyPreview();
|
||||
}
|
||||
|
||||
// Array of resultant MediaFiles
|
||||
var mediaFiles = [];
|
||||
|
||||
// save data to file here
|
||||
window.requestFileSystem(window.TEMPORARY, data.length * limit, function (fileSystem) {
|
||||
// If we need to capture multiple files, then append counter to filename
|
||||
var fileName = limit <= 1 ? 'image.jpg' : 'image' + imagesTaken + '.jpg';
|
||||
fileSystem.root.getFile(fileName, {create: true}, function (file) {
|
||||
file.createWriter(function (writer) {
|
||||
writer.onwriteend = function () {
|
||||
file.getMetadata(function (meta) {
|
||||
mediaFiles.push(new MediaFile(file.name, file.toURL(), 'image/jpeg', meta.modificationTime, meta.size));
|
||||
// Check if we're done with capture. If so, then call a successCallback
|
||||
if (imagesTaken >= limit) {
|
||||
successCallback(mediaFiles);
|
||||
}
|
||||
}, fail);
|
||||
};
|
||||
writer.onerror = fail;
|
||||
// Since success callback for start preview returns
|
||||
// a base64 encoded string, we need to convert it to blob first
|
||||
writer.write(dataURItoBlob(data));
|
||||
});
|
||||
}, fail);
|
||||
}, fail);
|
||||
}, function (err) {
|
||||
ui.destroyPreview();
|
||||
fail(err.code);
|
||||
});
|
||||
},
|
||||
|
||||
getFormatData: function (successCallback, errorCallback, args) {
|
||||
|
||||
var img = document.createElement('img');
|
||||
img.src = args[0];
|
||||
img.onload = function () {
|
||||
if (successCallback) {
|
||||
successCallback(new MediaFileData(null, 0, img.height, img.width, 0));
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
require('cordova/exec/proxy').add('Capture', module.exports);
|
||||
|
||||
});
|
34
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/CaptureAudioOptions.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
cordova.define("cordova-plugin-media-capture.CaptureAudioOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encapsulates all audio capture operation configuration options.
|
||||
*/
|
||||
var CaptureAudioOptions = function () {
|
||||
// Upper limit of sound clips user can record. Value must be equal or greater than 1.
|
||||
this.limit = 1;
|
||||
// Maximum duration of a single sound clip in seconds.
|
||||
this.duration = 0;
|
||||
};
|
||||
|
||||
module.exports = CaptureAudioOptions;
|
||||
|
||||
});
|
44
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/CaptureError.js
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
cordova.define("cordova-plugin-media-capture.CaptureError", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The CaptureError interface encapsulates all errors in the Capture API.
|
||||
*/
|
||||
var CaptureError = function (c) {
|
||||
this.code = c || null;
|
||||
};
|
||||
|
||||
// Camera or microphone failed to capture image or sound.
|
||||
CaptureError.CAPTURE_INTERNAL_ERR = 0;
|
||||
// Camera application or audio capture application is currently serving other capture request.
|
||||
CaptureError.CAPTURE_APPLICATION_BUSY = 1;
|
||||
// Invalid use of the API (e.g. limit parameter has value less than one).
|
||||
CaptureError.CAPTURE_INVALID_ARGUMENT = 2;
|
||||
// User exited camera application or audio capture application before capturing anything.
|
||||
CaptureError.CAPTURE_NO_MEDIA_FILES = 3;
|
||||
// User denied permissions required to perform the capture request.
|
||||
CaptureError.CAPTURE_PERMISSION_DENIED = 4;
|
||||
// The requested capture operation is not supported.
|
||||
CaptureError.CAPTURE_NOT_SUPPORTED = 20;
|
||||
|
||||
module.exports = CaptureError;
|
||||
|
||||
});
|
32
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/CaptureImageOptions.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
cordova.define("cordova-plugin-media-capture.CaptureImageOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encapsulates all image capture operation configuration options.
|
||||
*/
|
||||
var CaptureImageOptions = function () {
|
||||
// Upper limit of images user can take. Value must be equal or greater than 1.
|
||||
this.limit = 1;
|
||||
};
|
||||
|
||||
module.exports = CaptureImageOptions;
|
||||
|
||||
});
|
36
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/CaptureVideoOptions.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
cordova.define("cordova-plugin-media-capture.CaptureVideoOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encapsulates all video capture operation configuration options.
|
||||
*/
|
||||
var CaptureVideoOptions = function () {
|
||||
// Upper limit of videos user can record. Value must be equal or greater than 1.
|
||||
this.limit = 1;
|
||||
// Maximum duration of a single video clip in seconds.
|
||||
this.duration = 0;
|
||||
// Video quality parameter, 0 means low quality, suitable for MMS messages, and value 1 means high quality.
|
||||
this.quality = 1;
|
||||
};
|
||||
|
||||
module.exports = CaptureVideoOptions;
|
||||
|
||||
});
|
57
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/MediaFile.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
cordova.define("cordova-plugin-media-capture.MediaFile", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var utils = require('cordova/utils');
|
||||
var exec = require('cordova/exec');
|
||||
var File = require('cordova-plugin-file.File');
|
||||
var CaptureError = require('./CaptureError');
|
||||
/**
|
||||
* Represents a single file.
|
||||
*
|
||||
* name {DOMString} name of the file, without path information
|
||||
* fullPath {DOMString} the full path of the file, including the name
|
||||
* type {DOMString} mime type
|
||||
* lastModifiedDate {Date} last modified date
|
||||
* size {Number} size of the file in bytes
|
||||
*/
|
||||
var MediaFile = function (name, localURL, type, lastModifiedDate, size) {
|
||||
MediaFile.__super__.constructor.apply(this, arguments);
|
||||
};
|
||||
|
||||
utils.extend(MediaFile, File);
|
||||
|
||||
/**
|
||||
* Request capture format data for a specific file and type
|
||||
*
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
*/
|
||||
MediaFile.prototype.getFormatData = function (successCallback, errorCallback) {
|
||||
if (typeof this.fullPath === 'undefined' || this.fullPath === null) {
|
||||
errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
|
||||
} else {
|
||||
exec(successCallback, errorCallback, 'Capture', 'getFormatData', [this.fullPath, this.type]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = MediaFile;
|
||||
|
||||
});
|
41
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/MediaFileData.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
cordova.define("cordova-plugin-media-capture.MediaFileData", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* MediaFileData encapsulates format information of a media file.
|
||||
*
|
||||
* @param {DOMString} codecs
|
||||
* @param {long} bitrate
|
||||
* @param {long} height
|
||||
* @param {long} width
|
||||
* @param {float} duration
|
||||
*/
|
||||
var MediaFileData = function (codecs, bitrate, height, width, duration) {
|
||||
this.codecs = codecs || null;
|
||||
this.bitrate = bitrate || 0;
|
||||
this.height = height || 0;
|
||||
this.width = width || 0;
|
||||
this.duration = duration || 0;
|
||||
};
|
||||
|
||||
module.exports = MediaFileData;
|
||||
|
||||
});
|
84
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/capture.js
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
cordova.define("cordova-plugin-media-capture.capture", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
/**
|
||||
* Launches a capture of different types.
|
||||
*
|
||||
* @param (DOMString} type
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureVideoOptions} options
|
||||
*/
|
||||
function _capture (type, successCallback, errorCallback, options) {
|
||||
var win = function (pluginResult) {
|
||||
successCallback(helpers.wrapMediaFiles(pluginResult));
|
||||
};
|
||||
exec(win, errorCallback, 'Capture', type, [options]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Capture interface exposes an interface to the camera and microphone of the hosting device.
|
||||
*/
|
||||
function Capture () {
|
||||
this.supportedAudioModes = [];
|
||||
this.supportedImageModes = [];
|
||||
this.supportedVideoModes = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch audio recorder application for recording audio clip(s).
|
||||
*
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureAudioOptions} options
|
||||
*/
|
||||
Capture.prototype.captureAudio = function (successCallback, errorCallback, options) {
|
||||
_capture('captureAudio', successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch camera application for taking image(s).
|
||||
*
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureImageOptions} options
|
||||
*/
|
||||
Capture.prototype.captureImage = function (successCallback, errorCallback, options) {
|
||||
_capture('captureImage', successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Launch device camera application for recording video(s).
|
||||
*
|
||||
* @param {Function} successCB
|
||||
* @param {Function} errorCB
|
||||
* @param {CaptureVideoOptions} options
|
||||
*/
|
||||
Capture.prototype.captureVideo = function (successCallback, errorCallback, options) {
|
||||
_capture('captureVideo', successCallback, errorCallback, options);
|
||||
};
|
||||
|
||||
module.exports = new Capture();
|
||||
|
||||
});
|
46
platforms/browser/platform_www/plugins/cordova-plugin-media-capture/www/helpers.js
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
cordova.define("cordova-plugin-media-capture.helpers", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var MediaFile = require('./MediaFile');
|
||||
|
||||
function wrapMediaFiles (pluginResult) {
|
||||
var mediaFiles = [];
|
||||
var i;
|
||||
for (i = 0; i < pluginResult.length; i++) {
|
||||
var mediaFile = new MediaFile();
|
||||
mediaFile.name = pluginResult[i].name;
|
||||
|
||||
// Backwards compatibility
|
||||
mediaFile.localURL = pluginResult[i].localURL || pluginResult[i].fullPath;
|
||||
mediaFile.fullPath = pluginResult[i].fullPath;
|
||||
mediaFile.type = pluginResult[i].type;
|
||||
mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
|
||||
mediaFile.size = pluginResult[i].size;
|
||||
mediaFiles.push(mediaFile);
|
||||
}
|
||||
return mediaFiles;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
wrapMediaFiles: wrapMediaFiles
|
||||
};
|
||||
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
cordova.define("phonegap-plugin-barcodescanner.BarcodeScannerProxy", function(require, exports, module) { function scan(success, error) {
|
||||
var code = window.prompt("Enter barcode value (empty value will fire the error handler):");
|
||||
if(code) {
|
||||
var result = {
|
||||
text:code,
|
||||
format:"Fake",
|
||||
cancelled:false
|
||||
};
|
||||
success(result);
|
||||
} else {
|
||||
error("No barcode");
|
||||
}
|
||||
}
|
||||
|
||||
function encode(type, data, success, errorCallback) {
|
||||
success();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
scan: scan,
|
||||
encode: encode
|
||||
};
|
||||
|
||||
require("cordova/exec/proxy").add("BarcodeScanner",module.exports);
|
||||
});
|
|
@ -0,0 +1,158 @@
|
|||
cordova.define("phonegap-plugin-barcodescanner.BarcodeScanner", function(require, exports, module) { /**
|
||||
* cordova is available under the MIT License (2008).
|
||||
* See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) Matt Kane 2010
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
* Copyright (c) 2012-2017, Adobe Systems
|
||||
*/
|
||||
|
||||
|
||||
var exec = cordova.require("cordova/exec");
|
||||
|
||||
var scanInProgress = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @returns {BarcodeScanner}
|
||||
*/
|
||||
function BarcodeScanner() {
|
||||
|
||||
/**
|
||||
* Encoding constants.
|
||||
*
|
||||
* @type Object
|
||||
*/
|
||||
this.Encode = {
|
||||
TEXT_TYPE: "TEXT_TYPE",
|
||||
EMAIL_TYPE: "EMAIL_TYPE",
|
||||
PHONE_TYPE: "PHONE_TYPE",
|
||||
SMS_TYPE: "SMS_TYPE"
|
||||
// CONTACT_TYPE: "CONTACT_TYPE", // TODO: not implemented, requires passing a Bundle class from Javascript to Java
|
||||
// LOCATION_TYPE: "LOCATION_TYPE" // TODO: not implemented, requires passing a Bundle class from Javascript to Java
|
||||
};
|
||||
|
||||
/**
|
||||
* Barcode format constants, defined in ZXing library.
|
||||
*
|
||||
* @type Object
|
||||
*/
|
||||
this.format = {
|
||||
"all_1D": 61918,
|
||||
"aztec": 1,
|
||||
"codabar": 2,
|
||||
"code_128": 16,
|
||||
"code_39": 4,
|
||||
"code_93": 8,
|
||||
"data_MATRIX": 32,
|
||||
"ean_13": 128,
|
||||
"ean_8": 64,
|
||||
"itf": 256,
|
||||
"maxicode": 512,
|
||||
"msi": 131072,
|
||||
"pdf_417": 1024,
|
||||
"plessey": 262144,
|
||||
"qr_CODE": 2048,
|
||||
"rss_14": 4096,
|
||||
"rss_EXPANDED": 8192,
|
||||
"upc_A": 16384,
|
||||
"upc_E": 32768,
|
||||
"upc_EAN_EXTENSION": 65536
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Read code from scanner.
|
||||
*
|
||||
* @param {Function} successCallback This function will recieve a result object: {
|
||||
* text : '12345-mock', // The code that was scanned.
|
||||
* format : 'FORMAT_NAME', // Code format.
|
||||
* cancelled : true/false, // Was canceled.
|
||||
* }
|
||||
* @param {Function} errorCallback
|
||||
* @param config
|
||||
*/
|
||||
BarcodeScanner.prototype.scan = function (successCallback, errorCallback, config) {
|
||||
|
||||
if (config instanceof Array) {
|
||||
// do nothing
|
||||
} else {
|
||||
if (typeof(config) === 'object') {
|
||||
// string spaces between formats, ZXing does not like that
|
||||
if (config.formats) {
|
||||
config.formats = config.formats.replace(/\s+/g, '');
|
||||
}
|
||||
config = [ config ];
|
||||
} else {
|
||||
config = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCallback == null) {
|
||||
errorCallback = function () {
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof errorCallback != "function") {
|
||||
console.log("BarcodeScanner.scan failure: failure parameter not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof successCallback != "function") {
|
||||
console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
|
||||
return;
|
||||
}
|
||||
|
||||
if (scanInProgress) {
|
||||
errorCallback('Scan is already in progress');
|
||||
return;
|
||||
}
|
||||
|
||||
scanInProgress = true;
|
||||
|
||||
exec(
|
||||
function(result) {
|
||||
scanInProgress = false;
|
||||
// work around bug in ZXing library
|
||||
if (result.format === 'UPC_A' && result.text.length === 13) {
|
||||
result.text = result.text.substring(1);
|
||||
}
|
||||
successCallback(result);
|
||||
},
|
||||
function(error) {
|
||||
scanInProgress = false;
|
||||
errorCallback(error);
|
||||
},
|
||||
'BarcodeScanner',
|
||||
'scan',
|
||||
config
|
||||
);
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
|
||||
if (errorCallback == null) {
|
||||
errorCallback = function () {
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof errorCallback != "function") {
|
||||
console.log("BarcodeScanner.encode failure: failure parameter not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof successCallback != "function") {
|
||||
console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
|
||||
return;
|
||||
}
|
||||
|
||||
exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
|
||||
{"type": type, "data": data, "options": options}
|
||||
]);
|
||||
};
|
||||
|
||||
var barcodeScanner = new BarcodeScanner();
|
||||
module.exports = barcodeScanner;
|
||||
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<widget id="es.verdnatura.verdnaturafoto" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
||||
<name>Nature Photo</name>
|
||||
<description>
|
||||
A sample Apache Cordova application that responds to the deviceready event.
|
||||
</description>
|
||||
<author email="dev@cordova.apache.org" href="http://cordova.io">
|
||||
Apache Cordova Team
|
||||
</author>
|
||||
<content src="index.html" />
|
||||
<access origin="*" />
|
||||
<allow-intent href="http://*/*" />
|
||||
<allow-intent href="https://*/*" />
|
||||
<allow-intent href="tel:*" />
|
||||
<allow-intent href="sms:*" />
|
||||
<allow-intent href="mailto:*" />
|
||||
<allow-intent href="geo:*" />
|
||||
</widget>
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exports the ExposedJsApi.java object if available, otherwise exports the PromptBasedNativeApi.
|
||||
*/
|
||||
|
||||
var nativeApi = this._cordovaNative || require('cordova/android/promptbasednativeapi');
|
||||
var currentApi = nativeApi;
|
||||
|
||||
module.exports = {
|
||||
get: function() { return currentApi; },
|
||||
setPreferPrompt: function(value) {
|
||||
currentApi = value ? require('cordova/android/promptbasednativeapi') : nativeApi;
|
||||
},
|
||||
// Used only by tests.
|
||||
set: function(value) {
|
||||
currentApi = value;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
|
||||
* This is used pre-JellyBean, where addJavascriptInterface() is disabled.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
exec: function(bridgeSecret, service, action, callbackId, argsJson) {
|
||||
return prompt(argsJson, 'gap:'+JSON.stringify([bridgeSecret, service, action, callbackId]));
|
||||
},
|
||||
setNativeToJsBridgeMode: function(bridgeSecret, value) {
|
||||
prompt(value, 'gap_bridge_mode:' + bridgeSecret);
|
||||
},
|
||||
retrieveJsMessages: function(bridgeSecret, fromOnlineEvent) {
|
||||
return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var config;
|
||||
|
||||
function Config(xhr) {
|
||||
function loadPreferences(xhr) {
|
||||
var parser = new DOMParser();
|
||||
var doc = parser.parseFromString(xhr.responseText, "application/xml");
|
||||
|
||||
var preferences = doc.getElementsByTagName("preference");
|
||||
return Array.prototype.slice.call(preferences);
|
||||
}
|
||||
|
||||
this.xhr = xhr;
|
||||
this.preferences = loadPreferences(this.xhr);
|
||||
}
|
||||
|
||||
function readConfig(success, error) {
|
||||
var xhr;
|
||||
|
||||
if(typeof config != 'undefined') {
|
||||
success(config);
|
||||
}
|
||||
|
||||
function fail(msg) {
|
||||
console.error(msg);
|
||||
|
||||
if(error) {
|
||||
error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
var xhrStatusChangeHandler = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 /* file:// */) {
|
||||
config = new Config(xhr);
|
||||
success(config);
|
||||
}
|
||||
else {
|
||||
fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", xhrStatusChangeHandler);
|
||||
|
||||
|
||||
try {
|
||||
xhr.open("get", "config.xml", true);
|
||||
xhr.send();
|
||||
} catch(e) {
|
||||
fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a preference value from config.xml.
|
||||
* Returns preference value or undefined if it does not exist.
|
||||
* @param {String} preferenceName Preference name to read */
|
||||
Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) {
|
||||
var preferenceItem = this.preferences && this.preferences.filter(function(item) {
|
||||
return item.attributes.name && item.attributes.name.value === preferenceName;
|
||||
});
|
||||
|
||||
if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
|
||||
return preferenceItem[0].attributes.value.value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.readConfig = readConfig;
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*jslint sloppy:true, plusplus:true*/
|
||||
/*global require, module, console */
|
||||
|
||||
var cordova = require('cordova');
|
||||
var execProxy = require('cordova/exec/proxy');
|
||||
|
||||
/**
|
||||
* Execute a cordova command. It is up to the native side whether this action
|
||||
* is synchronous or asynchronous. The native side can return:
|
||||
* Synchronous: PluginResult object as a JSON string
|
||||
* Asynchronous: Empty string ""
|
||||
* If async, the native side will cordova.callbackSuccess or cordova.callbackError,
|
||||
* depending upon the result of the action.
|
||||
*
|
||||
* @param {Function} success The success callback
|
||||
* @param {Function} fail The fail callback
|
||||
* @param {String} service The name of the service to use
|
||||
* @param {String} action Action to be run in cordova
|
||||
* @param {String[]} [args] Zero or more arguments to pass to the method
|
||||
*/
|
||||
module.exports = function (success, fail, service, action, args) {
|
||||
|
||||
var proxy = execProxy.get(service, action);
|
||||
|
||||
args = args || [];
|
||||
|
||||
if (proxy) {
|
||||
|
||||
var callbackId = service + cordova.callbackId++;
|
||||
|
||||
if (typeof success === "function" || typeof fail === "function") {
|
||||
cordova.callbacks[callbackId] = {success: success, fail: fail};
|
||||
}
|
||||
try {
|
||||
|
||||
|
||||
|
||||
// callbackOptions param represents additional optional parameters command could pass back, like keepCallback or
|
||||
// custom callbackId, for example {callbackId: id, keepCallback: true, status: cordova.callbackStatus.JSON_EXCEPTION }
|
||||
var onSuccess = function (result, callbackOptions) {
|
||||
callbackOptions = callbackOptions || {};
|
||||
var callbackStatus;
|
||||
// covering both undefined and null.
|
||||
// strict null comparison was causing callbackStatus to be undefined
|
||||
// and then no callback was called because of the check in cordova.callbackFromNative
|
||||
// see CB-8996 Mobilespec app hang on windows
|
||||
if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
|
||||
callbackStatus = callbackOptions.status;
|
||||
}
|
||||
else {
|
||||
callbackStatus = cordova.callbackStatus.OK;
|
||||
}
|
||||
cordova.callbackSuccess(callbackOptions.callbackId || callbackId,
|
||||
{
|
||||
status: callbackStatus,
|
||||
message: result,
|
||||
keepCallback: callbackOptions.keepCallback || false
|
||||
});
|
||||
};
|
||||
var onError = function (err, callbackOptions) {
|
||||
callbackOptions = callbackOptions || {};
|
||||
var callbackStatus;
|
||||
// covering both undefined and null.
|
||||
// strict null comparison was causing callbackStatus to be undefined
|
||||
// and then no callback was called because of the check in cordova.callbackFromNative
|
||||
// note: status can be 0
|
||||
if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
|
||||
callbackStatus = callbackOptions.status;
|
||||
}
|
||||
else {
|
||||
callbackStatus = cordova.callbackStatus.OK;
|
||||
}
|
||||
cordova.callbackError(callbackOptions.callbackId || callbackId,
|
||||
{
|
||||
status: callbackStatus,
|
||||
message: err,
|
||||
keepCallback: callbackOptions.keepCallback || false
|
||||
});
|
||||
};
|
||||
proxy(onSuccess, onError, args);
|
||||
|
||||
} catch (e) {
|
||||
console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);
|
||||
}
|
||||
} else {
|
||||
|
||||
console.log("Error: exec proxy not found for :: " + service + " :: " + action);
|
||||
|
||||
if(typeof fail === "function" ) {
|
||||
fail("Missing Command Error");
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
id: 'browser',
|
||||
cordovaVersion: '4.2.0', // cordova-js
|
||||
|
||||
bootstrap: function() {
|
||||
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var channel = require('cordova/channel');
|
||||
|
||||
modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
|
||||
|
||||
channel.onNativeReady.fire();
|
||||
|
||||
document.addEventListener("visibilitychange", function(){
|
||||
if(document.hidden) {
|
||||
channel.onPause.fire();
|
||||
}
|
||||
else {
|
||||
channel.onResume.fire();
|
||||
}
|
||||
});
|
||||
|
||||
// End of bootstrap
|
||||
}
|
||||
};
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var APP_PLUGIN_NAME = Number(require('cordova').platformVersion.split('.')[0]) >= 4 ? 'CoreAndroid' : 'App';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Clear the resource cache.
|
||||
*/
|
||||
clearCache:function() {
|
||||
exec(null, null, APP_PLUGIN_NAME, "clearCache", []);
|
||||
},
|
||||
|
||||
/**
|
||||
* Load the url into the webview or into new browser instance.
|
||||
*
|
||||
* @param url The URL to load
|
||||
* @param props Properties that can be passed in to the activity:
|
||||
* wait: int => wait msec before loading URL
|
||||
* loadingDialog: "Title,Message" => display a native loading dialog
|
||||
* loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
|
||||
* clearHistory: boolean => clear webview history (default=false)
|
||||
* openExternal: boolean => open in a new browser (default=false)
|
||||
*
|
||||
* Example:
|
||||
* navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
|
||||
*/
|
||||
loadUrl:function(url, props) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "loadUrl", [url, props]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancel loadUrl that is waiting to be loaded.
|
||||
*/
|
||||
cancelLoadUrl:function() {
|
||||
exec(null, null, APP_PLUGIN_NAME, "cancelLoadUrl", []);
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear web history in this web view.
|
||||
* Instead of BACK button loading the previous web page, it will exit the app.
|
||||
*/
|
||||
clearHistory:function() {
|
||||
exec(null, null, APP_PLUGIN_NAME, "clearHistory", []);
|
||||
},
|
||||
|
||||
/**
|
||||
* Go to previous page displayed.
|
||||
* This is the same as pressing the backbutton on Android device.
|
||||
*/
|
||||
backHistory:function() {
|
||||
exec(null, null, APP_PLUGIN_NAME, "backHistory", []);
|
||||
},
|
||||
|
||||
/**
|
||||
* Override the default behavior of the Android back button.
|
||||
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
|
||||
*
|
||||
* Note: The user should not have to call this method. Instead, when the user
|
||||
* registers for the "backbutton" event, this is automatically done.
|
||||
*
|
||||
* @param override T=override, F=cancel override
|
||||
*/
|
||||
overrideBackbutton:function(override) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [override]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Override the default behavior of the Android volume button.
|
||||
* If overridden, when the volume button is pressed, the "volume[up|down]button"
|
||||
* JavaScript event will be fired.
|
||||
*
|
||||
* Note: The user should not have to call this method. Instead, when the user
|
||||
* registers for the "volume[up|down]button" event, this is automatically done.
|
||||
*
|
||||
* @param button volumeup, volumedown
|
||||
* @param override T=override, F=cancel override
|
||||
*/
|
||||
overrideButton:function(button, override) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideButton", [button, override]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Exit and terminate the application.
|
||||
*/
|
||||
exitApp:function() {
|
||||
return exec(null, null, APP_PLUGIN_NAME, "exitApp", []);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,322 @@
|
|||
cordova.define('cordova/plugin_list', function(require, exports, module) {
|
||||
module.exports = [
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraConstants.js",
|
||||
"id": "cordova-plugin-camera.Camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"Camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js",
|
||||
"id": "cordova-plugin-camera.CameraPopoverOptions",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"CameraPopoverOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/www/Camera.js",
|
||||
"id": "cordova-plugin-camera.camera",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"clobbers": [
|
||||
"navigator.camera"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-camera/src/browser/CameraProxy.js",
|
||||
"id": "cordova-plugin-camera.CameraProxy",
|
||||
"pluginId": "cordova-plugin-camera",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-dialogs/www/browser/notification.js",
|
||||
"id": "cordova-plugin-dialogs.notification_browser",
|
||||
"pluginId": "cordova-plugin-dialogs",
|
||||
"merges": [
|
||||
"navigator.notification"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/isChrome.js",
|
||||
"id": "cordova-plugin-file.isChrome",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/Preparing.js",
|
||||
"id": "cordova-plugin-file.Preparing",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/src/browser/FileProxy.js",
|
||||
"id": "cordova-plugin-file.browserFileProxy",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/browser/FileSystem.js",
|
||||
"id": "cordova-plugin-file.firefoxFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureAudioOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureAudioOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureAudioOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureImageOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureImageOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureImageOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureVideoOptions.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureVideoOptions",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureVideoOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/CaptureError.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureError",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"CaptureError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFileData.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFileData",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFileData"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/MediaFile.js",
|
||||
"id": "cordova-plugin-media-capture.MediaFile",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"MediaFile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/helpers.js",
|
||||
"id": "cordova-plugin-media-capture.helpers",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/www/capture.js",
|
||||
"id": "cordova-plugin-media-capture.capture",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"clobbers": [
|
||||
"navigator.device.capture"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-media-capture/src/browser/CaptureProxy.js",
|
||||
"id": "cordova-plugin-media-capture.CaptureProxy",
|
||||
"pluginId": "cordova-plugin-media-capture",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/www/barcodescanner.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScanner",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"clobbers": [
|
||||
"cordova.plugins.barcodeScanner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/phonegap-plugin-barcodescanner/src/browser/BarcodeScannerProxy.js",
|
||||
"id": "phonegap-plugin-barcodescanner.BarcodeScannerProxy",
|
||||
"pluginId": "phonegap-plugin-barcodescanner",
|
||||
"runs": true
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
// TOP OF METADATA
|
||||
{
|
||||
"cordova-plugin-camera": "4.0.3",
|
||||
"cordova-plugin-dialogs": "2.0.1",
|
||||
"cordova-plugin-file": "6.0.1",
|
||||
"cordova-plugin-media-capture": "3.0.2",
|
||||
"cordova-plugin-whitelist": "1.3.3",
|
||||
"phonegap-plugin-barcodescanner": "8.0.1"
|
||||
}
|
||||
// BOTTOM OF METADATA
|
||||
});
|
|
@ -0,0 +1,304 @@
|
|||
/*!
|
||||
* Cropper.js v1.5.1
|
||||
* https://fengyuanchen.github.io/cropperjs
|
||||
*
|
||||
* Copyright 2015-present Chen Fengyuan
|
||||
* Released under the MIT license
|
||||
*
|
||||
* Date: 2019-03-10T09:55:50.492Z
|
||||
*/
|
||||
|
||||
.cropper-container {
|
||||
direction: ltr;
|
||||
font-size: 0;
|
||||
line-height: 0;
|
||||
position: relative;
|
||||
-ms-touch-action: none;
|
||||
touch-action: none;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.cropper-container img {
|
||||
display: block;
|
||||
height: 100%;
|
||||
image-orientation: 0deg;
|
||||
max-height: none !important;
|
||||
max-width: none !important;
|
||||
min-height: 0 !important;
|
||||
min-width: 0 !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cropper-wrap-box,
|
||||
.cropper-canvas,
|
||||
.cropper-drag-box,
|
||||
.cropper-crop-box,
|
||||
.cropper-modal {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.cropper-wrap-box,
|
||||
.cropper-canvas {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cropper-drag-box {
|
||||
background-color: #fff;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cropper-modal {
|
||||
background-color: #000;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.cropper-view-box {
|
||||
display: block;
|
||||
height: 100%;
|
||||
outline: 1px solid #39f;
|
||||
outline-color: rgba(51, 153, 255, 0.75);
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cropper-dashed {
|
||||
border: 0 dashed #eee;
|
||||
display: block;
|
||||
opacity: 0.5;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.cropper-dashed.dashed-h {
|
||||
border-bottom-width: 1px;
|
||||
border-top-width: 1px;
|
||||
height: calc(100% / 3);
|
||||
left: 0;
|
||||
top: calc(100% / 3);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cropper-dashed.dashed-v {
|
||||
border-left-width: 1px;
|
||||
border-right-width: 1px;
|
||||
height: 100%;
|
||||
left: calc(100% / 3);
|
||||
top: 0;
|
||||
width: calc(100% / 3);
|
||||
}
|
||||
|
||||
.cropper-center {
|
||||
display: block;
|
||||
height: 0;
|
||||
left: 50%;
|
||||
opacity: 0.75;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.cropper-center::before,
|
||||
.cropper-center::after {
|
||||
background-color: #eee;
|
||||
content: ' ';
|
||||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.cropper-center::before {
|
||||
height: 1px;
|
||||
left: -3px;
|
||||
top: 0;
|
||||
width: 7px;
|
||||
}
|
||||
|
||||
.cropper-center::after {
|
||||
height: 7px;
|
||||
left: 0;
|
||||
top: -3px;
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
.cropper-face,
|
||||
.cropper-line,
|
||||
.cropper-point {
|
||||
display: block;
|
||||
height: 100%;
|
||||
opacity: 0.1;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cropper-face {
|
||||
background-color: #fff;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.cropper-line {
|
||||
background-color: #39f;
|
||||
}
|
||||
|
||||
.cropper-line.line-e {
|
||||
cursor: ew-resize;
|
||||
right: -3px;
|
||||
top: 0;
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
.cropper-line.line-n {
|
||||
cursor: ns-resize;
|
||||
height: 5px;
|
||||
left: 0;
|
||||
top: -3px;
|
||||
}
|
||||
|
||||
.cropper-line.line-w {
|
||||
cursor: ew-resize;
|
||||
left: -3px;
|
||||
top: 0;
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
.cropper-line.line-s {
|
||||
bottom: -3px;
|
||||
cursor: ns-resize;
|
||||
height: 5px;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.cropper-point {
|
||||
background-color: #39f;
|
||||
height: 5px;
|
||||
opacity: 0.75;
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
.cropper-point.point-e {
|
||||
cursor: ew-resize;
|
||||
margin-top: -3px;
|
||||
right: -3px;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
.cropper-point.point-n {
|
||||
cursor: ns-resize;
|
||||
left: 50%;
|
||||
margin-left: -3px;
|
||||
top: -3px;
|
||||
}
|
||||
|
||||
.cropper-point.point-w {
|
||||
cursor: ew-resize;
|
||||
left: -3px;
|
||||
margin-top: -3px;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
.cropper-point.point-s {
|
||||
bottom: -3px;
|
||||
cursor: s-resize;
|
||||
left: 50%;
|
||||
margin-left: -3px;
|
||||
}
|
||||
|
||||
.cropper-point.point-ne {
|
||||
cursor: nesw-resize;
|
||||
right: -3px;
|
||||
top: -3px;
|
||||
}
|
||||
|
||||
.cropper-point.point-nw {
|
||||
cursor: nwse-resize;
|
||||
left: -3px;
|
||||
top: -3px;
|
||||
}
|
||||
|
||||
.cropper-point.point-sw {
|
||||
bottom: -3px;
|
||||
cursor: nesw-resize;
|
||||
left: -3px;
|
||||
}
|
||||
|
||||
.cropper-point.point-se {
|
||||
bottom: -3px;
|
||||
cursor: nwse-resize;
|
||||
height: 20px;
|
||||
opacity: 1;
|
||||
right: -3px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.cropper-point.point-se {
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.cropper-point.point-se {
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
.cropper-point.point-se {
|
||||
height: 5px;
|
||||
opacity: 0.75;
|
||||
width: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.cropper-point.point-se::before {
|
||||
background-color: #39f;
|
||||
bottom: -50%;
|
||||
content: ' ';
|
||||
display: block;
|
||||
height: 200%;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
right: -50%;
|
||||
width: 200%;
|
||||
}
|
||||
|
||||
.cropper-invisible {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cropper-bg {
|
||||
background-color: #282828;
|
||||
}
|
||||
|
||||
.cropper-hide {
|
||||
display: block;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.cropper-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.cropper-move {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.cropper-crop {
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
.cropper-disabled .cropper-drag-box,
|
||||
.cropper-disabled .cropper-face,
|
||||
.cropper-disabled .cropper-line,
|
||||
.cropper-disabled .cropper-point {
|
||||
cursor: not-allowed;
|
||||
}
|
|
@ -0,0 +1,650 @@
|
|||
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
|
||||
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
|
||||
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
|
||||
|
||||
* {
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0);
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.greenBackground{
|
||||
background: rgba(247,120,36,1);
|
||||
background: -moz-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -webkit-gradient(left bottom, right top, color-stop(0%, rgba(247,120,36,1)), color-stop(23%, rgba(247,120,36,1)), color-stop(100%, rgba(250,217,97,1)));
|
||||
background: -webkit-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -o-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -ms-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f77824', endColorstr='#fad961', GradientType=1 );
|
||||
}
|
||||
|
||||
.blueBackground{
|
||||
background: #282828;
|
||||
|
||||
}
|
||||
|
||||
html{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
}
|
||||
|
||||
body {
|
||||
background: #000;
|
||||
padding: 0px;
|
||||
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
|
||||
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
|
||||
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
|
||||
|
||||
|
||||
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
|
||||
font-size:12px;
|
||||
|
||||
margin:0px;
|
||||
|
||||
|
||||
color: #fff;
|
||||
|
||||
-webkit-transition: background 2s; /* Safari */
|
||||
transition: background 2s;
|
||||
|
||||
}
|
||||
p{
|
||||
text-align: center;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.contentPhoto{
|
||||
width: 100%;
|
||||
padding: 25px 0px;
|
||||
}
|
||||
.blackground{
|
||||
background: #242424;
|
||||
}
|
||||
#photo{
|
||||
max-width: 100%;
|
||||
|
||||
}
|
||||
.btns{
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.cancelar{
|
||||
background: #ddd;
|
||||
}
|
||||
#logomini{
|
||||
float: left;
|
||||
width: 28px;
|
||||
margin: 0px 10px;
|
||||
}
|
||||
.menubtn{
|
||||
width: 100%;
|
||||
margin-top: 0px;
|
||||
overflow: hidden;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
background: #000;
|
||||
height: 50px;
|
||||
padding: 5px 0;
|
||||
left: 0;
|
||||
}
|
||||
.btnmin{
|
||||
float: left;
|
||||
width: 33.3333%;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
padding: 10px 0;
|
||||
height: 100%;
|
||||
}
|
||||
.selected{
|
||||
border-bottom: 3px solid #2A9CD3;
|
||||
}
|
||||
.btnlogout{
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
background-image: url(../img/logout.png);
|
||||
background-position: center;
|
||||
background-size: 25px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
#logo{
|
||||
margin: auto;
|
||||
display: block;
|
||||
width: 80px;
|
||||
margin-top: 50px;
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
h1{
|
||||
color: #fff;
|
||||
font-weight: normal;
|
||||
margin: 13px 10px 0px 10px;
|
||||
font-size: 1.5em;
|
||||
text-align: left;
|
||||
}
|
||||
h2{
|
||||
font-size: 2.5em;
|
||||
}
|
||||
h3{
|
||||
font-weight: lighter;
|
||||
font-size: 2.8em;
|
||||
margin-bottom: -5px;
|
||||
color: rgba(255,255,255,.5);
|
||||
}
|
||||
h4{
|
||||
font-weight: lighter;
|
||||
font-size: 2em;
|
||||
}
|
||||
h5{
|
||||
font-size: 1.5em;
|
||||
}
|
||||
spam{
|
||||
color: #BABABA;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
.menu{
|
||||
padding: 2%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #000;
|
||||
}
|
||||
.btnbarcode{
|
||||
margin-bottom: 10px;
|
||||
background-color: #D4D2D4;
|
||||
background-image: url(../img/barcode.png);
|
||||
background-repeat: no-repeat;
|
||||
background-size: 25px;
|
||||
background-position-y: center;
|
||||
background-position-x: 10px;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
border-radius: 26px;
|
||||
padding-left: 43px;
|
||||
font-size: 1.2em;
|
||||
padding-top: 14px;
|
||||
}
|
||||
.btnsalix{
|
||||
margin-bottom: 10px;
|
||||
background-color: #8DD202;
|
||||
background-image: url(../img/salix.png);
|
||||
background-repeat: no-repeat;
|
||||
background-size: 25px;
|
||||
background-position-y: center;
|
||||
background-position-x: 10px;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
border-radius: 26px;
|
||||
padding-left: 43px;
|
||||
font-size: 1.2em;
|
||||
padding-top: 14px;
|
||||
}
|
||||
label{
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 5px;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
.btnlogout{
|
||||
position: fixed;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
top: 0;
|
||||
right: 0;
|
||||
background-image: url(../img/logout.png);
|
||||
background-repeat: no-repeat;
|
||||
background-size: 25px;
|
||||
background-position: center;
|
||||
}
|
||||
input::placeholder{
|
||||
color: #000;
|
||||
}
|
||||
.input{
|
||||
background: #fff;
|
||||
padding: 14px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 26px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
|
||||
.input img{
|
||||
width: 25px;
|
||||
float: left;
|
||||
}
|
||||
.input input{
|
||||
width: calc(100% - 38px);
|
||||
height: 25px;
|
||||
display: block;
|
||||
float: left;
|
||||
border: none;
|
||||
background: none;
|
||||
margin-left: 8px;
|
||||
color: #000;
|
||||
font-size: 1.2em;
|
||||
|
||||
}
|
||||
input.middle:focus {
|
||||
outline-width: 0;
|
||||
}
|
||||
::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
|
||||
color: #fff;
|
||||
opacity: 1; /* Firefox */
|
||||
}
|
||||
:-ms-input-placeholder { /* Internet Explorer 10-11 */
|
||||
color: #fff;
|
||||
}
|
||||
::-ms-input-placeholder { /* Microsoft Edge */
|
||||
color: #fff;
|
||||
}
|
||||
.target{
|
||||
position: fixed;
|
||||
bottom: -20px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 270px;
|
||||
background: #fff;
|
||||
border-radius: 30px;
|
||||
}
|
||||
.btn{
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
background: #8DD202;
|
||||
color: #000;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
padding: 10px;
|
||||
}
|
||||
.loginbtn{
|
||||
border-radius: 31px;
|
||||
position: fixed;
|
||||
bottom: 15px;
|
||||
left: 0;
|
||||
width: 200px;
|
||||
margin: auto;
|
||||
right: 0;
|
||||
padding: 18px;
|
||||
}
|
||||
.mainheader{
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
padding-top: 30px;
|
||||
}
|
||||
.mainheader img{
|
||||
width: 100px;
|
||||
border-radius: 50%;
|
||||
border: 4px solid #199BA6;
|
||||
|
||||
}
|
||||
.progress{
|
||||
margin-top: 10px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
.progress label{
|
||||
font-size: 1.2em;
|
||||
margin-bottom: 5px;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
.progress .progressbar{
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
background: #DCDCDC;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.progress .progressbar .progresscontent{
|
||||
height: 100%;
|
||||
/*background: #0ECC80;*/
|
||||
width: 70%;
|
||||
border-radius: 20px;
|
||||
border: 1px solid rgba(255,255,255,.3);
|
||||
}
|
||||
.progress .progressbar .progresscontent span{
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
padding-right: 20px;
|
||||
}
|
||||
.target ul{
|
||||
width: 100%;
|
||||
}
|
||||
.target ul li{
|
||||
width: 100%;
|
||||
padding: 30px 30px 0 30px;
|
||||
color: #000;
|
||||
overflow: hidden;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
.floatl {
|
||||
float: left;
|
||||
}
|
||||
.target ul li div img{
|
||||
width: 30px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
header{
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
|
||||
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
}
|
||||
header h1{
|
||||
float: left;
|
||||
margin-bottom: 0px;
|
||||
font-size: 1.4em;
|
||||
margin-top: 2px;
|
||||
margin-left: 0px;
|
||||
font-weight: normal;
|
||||
}
|
||||
.btnback{
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-image: url(../img/back.png);
|
||||
float: left;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 10px;
|
||||
}
|
||||
.btnsave{
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-image: url(../img/shared.png);
|
||||
float: right;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 17px;
|
||||
}
|
||||
ul{
|
||||
list-style: none;
|
||||
}
|
||||
nav{
|
||||
width: 100%;
|
||||
height: auto;
|
||||
overflow: hidden;
|
||||
padding-top: 20px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
nav ul {
|
||||
width: inherit;
|
||||
height: inherit;
|
||||
}
|
||||
nav ul li{
|
||||
float: left;
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-size: cover;
|
||||
margin-right: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.navsemana{
|
||||
padding-top: 0px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
nav .misemanatab li{
|
||||
width: 33.333333%;
|
||||
margin: 0;
|
||||
padding: 5px;
|
||||
height: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
nav .misemanatab li h5{
|
||||
font-weight: normal;
|
||||
font-size: 1.3em;
|
||||
text-align: center;
|
||||
}
|
||||
nav .misemanatab li p{
|
||||
font-weight: bold;
|
||||
font-size: 1.4em;
|
||||
}
|
||||
nav .misemanatab li:not(:last-child){
|
||||
border-right: 1px solid rgba(255,255,255,0);
|
||||
}
|
||||
nav ul li:hover{
|
||||
/* height: 55px;
|
||||
width: 55px;*/
|
||||
}
|
||||
nav .misemanatab li:hover{
|
||||
width: 33.333333%;
|
||||
height: auto;
|
||||
}
|
||||
.btnsemana{
|
||||
background-image: url(../img/semana.png);
|
||||
}
|
||||
.btnsemanaselected{
|
||||
background-image: url(../img/semanag.png);
|
||||
}
|
||||
.btnmes{
|
||||
background-image: url(../img/mes.png);
|
||||
}
|
||||
.btnmesselected{
|
||||
background-image: url(../img/mesg.png);
|
||||
}
|
||||
.btnano{
|
||||
background-image: url(../img/ano.png);
|
||||
}
|
||||
.btnanoselected{
|
||||
background-image: url(../img/anog.png);
|
||||
}
|
||||
.viewhoras{
|
||||
margin: 20px 0;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
background: rgba(38,211,141,.46);
|
||||
overflow: hidden;
|
||||
}
|
||||
.viewhoras img{
|
||||
width: 40px;
|
||||
float: left;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.viewhoras .infohoras{
|
||||
float: right;
|
||||
}
|
||||
.viewhoras .infohoras h3{
|
||||
margin: 0;
|
||||
}
|
||||
.viewhoras .infohoras p{
|
||||
font-size: 2.5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
.bad{
|
||||
color: #FF5947;
|
||||
}
|
||||
.good{
|
||||
color: #007742;
|
||||
}
|
||||
.green{
|
||||
color: #26D38D
|
||||
}
|
||||
.listsemana {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.listsemana .header{
|
||||
background: #fff;
|
||||
padding: 5px;
|
||||
height: auto;
|
||||
}
|
||||
.listsemana .header h3{
|
||||
color: #000;
|
||||
font-size: 1.3em;
|
||||
margin: 0;
|
||||
}
|
||||
.listsemana .registro{
|
||||
border-bottom: 1px solid rgba(255,255,255,1);
|
||||
padding: 10px 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.listsemana .registro img{
|
||||
width: 30px;
|
||||
float: left;
|
||||
}
|
||||
.listsemana .registro p{
|
||||
font-weight: bold;
|
||||
float: left;
|
||||
font-size: 1.3em;
|
||||
margin-top: 3px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
#txtNombre{
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.3);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.workingHours{
|
||||
text-align: center;
|
||||
font-size: 2.5em!important;
|
||||
font-weight: bold;
|
||||
}
|
||||
.rotateAnimation{
|
||||
-webkit-animation:spin 4s linear infinite;
|
||||
-moz-animation:spin 4s linear infinite;
|
||||
animation:spin 4s linear infinite;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.loading{
|
||||
display: none;
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(247,120,36,1);
|
||||
background: -moz-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -webkit-gradient(left bottom, right top, color-stop(0%, rgba(247,120,36,1)), color-stop(23%, rgba(247,120,36,1)), color-stop(100%, rgba(250,217,97,1)));
|
||||
background: -webkit-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -o-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: -ms-linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
background: linear-gradient(45deg, rgba(247,120,36,1) 0%, rgba(247,120,36,1) 23%, rgba(250,217,97,1) 100%);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f77824', endColorstr='#fad961', GradientType=1 );
|
||||
}
|
||||
|
||||
|
||||
.loadingcontent{
|
||||
position: fixed;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.sk-cube-grid {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.sk-cube-grid .sk-cube {
|
||||
width: 33%;
|
||||
height: 33%;
|
||||
background-color: #fff;
|
||||
float: left;
|
||||
-webkit-animation: sk-cubeGridScaleDelay 1.3s infinite ease-in-out;
|
||||
animation: sk-cubeGridScaleDelay 1.3s infinite ease-in-out;
|
||||
}
|
||||
.sk-cube-grid .sk-cube1 {
|
||||
-webkit-animation-delay: 0.2s;
|
||||
animation-delay: 0.2s; }
|
||||
.sk-cube-grid .sk-cube2 {
|
||||
-webkit-animation-delay: 0.3s;
|
||||
animation-delay: 0.3s; }
|
||||
.sk-cube-grid .sk-cube3 {
|
||||
-webkit-animation-delay: 0.4s;
|
||||
animation-delay: 0.4s; }
|
||||
.sk-cube-grid .sk-cube4 {
|
||||
-webkit-animation-delay: 0.1s;
|
||||
animation-delay: 0.1s; }
|
||||
.sk-cube-grid .sk-cube5 {
|
||||
-webkit-animation-delay: 0.2s;
|
||||
animation-delay: 0.2s; }
|
||||
.sk-cube-grid .sk-cube6 {
|
||||
-webkit-animation-delay: 0.3s;
|
||||
animation-delay: 0.3s; }
|
||||
.sk-cube-grid .sk-cube7 {
|
||||
-webkit-animation-delay: 0s;
|
||||
animation-delay: 0s; }
|
||||
.sk-cube-grid .sk-cube8 {
|
||||
-webkit-animation-delay: 0.1s;
|
||||
animation-delay: 0.1s; }
|
||||
.sk-cube-grid .sk-cube9 {
|
||||
-webkit-animation-delay: 0.2s;
|
||||
animation-delay: 0.2s; }
|
||||
|
||||
@-webkit-keyframes sk-cubeGridScaleDelay {
|
||||
0%, 70%, 100% {
|
||||
-webkit-transform: scale3D(1, 1, 1);
|
||||
transform: scale3D(1, 1, 1);
|
||||
} 35% {
|
||||
-webkit-transform: scale3D(0, 0, 1);
|
||||
transform: scale3D(0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sk-cubeGridScaleDelay {
|
||||
0%, 70%, 100% {
|
||||
-webkit-transform: scale3D(1, 1, 1);
|
||||
transform: scale3D(1, 1, 1);
|
||||
} 35% {
|
||||
-webkit-transform: scale3D(0, 0, 1);
|
||||
transform: scale3D(0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@media screen and (max-height:518px){
|
||||
h3 {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
}
|
||||
.workingHours {
|
||||
font-size: 2em!important;
|
||||
}
|
||||
h4 {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
#logo{
|
||||
width: 40px;
|
||||
|
||||
}
|
||||
.loginbtn {
|
||||
position: relative;
|
||||
top: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-height:477px){
|
||||
#txtNombre {
|
||||
padding-bottom: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.9em;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 216 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 893 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 847 B |
|
@ -0,0 +1,59 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
|
||||
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<title>Verdnatura Photo</title>
|
||||
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="js/fastclick.js" type="application/javascript"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<img id="logo" src="img/logo.png" alt="verdnatura"/>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/user.png" alt="verdnatura" />
|
||||
<input type="text" id="txtuser" placeholder="usuario" value=""/>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<img src="img/password.png" alt="verdnatura"/>
|
||||
<input type="password" id="txtpassword" placeholder="contraseña" value=""/>
|
||||
</div>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
|
||||
<div class="btn loginbtn">
|
||||
Entrar
|
||||
</div>
|
||||
|
||||
|
||||
<div class="loading">
|
||||
<div class="loadingcontent">
|
||||
<div class="sk-cube-grid">
|
||||
<div class="sk-cube sk-cube1"></div>
|
||||
<div class="sk-cube sk-cube2"></div>
|
||||
<div class="sk-cube sk-cube3"></div>
|
||||
<div class="sk-cube sk-cube4"></div>
|
||||
<div class="sk-cube sk-cube5"></div>
|
||||
<div class="sk-cube sk-cube6"></div>
|
||||
<div class="sk-cube sk-cube7"></div>
|
||||
<div class="sk-cube sk-cube8"></div>
|
||||
<div class="sk-cube sk-cube9"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="js/login.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,841 @@
|
|||
;(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @preserve FastClick: polyfill to remove click delays on browsers with touch UIs.
|
||||
*
|
||||
* @codingstandard ftlabs-jsv2
|
||||
* @copyright The Financial Times Limited [All Rights Reserved]
|
||||
* @license MIT License (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
/*jslint browser:true, node:true*/
|
||||
/*global define, Event, Node*/
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate fast-clicking listeners on the specified layer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
function FastClick(layer, options) {
|
||||
var oldOnClick;
|
||||
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Whether a click is currently being tracked.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
this.trackingClick = false;
|
||||
|
||||
|
||||
/**
|
||||
* Timestamp for when click tracking started.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The element being tracked for a click.
|
||||
*
|
||||
* @type EventTarget
|
||||
*/
|
||||
this.targetElement = null;
|
||||
|
||||
|
||||
/**
|
||||
* X-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartX = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Y-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartY = 0;
|
||||
|
||||
|
||||
/**
|
||||
* ID of the last touch, retrieved from Touch.identifier.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.lastTouchIdentifier = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Touchmove boundary, beyond which a click will be cancelled.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchBoundary = options.touchBoundary || 10;
|
||||
|
||||
|
||||
/**
|
||||
* The FastClick layer.
|
||||
*
|
||||
* @type Element
|
||||
*/
|
||||
this.layer = layer;
|
||||
|
||||
/**
|
||||
* The minimum time between tap(touchstart and touchend) events
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapDelay = options.tapDelay || 200;
|
||||
|
||||
/**
|
||||
* The maximum time for a tap
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapTimeout = options.tapTimeout || 700;
|
||||
|
||||
if (FastClick.notNeeded(layer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some old versions of Android don't have Function.prototype.bind
|
||||
function bind(method, context) {
|
||||
return function() { return method.apply(context, arguments); };
|
||||
}
|
||||
|
||||
|
||||
var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'];
|
||||
var context = this;
|
||||
for (var i = 0, l = methods.length; i < l; i++) {
|
||||
context[methods[i]] = bind(context[methods[i]], context);
|
||||
}
|
||||
|
||||
// Set up event handlers as required
|
||||
if (deviceIsAndroid) {
|
||||
layer.addEventListener('mouseover', this.onMouse, true);
|
||||
layer.addEventListener('mousedown', this.onMouse, true);
|
||||
layer.addEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.addEventListener('click', this.onClick, true);
|
||||
layer.addEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.addEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.addEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.addEventListener('touchcancel', this.onTouchCancel, false);
|
||||
|
||||
// Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
// which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
|
||||
// layer when they are cancelled.
|
||||
if (!Event.prototype.stopImmediatePropagation) {
|
||||
layer.removeEventListener = function(type, callback, capture) {
|
||||
var rmv = Node.prototype.removeEventListener;
|
||||
if (type === 'click') {
|
||||
rmv.call(layer, type, callback.hijacked || callback, capture);
|
||||
} else {
|
||||
rmv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
|
||||
layer.addEventListener = function(type, callback, capture) {
|
||||
var adv = Node.prototype.addEventListener;
|
||||
if (type === 'click') {
|
||||
adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
|
||||
if (!event.propagationStopped) {
|
||||
callback(event);
|
||||
}
|
||||
}), capture);
|
||||
} else {
|
||||
adv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// If a handler is already declared in the element's onclick attribute, it will be fired before
|
||||
// FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
|
||||
// adding it as listener.
|
||||
if (typeof layer.onclick === 'function') {
|
||||
|
||||
// Android browser on at least 3.2 requires a new reference to the function in layer.onclick
|
||||
// - the old one won't work if passed to addEventListener directly.
|
||||
oldOnClick = layer.onclick;
|
||||
layer.addEventListener('click', function(event) {
|
||||
oldOnClick(event);
|
||||
}, false);
|
||||
layer.onclick = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows Phone 8.1 fakes user agent string to look like Android and iPhone.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
|
||||
|
||||
/**
|
||||
* Android requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS 4 requires an exception for select elements.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
|
||||
|
||||
|
||||
/**
|
||||
* iOS 6.0-7.* requires the target element to be manually derived
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent);
|
||||
|
||||
/**
|
||||
* BlackBerry requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a native click.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element needs a native click
|
||||
*/
|
||||
FastClick.prototype.needsClick = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
|
||||
// Don't send a synthetic click to disabled inputs (issue #62)
|
||||
case 'button':
|
||||
case 'select':
|
||||
case 'textarea':
|
||||
if (target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'input':
|
||||
|
||||
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
|
||||
if ((deviceIsIOS && target.type === 'file') || target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'label':
|
||||
case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
|
||||
case 'video':
|
||||
return true;
|
||||
}
|
||||
|
||||
return (/\bneedsclick\b/).test(target.className);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a call to focus to simulate click into element.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
|
||||
*/
|
||||
FastClick.prototype.needsFocus = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
case 'textarea':
|
||||
return true;
|
||||
case 'select':
|
||||
return !deviceIsAndroid;
|
||||
case 'input':
|
||||
switch (target.type) {
|
||||
case 'button':
|
||||
case 'checkbox':
|
||||
case 'file':
|
||||
case 'image':
|
||||
case 'radio':
|
||||
case 'submit':
|
||||
return false;
|
||||
}
|
||||
|
||||
// No point in attempting to focus disabled inputs
|
||||
return !target.disabled && !target.readOnly;
|
||||
default:
|
||||
return (/\bneedsfocus\b/).test(target.className);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send a click event to the specified element.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
* @param {Event} event
|
||||
*/
|
||||
FastClick.prototype.sendClick = function(targetElement, event) {
|
||||
var clickEvent, touch;
|
||||
|
||||
// On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
|
||||
if (document.activeElement && document.activeElement !== targetElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// Synthesise a click event, with an extra attribute so it can be tracked
|
||||
clickEvent = document.createEvent('MouseEvents');
|
||||
clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
|
||||
clickEvent.forwardedTouchEvent = true;
|
||||
targetElement.dispatchEvent(clickEvent);
|
||||
};
|
||||
|
||||
FastClick.prototype.determineEventType = function(targetElement) {
|
||||
|
||||
//Issue #159: Android Chrome Select Box does not open with a synthetic click event
|
||||
if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
|
||||
return 'mousedown';
|
||||
}
|
||||
|
||||
return 'click';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.focus = function(targetElement) {
|
||||
var length;
|
||||
|
||||
// Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
|
||||
if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') {
|
||||
length = targetElement.value.length;
|
||||
targetElement.setSelectionRange(length, length);
|
||||
} else {
|
||||
targetElement.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.updateScrollParent = function(targetElement) {
|
||||
var scrollParent, parentElement;
|
||||
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
|
||||
// Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
|
||||
// target element was moved to another parent.
|
||||
if (!scrollParent || !scrollParent.contains(targetElement)) {
|
||||
parentElement = targetElement;
|
||||
do {
|
||||
if (parentElement.scrollHeight > parentElement.offsetHeight) {
|
||||
scrollParent = parentElement;
|
||||
targetElement.fastClickScrollParent = parentElement;
|
||||
break;
|
||||
}
|
||||
|
||||
parentElement = parentElement.parentElement;
|
||||
} while (parentElement);
|
||||
}
|
||||
|
||||
// Always update the scroll top tracker if possible.
|
||||
if (scrollParent) {
|
||||
scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget} targetElement
|
||||
* @returns {Element|EventTarget}
|
||||
*/
|
||||
FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
|
||||
|
||||
// On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
|
||||
if (eventTarget.nodeType === Node.TEXT_NODE) {
|
||||
return eventTarget.parentNode;
|
||||
}
|
||||
|
||||
return eventTarget;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch start, record the position and scroll offset.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchStart = function(event) {
|
||||
var targetElement, touch, selection;
|
||||
|
||||
// Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
|
||||
if (event.targetTouches.length > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
targetElement = this.getTargetElementFromEventTarget(event.target);
|
||||
touch = event.targetTouches[0];
|
||||
|
||||
if (deviceIsIOS) {
|
||||
|
||||
// Only trusted events will deselect text on iOS (issue #49)
|
||||
selection = window.getSelection();
|
||||
if (selection.rangeCount && !selection.isCollapsed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!deviceIsIOS4) {
|
||||
|
||||
// Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
|
||||
// when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
|
||||
// with the same identifier as the touch event that previously triggered the click that triggered the alert.
|
||||
// Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
|
||||
// immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
|
||||
// Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string,
|
||||
// which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long,
|
||||
// random integers, it's safe to to continue if the identifier is 0 here.
|
||||
if (touch.identifier && touch.identifier === this.lastTouchIdentifier) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.lastTouchIdentifier = touch.identifier;
|
||||
|
||||
// If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
|
||||
// 1) the user does a fling scroll on the scrollable layer
|
||||
// 2) the user stops the fling scroll with another tap
|
||||
// then the event.target of the last 'touchend' event will be the element that was under the user's finger
|
||||
// when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
|
||||
// is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
|
||||
this.updateScrollParent(targetElement);
|
||||
}
|
||||
}
|
||||
|
||||
this.trackingClick = true;
|
||||
this.trackingClickStart = event.timeStamp;
|
||||
this.targetElement = targetElement;
|
||||
|
||||
this.touchStartX = touch.pageX;
|
||||
this.touchStartY = touch.pageY;
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.touchHasMoved = function(event) {
|
||||
var touch = event.changedTouches[0], boundary = this.touchBoundary;
|
||||
|
||||
if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the last position.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchMove = function(event) {
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the touch has moved, cancel the click tracking
|
||||
if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find the labelled control for the given label element.
|
||||
*
|
||||
* @param {EventTarget|HTMLLabelElement} labelElement
|
||||
* @returns {Element|null}
|
||||
*/
|
||||
FastClick.prototype.findControl = function(labelElement) {
|
||||
|
||||
// Fast path for newer browsers supporting the HTML5 control attribute
|
||||
if (labelElement.control !== undefined) {
|
||||
return labelElement.control;
|
||||
}
|
||||
|
||||
// All browsers under test that support touch events also support the HTML5 htmlFor attribute
|
||||
if (labelElement.htmlFor) {
|
||||
return document.getElementById(labelElement.htmlFor);
|
||||
}
|
||||
|
||||
// If no for attribute exists, attempt to retrieve the first labellable descendant element
|
||||
// the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
|
||||
return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch end, determine whether to send a click event at once.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchEnd = function(event) {
|
||||
var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
|
||||
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
this.cancelNextClick = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset to prevent wrong click cancel on input (issue #156).
|
||||
this.cancelNextClick = false;
|
||||
|
||||
this.lastClickTime = event.timeStamp;
|
||||
|
||||
trackingClickStart = this.trackingClickStart;
|
||||
this.trackingClick = false;
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
// On some iOS devices, the targetElement supplied with the event is invalid if the layer
|
||||
// is performing a transition or scroll, and has to be re-detected manually. Note that
|
||||
// for this to function correctly, it must be called *after* the event target is checked!
|
||||
// See issue #57; also filed as rdar://13048589 .
|
||||
if (deviceIsIOSWithBadTarget) {
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
|
||||
targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
|
||||
targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
|
||||
}
|
||||
|
||||
targetTagName = targetElement.tagName.toLowerCase();
|
||||
if (targetTagName === 'label') {
|
||||
forElement = this.findControl(targetElement);
|
||||
if (forElement) {
|
||||
this.focus(targetElement);
|
||||
if (deviceIsAndroid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
targetElement = forElement;
|
||||
}
|
||||
} else if (this.needsFocus(targetElement)) {
|
||||
|
||||
// Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
|
||||
// Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
|
||||
if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) {
|
||||
this.targetElement = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.focus(targetElement);
|
||||
this.sendClick(targetElement, event);
|
||||
|
||||
// Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
|
||||
// Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
|
||||
if (!deviceIsIOS || targetTagName !== 'select') {
|
||||
this.targetElement = null;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceIsIOS && !deviceIsIOS4) {
|
||||
|
||||
// Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
|
||||
// and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent the actual click from going though - unless the target node is marked as requiring
|
||||
// real clicks or if it is in the allowlist in which case only non-programmatic clicks are permitted.
|
||||
if (!this.needsClick(targetElement)) {
|
||||
event.preventDefault();
|
||||
this.sendClick(targetElement, event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch cancel, stop tracking the click.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.onTouchCancel = function() {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine mouse events which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onMouse = function(event) {
|
||||
|
||||
// If a target element was never set (because a touch event was never fired) allow the event
|
||||
if (!this.targetElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.forwardedTouchEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Programmatically generated events targeting a specific element should be permitted
|
||||
if (!event.cancelable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derive and check the target element to see whether the mouse event needs to be permitted;
|
||||
// unless explicitly enabled, prevent non-touch click events from triggering actions,
|
||||
// to prevent ghost/doubleclicks.
|
||||
if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
|
||||
|
||||
// Prevent any user-added listeners declared on FastClick element from being fired.
|
||||
if (event.stopImmediatePropagation) {
|
||||
event.stopImmediatePropagation();
|
||||
} else {
|
||||
|
||||
// Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
|
||||
// Cancel the event
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the mouse event is permitted, return true for the action to go through.
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On actual clicks, determine whether this is a touch-generated click, a click action occurring
|
||||
* naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
|
||||
* an actual click which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onClick = function(event) {
|
||||
var permitted;
|
||||
|
||||
// It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
|
||||
if (this.trackingClick) {
|
||||
this.targetElement = null;
|
||||
this.trackingClick = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
|
||||
if (event.target.type === 'submit' && event.detail === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
permitted = this.onMouse(event);
|
||||
|
||||
// Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
|
||||
if (!permitted) {
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
// If clicks are permitted, return true for the action to go through.
|
||||
return permitted;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove all FastClick's event listeners.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.destroy = function() {
|
||||
var layer = this.layer;
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
layer.removeEventListener('mouseover', this.onMouse, true);
|
||||
layer.removeEventListener('mousedown', this.onMouse, true);
|
||||
layer.removeEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.removeEventListener('click', this.onClick, true);
|
||||
layer.removeEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.removeEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.removeEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.removeEventListener('touchcancel', this.onTouchCancel, false);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether FastClick is needed.
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
*/
|
||||
FastClick.notNeeded = function(layer) {
|
||||
var metaViewport;
|
||||
var chromeVersion;
|
||||
var blackberryVersion;
|
||||
var firefoxVersion;
|
||||
|
||||
// Devices that don't support touch don't need FastClick
|
||||
if (typeof window.ontouchstart === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Chrome version - zero for other browsers
|
||||
chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1];
|
||||
|
||||
if (chromeVersion) {
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// Chrome 32 and above with width=device-width or less don't need FastClick
|
||||
if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Chrome desktop doesn't need FastClick (issue #15)
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceIsBlackBerry10) {
|
||||
blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/);
|
||||
|
||||
// BlackBerry 10.3+ does not require Fastclick library.
|
||||
// https://github.com/ftlabs/fastclick/issues/251
|
||||
if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// user-scalable=no eliminates click delay.
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// width=device-width (or less than device-width) eliminates click delay.
|
||||
if (document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97)
|
||||
if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Firefox version - zero for other browsers
|
||||
firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1];
|
||||
|
||||
if (firefoxVersion >= 27) {
|
||||
// Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896
|
||||
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx
|
||||
if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Factory method for creating a FastClick object
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
FastClick.attach = function(layer, options) {
|
||||
return new FastClick(layer, options);
|
||||
};
|
||||
|
||||
|
||||
if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
|
||||
|
||||
// AMD. Register as an anonymous module.
|
||||
define(function() {
|
||||
return FastClick;
|
||||
});
|
||||
} else if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = FastClick.attach;
|
||||
module.exports.FastClick = FastClick;
|
||||
} else {
|
||||
window.FastClick = FastClick;
|
||||
}
|
||||
}());
|
|
@ -0,0 +1,321 @@
|
|||
//var url = "http://172.16.198.221:3000/api/";
|
||||
var url = "https://salix.verdnatura.es/api/";
|
||||
var urlweb = "https://verdnatura.es/";
|
||||
var idArticulo = "";
|
||||
var minCroppedWidth = 320;
|
||||
var minCroppedHeight = 160;
|
||||
var maxCroppedWidth = 4032;
|
||||
var maxCroppedHeight = 2688;
|
||||
var ratio = 1;
|
||||
var maxAspectRatio = 1.5;
|
||||
var image;
|
||||
|
||||
var cropper;
|
||||
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
|
||||
FastClick.attach(document.body);
|
||||
//setTimeout(scanBarcode, 1000);
|
||||
image = document.querySelector('#photo');
|
||||
maxCroppedWidth = image.naturalWidth;
|
||||
maxCroppedHeight = (maxCroppedWidth / 3) * 2;
|
||||
minCroppedWidth = maxCroppedWidth / 3;
|
||||
minCroppedHeight = maxCroppedHeight / 3;
|
||||
|
||||
$("#btn1").on("click", function () {
|
||||
ratio = 1;
|
||||
$(".menubtn").children().removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
maxCroppedWidth = image.naturalWidth;
|
||||
maxCroppedHeight = (maxCroppedWidth / 3) * 2;
|
||||
|
||||
});
|
||||
$("#btn2").on("click", function () {
|
||||
ratio = 2;
|
||||
$(".menubtn").children().removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
maxCroppedWidth = image.naturalWidth;
|
||||
maxCroppedHeight = (maxCroppedWidth / 16) * 9;
|
||||
|
||||
|
||||
});
|
||||
$("#btn3").on("click", function () {
|
||||
ratio = 3;
|
||||
$(".menubtn").children().removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
maxCroppedWidth = image.naturalWidth;
|
||||
maxCroppedHeight = (maxCroppedWidth / 1) * 1;
|
||||
|
||||
});
|
||||
|
||||
$(".btnback").on("click", function () {
|
||||
window.location = "main.html";
|
||||
});
|
||||
|
||||
$(".btnsave").on("click", savePhoto);
|
||||
|
||||
|
||||
$(".btnbarcode").on("click", function () {
|
||||
$(".loading").fadeIn(200);
|
||||
scanBarcode();
|
||||
});
|
||||
$("#btntakepicture").on("click", setManualMode);
|
||||
|
||||
$(".btnlogout").on("click", function () {
|
||||
localStorage.removeItem("user");
|
||||
localStorage.removeItem("password");
|
||||
window.location = "index.html";
|
||||
});
|
||||
|
||||
$(".btnsalix").on("click", function () {
|
||||
var target = "_system";
|
||||
var options = "location=no";
|
||||
var url = "https://salix.verdnatura.es";
|
||||
var ref = cordova.InAppBrowser.open(url, target, options);
|
||||
});
|
||||
|
||||
$("#txtarticle").on("keypress", function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
setManualMode();
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function setManualMode() {
|
||||
idArticulo = $("#txtarticle").val();
|
||||
|
||||
if (idArticulo.trim().length > 0) {
|
||||
navigator.notification.confirm(
|
||||
'Article: ' + idArticulo, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Biblioteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
} else {
|
||||
navigator.notification.alert("Insert manual id or scan article", null, "Verdnatura says:", "¡ups!");
|
||||
}
|
||||
|
||||
}
|
||||
function savePhoto() {
|
||||
|
||||
navigator.notification.confirm(
|
||||
'Estas seguro de actualizar la foto de: ' + idArticulo, // message
|
||||
confirmSave, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Guardar', 'Cancelar'] // buttonLabels
|
||||
);
|
||||
|
||||
// confirmSave(1);
|
||||
|
||||
}
|
||||
function confirmSave(buttonIndex) {
|
||||
if (buttonIndex == 1) {
|
||||
$(".loading").fadeIn(200);
|
||||
var img = dataURItoBlob(cropper.getCroppedCanvas().toDataURL('image/png'));
|
||||
|
||||
var data = new FormData();
|
||||
data.append('srv', 'json:image/upload');
|
||||
data.append('schema', 'catalog');
|
||||
data.append('name', idArticulo);
|
||||
data.append('updateMatching', true);
|
||||
data.append('image', img);
|
||||
|
||||
navigator.notification.alert("Error al cargar la foto", localStorage.getItem("user") + localStorage.getItem("password") + localStorage.getItem("token"));
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.setRequestHeader('Authorization', localStorage.getItem('token'));
|
||||
xhr.open("POST", urlweb, true);
|
||||
xhr.send(data);
|
||||
xhr.onload = function () {
|
||||
var response = JSON.parse(xhr.response);
|
||||
if (!response.data == true) {
|
||||
navigator.notification.alert("Carga completa!", function () {
|
||||
window.location = "main.html";
|
||||
}, "Verdnatura dice:", "¡Buen trabajo!");
|
||||
} else {
|
||||
navigator.notification.alert("Error al cargar la foto", null, "Verdnatura dice:", "¡ooohh!");
|
||||
$(".loading").fadeOut(500);
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
navigator.notification.alert("Error al cargar la foto", null, "Verdnatura dice:", "¡ooohh!");
|
||||
$(".loading").fadeOut(500);
|
||||
};
|
||||
}
|
||||
}
|
||||
function dataURItoBlob(dataURI) {
|
||||
var binary = atob(dataURI.split(',')[1]);
|
||||
var array = [];
|
||||
for (var i = 0; i < binary.length; i++) {
|
||||
array.push(binary.charCodeAt(i));
|
||||
}
|
||||
return new Blob([new Uint8Array(array)], { type: 'image/png' });
|
||||
}
|
||||
function scanBarcode() {
|
||||
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
idArticulo = result.text;
|
||||
|
||||
navigator.notification.confirm(
|
||||
'Article: ' + result.text, // message
|
||||
onConfirm, // callback to invoke with index of button pressed
|
||||
'Verdnatura says:', // title
|
||||
['Hacer foto', 'Bibloteca', 'Cerrar'] // buttonLabels
|
||||
);
|
||||
|
||||
},
|
||||
function (error) {
|
||||
navigator.notification.alert(
|
||||
"Could not scan: " + error, // message
|
||||
onError, // callback
|
||||
'Game Over', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
function onConfirm(buttonIndex) {
|
||||
$(".menu").fadeOut(200);
|
||||
switch (buttonIndex) {
|
||||
case 1:
|
||||
showCamera();
|
||||
break;
|
||||
case 2:
|
||||
showLibrary();
|
||||
break;
|
||||
case 3:
|
||||
window.location = "main.html";
|
||||
break;
|
||||
default:
|
||||
window.location = "main.html";
|
||||
}
|
||||
}
|
||||
function onError() {
|
||||
window.location = "main.html";
|
||||
}
|
||||
function showCamera() {
|
||||
var srcType = Camera.PictureSourceType.CAMERA;
|
||||
|
||||
var options = {
|
||||
saveToPhotoAlbum: true,
|
||||
quality: 100,
|
||||
destinationType: Camera.DestinationType.FILE_URI,
|
||||
sourceType: srcType,
|
||||
encodingType: Camera.EncodingType.JPEG,
|
||||
mediaType: Camera.MediaType.PICTURE,
|
||||
allowEdit: false,
|
||||
correctOrientation: true
|
||||
};
|
||||
|
||||
|
||||
|
||||
navigator.camera.getPicture(cameraSuccess, cameraError, options);
|
||||
|
||||
}
|
||||
function showLibrary() {
|
||||
var srcType = Camera.PictureSourceType.PHOTOLIBRARY;
|
||||
|
||||
var options = {
|
||||
saveToPhotoAlbum: false,
|
||||
quality: 100,
|
||||
destinationType: Camera.DestinationType.FILE_URI,
|
||||
sourceType: srcType,
|
||||
encodingType: Camera.EncodingType.JPEG,
|
||||
mediaType: Camera.MediaType.PICTURE,
|
||||
allowEdit: false,
|
||||
correctOrientation: true
|
||||
};
|
||||
navigator.camera.getPicture(cameraSuccess, cameraError, options);
|
||||
|
||||
}
|
||||
function cameraSuccess(imageData) {
|
||||
$(".loading").fadeOut(200);
|
||||
console.log("Camera success.");
|
||||
$("#photo").attr("src", imageData);
|
||||
|
||||
|
||||
setCrop();
|
||||
}
|
||||
function setCrop() {
|
||||
|
||||
cropper = new Cropper(image, {
|
||||
viewMode: 1,
|
||||
|
||||
data: {
|
||||
width: (minCroppedWidth + maxCroppedWidth) / 2,
|
||||
height: (minCroppedHeight + maxCroppedHeight) / 2
|
||||
},
|
||||
|
||||
crop: function (event) {
|
||||
var width = event.detail.width;
|
||||
var height = event.detail.height;
|
||||
|
||||
if (
|
||||
width < minCroppedWidth
|
||||
|| height < minCroppedHeight
|
||||
|| width > maxCroppedWidth
|
||||
|| height > maxCroppedHeight
|
||||
) {
|
||||
cropper.setData({
|
||||
width: Math.max(minCroppedWidth, Math.min(maxCroppedWidth, width)),
|
||||
height: Math.max(minCroppedHeight, Math.min(maxCroppedHeight, height))
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
cropmove: function () {
|
||||
var cropper = this.cropper;
|
||||
var cropBoxData = cropper.getCropBoxData();
|
||||
var h = 0;
|
||||
switch (ratio) {
|
||||
case 1:
|
||||
h = (cropBoxData.width / 3) * 2;
|
||||
break;
|
||||
case 2:
|
||||
h = (cropBoxData.width / 16) * 9;
|
||||
break;
|
||||
case 3:
|
||||
h = (cropBoxData.width / 1) * 1;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
cropper.setCropBoxData({
|
||||
height: h
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
function cameraError(message) {
|
||||
navigator.notification.alert(
|
||||
"Could not take a picture: " + message, // message
|
||||
onError, // callback
|
||||
'Game Over', // title
|
||||
'Ok' // buttonName
|
||||
);
|
||||
}
|
||||
function setOptions(srcType) {
|
||||
|
||||
var options = {
|
||||
quality: 80,
|
||||
destinationType: Camera.DestinationType.FILE_URI,
|
||||
sourceType: srcType,
|
||||
encodingType: Camera.EncodingType.JPEG,
|
||||
mediaType: Camera.MediaType.PICTURE,
|
||||
allowEdit: false,
|
||||
correctOrientation: true,
|
||||
saveToPhotoAlbum: true
|
||||
};
|
||||
return options;
|
||||
}
|