cordova-plugin-x-socialsharing
Advanced tools
Comparing version 5.0.9 to 5.0.10
{ | ||
"name": "cordova-plugin-x-socialsharing", | ||
"version": "5.0.9", | ||
"version": "5.0.10", | ||
"description": "Share text, images (and other files), or a link via the native sharing widget of your device. Android is fully supported, as well as iOS 6 and up. WP8 has somewhat limited support.", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -13,3 +13,33 @@ var cordova = require('cordova'); | ||
var url = args[3]; | ||
var folder = Windows.Storage.ApplicationData.current.temporaryFolder; | ||
var getExtension = function (strBase64) { | ||
return strBase64.substring(strBase64.indexOf("/") + 1, strBase64.indexOf(";base64")); | ||
}; | ||
var replaceAll = function (str, find, replace) { | ||
return str.replace(new RegExp(find, 'g'), replace); | ||
}; | ||
var sanitizeFilename = function (name) { | ||
return replaceAll(name, "[:\\\\/*?|<> ]", "_"); | ||
}; | ||
var getFileName = function (position, fileExtension) { | ||
var fileName = (subject ? sanitizeFilename(subject) : "file") + (position == 0 ? "" : "_" + position) + "." + fileExtension; | ||
return fileName; | ||
}; | ||
var createTemporalFile = function (fileName, buffer) { | ||
var filePath = ""; | ||
return folder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) { | ||
filePath = file.path; | ||
return Windows.Storage.FileIO.writeBufferAsync(file, buffer); | ||
}).then(function(){ | ||
return Windows.Storage.StorageFile.getFileFromPathAsync(filePath); | ||
}); | ||
}; | ||
var doShare = function (e) { | ||
@@ -23,18 +53,42 @@ e.request.data.properties.title = subject?subject: "Sharing"; | ||
var filesCount = fileOrFileArray.length; | ||
var completeFile = function () { | ||
if (!--filesCount) { | ||
storageItems.length && e.request.data.setStorageItems(storageItems); | ||
deferral.complete(); | ||
} | ||
}; | ||
for (var i = 0; i < fileOrFileArray.length; i++) { | ||
Windows.Storage.StorageFile.getFileFromPathAsync(fileOrFileArray[i]).done( | ||
function (file) { | ||
storageItems.push(file); | ||
if (!--filesCount) { | ||
e.request.data.setStorageItems(storageItems); | ||
deferral.complete(); | ||
var file = fileOrFileArray[i]; | ||
if (file.indexOf("data:") >= 0) { | ||
var fileName = getFileName(i, getExtension(file)); | ||
var buffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(file.split(',')[1]); | ||
if (buffer) { | ||
createTemporalFile(fileName, buffer).done( | ||
function (file) { | ||
storageItems.push(file); | ||
completeFile(); | ||
}, | ||
function () { | ||
completeFile(); | ||
} | ||
); | ||
} | ||
else { | ||
completeFile(); | ||
} | ||
} | ||
else { | ||
Windows.Storage.StorageFile.getFileFromPathAsync(file).done( | ||
function (file) { | ||
storageItems.push(file); | ||
completeFile(); | ||
}, | ||
function () { | ||
completeFile(); | ||
} | ||
}, | ||
function() { | ||
if (!--filesCount) { | ||
e.request.data.setStorageItems(storageItems); | ||
deferral.complete(); | ||
} | ||
} | ||
); | ||
); | ||
} | ||
} | ||
@@ -41,0 +95,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1296555
529