From f6e7c07078252d72b0c7725350a83adfff740b99 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 30 Nov 2015 23:19:28 -0500 Subject: plugins --- .../src/windows/SocialSharingProxy.js | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js (limited to 'StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows') diff --git a/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js new file mode 100644 index 00000000..99e0af15 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js @@ -0,0 +1,114 @@ +var cordova = require('cordova'); + +module.exports = { + share: function (win, fail, args) { + //Text Message + var message = args[0]; + //Title + var subject = args[1]; + //File(s) Path + var fileOrFileArray = args[2]; + //Web link + var url = args[3]; + + var doShare = function (e) { + e.request.data.properties.title = subject?subject: "Sharing"; + if (message) e.request.data.setText(message); + if (url) e.request.data.setWebLink(new Windows.Foundation.Uri(url)); + if (fileOrFileArray.length > 0) { + var deferral = e.request.getDeferral(); + var storageItems = []; + var filesCount = fileOrFileArray.length; + 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(); + } + }, + function() { + if (!--filesCount) { + e.request.data.setStorageItems(storageItems); + deferral.complete(); + } + } + ); + } + } + } + + + var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView(); + + dataTransferManager.addEventListener("datarequested", doShare); + + try { + Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI(); + win(true); + } catch (err) { + fail(err); + } + }, + + canShareViaEmail: function (win, fail, args) { + win(true); + }, + + shareViaEmail: function (win, fail, args) { + //Text Message + var message = args[0]; + //Title + var subject = args[1]; + //File(s) Path + var fileOrFileArray = args[5]; + + var doShare = function (e) { + e.request.data.properties.title = subject ? subject : "Sharing"; + if (message) { + var htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(message); + e.request.data.setHtmlFormat(htmlFormat); + } + + if (fileOrFileArray.length > 0) { + var deferral = e.request.getDeferral(); + var storageItems = []; + var filesCount = fileOrFileArray.length; + for (var i = 0; i < fileOrFileArray.length; i++) { + Windows.Storage.StorageFile.getFileFromPathAsync(fileOrFileArray[i]).done( + function (index, file) { + var path = fileOrFileArray[index]; + var streamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(file); + e.request.data.resourceMap[path] = streamRef; + storageItems.push(file); + if (!--filesCount) { + e.request.data.setStorageItems(storageItems); + deferral.complete(); + } + }.bind(this, i), + function () { + if (!--filesCount) { + e.request.data.setStorageItems(storageItems); + deferral.complete(); + } + } + ); + } + } + } + + var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView(); + + dataTransferManager.addEventListener("datarequested", doShare); + + try { + Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI(); + win(true); + } catch (err) { + fail(err); + } + } +}; + +require("cordova/exec/proxy").add("SocialSharing", module.exports); \ No newline at end of file -- cgit v1.2.3-70-g09d2