summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows
diff options
context:
space:
mode:
authorRene Ae <aehtyb@gmail.com>2015-12-01 00:51:02 -0600
committerRene Ae <aehtyb@gmail.com>2015-12-01 00:51:02 -0600
commit6415f506034262dd7151be2e35e1e1c1e97f4dfa (patch)
treec6e564e374967725a40fd87f7c5f3a1ba8019089 /StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows
parent5e07e273e18a609978253c45f3c5f702b0de4991 (diff)
parent9497b50fa02f3cfa9cb263ce3a96fa725282d60d (diff)
Merge branch 'master' of https://github.com/okfocus/stone-island
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows')
-rw-r--r--StoneIsland/plugins/cordova-plugin-x-socialsharing/src/windows/SocialSharingProxy.js114
1 files changed, 114 insertions, 0 deletions
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