community-cordova-plugin-social-sharing 6.1.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -0
- package/.travis.yml +4 -4
- package/LICENSE +18 -18
- package/README.md +585 -559
- package/package.json +48 -48
- package/plugin.xml +125 -119
- package/src/android/nl/xservices/plugins/FileProvider.java +3 -3
- package/src/android/nl/xservices/plugins/ShareChooserPendingIntent.java +16 -16
- package/src/android/nl/xservices/plugins/SocialSharing.java +809 -802
- package/src/android/res/xml/sharing_paths.xml +10 -10
- package/src/ios/NSString+SSURLEncoding.h +5 -5
- package/src/ios/NSString+SSURLEncoding.m +30 -30
- package/src/ios/SocialSharing.h +28 -28
- package/src/ios/SocialSharing.m +861 -861
- package/src/windows/SocialSharingProxy.js +176 -176
- package/src/wp8/Newtonsoft.Json.dll +0 -0
- package/src/wp8/SocialSharing.cs +103 -103
- package/types/index.d.ts +62 -62
- package/www/SocialSharing.js +157 -157
package/types/index.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
// Type definitions for PhoneGap / Cordova Social Sharing plugin
|
|
2
|
-
// Project: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
|
|
3
|
-
// Licensed under the MIT license.
|
|
4
|
-
|
|
5
|
-
interface Window {
|
|
6
|
-
plugins: Plugins
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface Plugins {
|
|
10
|
-
socialsharing: SocialSharing
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface Navigator {
|
|
14
|
-
share: SocialSharingW3C
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare class SocialSharing {
|
|
18
|
-
iPadPopupCoordinates: () => string
|
|
19
|
-
setIPadPopupCoordinates: (coords: string) => void
|
|
20
|
-
available: (callback: (available: boolean) => void) => void
|
|
21
|
-
shareWithOptions: (options: SocialSharingOptions, successCallback?: SocialSharingSuccessCallback<SocialSharingResult>, errorCallback?: SocialSharingErrorCallback) => void
|
|
22
|
-
shareW3C: SocialSharingW3C
|
|
23
|
-
share: (message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
24
|
-
shareViaTwitter: (message?: string, file?: string, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
25
|
-
shareViaFacebook: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
26
|
-
shareViaFacebookWithPasteMessageHint: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, pasteMessageHint?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
27
|
-
shareViaWhatsApp: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
28
|
-
shareViaWhatsAppToReceiver: (receiver?: string, message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
29
|
-
shareViaWhatsAppToPhone: (phone?: string, message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
30
|
-
shareViaSMS: (options?: SocialSharingOptions | string, phoneNumbers?: ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
31
|
-
shareViaEmail: (message?: string, subject?: string, toArray?: ArrayLike<string>, ccArray?: ArrayLike<string>, bccArray?: ArrayLike<string>, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
32
|
-
canShareVia: (via: string, message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
33
|
-
canShareViaEmail: (successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
34
|
-
shareViaInstagram: (message?: string, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
35
|
-
shareVia: (via: string, message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
36
|
-
saveToPhotoAlbum: (fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type SocialSharingW3C = (shareData: SocialSharingW3CData) => Promise<SocialSharingResult>
|
|
40
|
-
|
|
41
|
-
interface SocialSharingW3CData {
|
|
42
|
-
title?: string
|
|
43
|
-
text?: string
|
|
44
|
-
url?: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface SocialSharingOptions {
|
|
48
|
-
message?: string
|
|
49
|
-
subject?: string
|
|
50
|
-
files?: ArrayLike<string>
|
|
51
|
-
url?: string
|
|
52
|
-
chooserTitle?: string
|
|
53
|
-
appPackageName?: string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type SocialSharingSuccessCallback<T> = (result: T) => void
|
|
57
|
-
type SocialSharingErrorCallback = (msg?: string) => void
|
|
58
|
-
|
|
59
|
-
interface SocialSharingResult {
|
|
60
|
-
completed: boolean
|
|
61
|
-
app?: string
|
|
62
|
-
}
|
|
1
|
+
// Type definitions for PhoneGap / Cordova Social Sharing plugin
|
|
2
|
+
// Project: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
|
|
5
|
+
interface Window {
|
|
6
|
+
plugins: Plugins
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface Plugins {
|
|
10
|
+
socialsharing: SocialSharing
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Navigator {
|
|
14
|
+
share: SocialSharingW3C
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class SocialSharing {
|
|
18
|
+
iPadPopupCoordinates: () => string
|
|
19
|
+
setIPadPopupCoordinates: (coords: string) => void
|
|
20
|
+
available: (callback: (available: boolean) => void) => void
|
|
21
|
+
shareWithOptions: (options: SocialSharingOptions, successCallback?: SocialSharingSuccessCallback<SocialSharingResult>, errorCallback?: SocialSharingErrorCallback) => void
|
|
22
|
+
shareW3C: SocialSharingW3C
|
|
23
|
+
share: (message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
24
|
+
shareViaTwitter: (message?: string, file?: string, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
25
|
+
shareViaFacebook: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
26
|
+
shareViaFacebookWithPasteMessageHint: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, pasteMessageHint?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
27
|
+
shareViaWhatsApp: (message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
28
|
+
shareViaWhatsAppToReceiver: (receiver?: string, message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
29
|
+
shareViaWhatsAppToPhone: (phone?: string, message?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
30
|
+
shareViaSMS: (options?: SocialSharingOptions | string, phoneNumbers?: ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
31
|
+
shareViaEmail: (message?: string, subject?: string, toArray?: ArrayLike<string>, ccArray?: ArrayLike<string>, bccArray?: ArrayLike<string>, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
32
|
+
canShareVia: (via: string, message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
33
|
+
canShareViaEmail: (successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
34
|
+
shareViaInstagram: (message?: string, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
35
|
+
shareVia: (via: string, message?: string, subject?: string, fileOrFileArray?: string | ArrayLike<string>, url?: string, successCallback?: SocialSharingSuccessCallback<boolean>, errorCallback?: SocialSharingErrorCallback) => void
|
|
36
|
+
saveToPhotoAlbum: (fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type SocialSharingW3C = (shareData: SocialSharingW3CData) => Promise<SocialSharingResult>
|
|
40
|
+
|
|
41
|
+
interface SocialSharingW3CData {
|
|
42
|
+
title?: string
|
|
43
|
+
text?: string
|
|
44
|
+
url?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SocialSharingOptions {
|
|
48
|
+
message?: string
|
|
49
|
+
subject?: string
|
|
50
|
+
files?: ArrayLike<string>
|
|
51
|
+
url?: string
|
|
52
|
+
chooserTitle?: string
|
|
53
|
+
appPackageName?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type SocialSharingSuccessCallback<T> = (result: T) => void
|
|
57
|
+
type SocialSharingErrorCallback = (msg?: string) => void
|
|
58
|
+
|
|
59
|
+
interface SocialSharingResult {
|
|
60
|
+
completed: boolean
|
|
61
|
+
app?: string
|
|
62
|
+
}
|
package/www/SocialSharing.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
function SocialSharing() {
|
|
2
|
-
}
|
|
3
|
-
|
|
4
|
-
// Override this method (after deviceready) to set the location where you want the iPad popup arrow to appear.
|
|
5
|
-
// If not overridden with different values, the popup is not used. Example:
|
|
6
|
-
//
|
|
7
|
-
// window.plugins.socialsharing.iPadPopupCoordinates = function() {
|
|
8
|
-
// return "100,100,200,300";
|
|
9
|
-
// };
|
|
10
|
-
SocialSharing.prototype.iPadPopupCoordinates = function () {
|
|
11
|
-
// left,top,width,height
|
|
12
|
-
return "-1,-1,-1,-1";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
SocialSharing.prototype.setIPadPopupCoordinates = function (coords) {
|
|
16
|
-
console.log("Deprecated - setIPadPopupCoordinates no longer works since plugin version 5.5.0. See https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/1052");
|
|
17
|
-
// left,top,width,height
|
|
18
|
-
cordova.exec(function() {}, this._getErrorCallback(function() {}, "setIPadPopupCoordinates"), "SocialSharing", "setIPadPopupCoordinates", [coords]);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
SocialSharing.prototype.available = function (callback) {
|
|
22
|
-
cordova.exec(function (avail) {
|
|
23
|
-
callback(avail ? true : false);
|
|
24
|
-
}, null, "SocialSharing", "available", []);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// this is the recommended way to share as it is the most feature-rich with respect to what you pass in and get back
|
|
28
|
-
SocialSharing.prototype.shareWithOptions = function (options, successCallback, errorCallback) {
|
|
29
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareWithOptions"), "SocialSharing", "shareWithOptions", [options]);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
SocialSharing.prototype.shareW3C = function (sharedata) {
|
|
33
|
-
return new Promise(function(resolve, reject) {
|
|
34
|
-
var options = {
|
|
35
|
-
subject: sharedata.title,
|
|
36
|
-
message: sharedata.text,
|
|
37
|
-
url: sharedata.url,
|
|
38
|
-
iPadCoordinates: sharedata.iPadCoordinates || undefined
|
|
39
|
-
};
|
|
40
|
-
if(sharedata.hasOwnProperty('title') ||
|
|
41
|
-
sharedata.hasOwnProperty('text') ||
|
|
42
|
-
sharedata.hasOwnProperty('url')) {
|
|
43
|
-
cordova.exec(resolve, reject, "SocialSharing", "shareWithOptions", [options]);
|
|
44
|
-
} else {
|
|
45
|
-
reject();
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
SocialSharing.prototype.share = function (message, subject, fileOrFileArray, url, iPadCoordinates, successCallback, errorCallback) {
|
|
51
|
-
if (typeof iPadCoordinates === 'function') {
|
|
52
|
-
errorCallback = successCallback;
|
|
53
|
-
successCallback = iPadCoordinates;
|
|
54
|
-
iPadCoordinates = "";
|
|
55
|
-
}
|
|
56
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "share"), "SocialSharing", "share", [message, subject, this._asArray(fileOrFileArray), url, iPadCoordinates]);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
SocialSharing.prototype.shareViaTwitter = function (message, file /* multiple not allowed by twitter */, url, successCallback, errorCallback) {
|
|
60
|
-
var fileArray = this._asArray(file);
|
|
61
|
-
var ecb = this._getErrorCallback(errorCallback, "shareViaTwitter");
|
|
62
|
-
if (fileArray.length > 1) {
|
|
63
|
-
ecb("shareViaTwitter supports max one file");
|
|
64
|
-
} else {
|
|
65
|
-
cordova.exec(successCallback, ecb, "SocialSharing", "shareViaTwitter", [message, null, fileArray, url]);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
SocialSharing.prototype.shareViaFacebook = function (message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
70
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebook"), "SocialSharing", "shareViaFacebook", [message, null, this._asArray(fileOrFileArray), url]);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
SocialSharing.prototype.shareViaFacebookWithPasteMessageHint = function (message, fileOrFileArray, url, pasteMessageHint, successCallback, errorCallback) {
|
|
74
|
-
pasteMessageHint = pasteMessageHint || "If you like you can paste a message from your clipboard";
|
|
75
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebookWithPasteMessageHint"), "SocialSharing", "shareViaFacebookWithPasteMessageHint", [message, null, this._asArray(fileOrFileArray), url, pasteMessageHint]);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
SocialSharing.prototype.shareViaWhatsApp = function (message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
79
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsApp"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null, null]);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
SocialSharing.prototype.shareViaWhatsAppToReceiver = function (receiver, message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
83
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToReceiver"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, receiver, null]);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
SocialSharing.prototype.shareViaWhatsAppToPhone = function (phone, message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
87
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToPhone"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null, phone]);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
SocialSharing.prototype.shareViaSMS = function (options, phonenumbers, successCallback, errorCallback) {
|
|
91
|
-
var opts = options;
|
|
92
|
-
if (typeof options === "string") {
|
|
93
|
-
opts = {"message":options}; // for backward compatibility as the options param used to be the message
|
|
94
|
-
}
|
|
95
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaSMS"), "SocialSharing", "shareViaSMS", [opts, phonenumbers]);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
SocialSharing.prototype.shareViaEmail = function (message, subject, toArray, ccArray, bccArray, fileOrFileArray, successCallback, errorCallback) {
|
|
99
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaEmail"), "SocialSharing", "shareViaEmail", [message, subject, this._asArray(toArray), this._asArray(ccArray), this._asArray(bccArray), this._asArray(fileOrFileArray)]);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
SocialSharing.prototype.canShareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
|
|
103
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareVia"), "SocialSharing", "canShareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
SocialSharing.prototype.canShareViaEmail = function (successCallback, errorCallback) {
|
|
107
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareViaEmail"), "SocialSharing", "canShareViaEmail", []);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
SocialSharing.prototype.shareViaInstagram = function (message, fileOrFileArray, successCallback, errorCallback) {
|
|
111
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaInstagram"), "SocialSharing", "shareViaInstagram", [message, null, this._asArray(fileOrFileArray), null]);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
SocialSharing.prototype.shareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
|
|
115
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareVia"), "SocialSharing", "shareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
SocialSharing.prototype.saveToPhotoAlbum = function (fileOrFileArray, successCallback, errorCallback) {
|
|
119
|
-
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "saveToPhotoAlbum"), "SocialSharing", "saveToPhotoAlbum", [this._asArray(fileOrFileArray)]);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
SocialSharing.prototype._asArray = function (param) {
|
|
123
|
-
if (param == null) {
|
|
124
|
-
param = [];
|
|
125
|
-
} else if (typeof param === 'string') {
|
|
126
|
-
param = new Array(param);
|
|
127
|
-
}
|
|
128
|
-
return param;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
SocialSharing.prototype._getErrorCallback = function (ecb, functionName) {
|
|
132
|
-
if (typeof ecb === 'function') {
|
|
133
|
-
return ecb;
|
|
134
|
-
} else {
|
|
135
|
-
return function (result) {
|
|
136
|
-
console.log("The injected error callback of '" + functionName + "' received: " + JSON.stringify(result));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
SocialSharing.install = function () {
|
|
142
|
-
if (!window.plugins) {
|
|
143
|
-
window.plugins = {};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
window.plugins.socialsharing = new SocialSharing();
|
|
147
|
-
|
|
148
|
-
// Note only polyfill navigator.share if it is not defined, since shareW3C implements L1 of the spec,
|
|
149
|
-
// and an existing navigator.share method could implement L2.
|
|
150
|
-
if (!navigator.share) {
|
|
151
|
-
navigator.share = window.plugins.socialsharing.shareW3C;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return window.plugins.socialsharing;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
cordova.addConstructor(SocialSharing.install);
|
|
1
|
+
function SocialSharing() {
|
|
2
|
+
}
|
|
3
|
+
|
|
4
|
+
// Override this method (after deviceready) to set the location where you want the iPad popup arrow to appear.
|
|
5
|
+
// If not overridden with different values, the popup is not used. Example:
|
|
6
|
+
//
|
|
7
|
+
// window.plugins.socialsharing.iPadPopupCoordinates = function() {
|
|
8
|
+
// return "100,100,200,300";
|
|
9
|
+
// };
|
|
10
|
+
SocialSharing.prototype.iPadPopupCoordinates = function () {
|
|
11
|
+
// left,top,width,height
|
|
12
|
+
return "-1,-1,-1,-1";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
SocialSharing.prototype.setIPadPopupCoordinates = function (coords) {
|
|
16
|
+
console.log("Deprecated - setIPadPopupCoordinates no longer works since plugin version 5.5.0. See https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/1052");
|
|
17
|
+
// left,top,width,height
|
|
18
|
+
cordova.exec(function() {}, this._getErrorCallback(function() {}, "setIPadPopupCoordinates"), "SocialSharing", "setIPadPopupCoordinates", [coords]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
SocialSharing.prototype.available = function (callback) {
|
|
22
|
+
cordova.exec(function (avail) {
|
|
23
|
+
callback(avail ? true : false);
|
|
24
|
+
}, null, "SocialSharing", "available", []);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// this is the recommended way to share as it is the most feature-rich with respect to what you pass in and get back
|
|
28
|
+
SocialSharing.prototype.shareWithOptions = function (options, successCallback, errorCallback) {
|
|
29
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareWithOptions"), "SocialSharing", "shareWithOptions", [options]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
SocialSharing.prototype.shareW3C = function (sharedata) {
|
|
33
|
+
return new Promise(function(resolve, reject) {
|
|
34
|
+
var options = {
|
|
35
|
+
subject: sharedata.title,
|
|
36
|
+
message: sharedata.text,
|
|
37
|
+
url: sharedata.url,
|
|
38
|
+
iPadCoordinates: sharedata.iPadCoordinates || undefined
|
|
39
|
+
};
|
|
40
|
+
if(sharedata.hasOwnProperty('title') ||
|
|
41
|
+
sharedata.hasOwnProperty('text') ||
|
|
42
|
+
sharedata.hasOwnProperty('url')) {
|
|
43
|
+
cordova.exec(resolve, reject, "SocialSharing", "shareWithOptions", [options]);
|
|
44
|
+
} else {
|
|
45
|
+
reject();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
SocialSharing.prototype.share = function (message, subject, fileOrFileArray, url, iPadCoordinates, successCallback, errorCallback) {
|
|
51
|
+
if (typeof iPadCoordinates === 'function') {
|
|
52
|
+
errorCallback = successCallback;
|
|
53
|
+
successCallback = iPadCoordinates;
|
|
54
|
+
iPadCoordinates = "";
|
|
55
|
+
}
|
|
56
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "share"), "SocialSharing", "share", [message, subject, this._asArray(fileOrFileArray), url, iPadCoordinates]);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
SocialSharing.prototype.shareViaTwitter = function (message, file /* multiple not allowed by twitter */, url, successCallback, errorCallback) {
|
|
60
|
+
var fileArray = this._asArray(file);
|
|
61
|
+
var ecb = this._getErrorCallback(errorCallback, "shareViaTwitter");
|
|
62
|
+
if (fileArray.length > 1) {
|
|
63
|
+
ecb("shareViaTwitter supports max one file");
|
|
64
|
+
} else {
|
|
65
|
+
cordova.exec(successCallback, ecb, "SocialSharing", "shareViaTwitter", [message, null, fileArray, url]);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
SocialSharing.prototype.shareViaFacebook = function (message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
70
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebook"), "SocialSharing", "shareViaFacebook", [message, null, this._asArray(fileOrFileArray), url]);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
SocialSharing.prototype.shareViaFacebookWithPasteMessageHint = function (message, fileOrFileArray, url, pasteMessageHint, successCallback, errorCallback) {
|
|
74
|
+
pasteMessageHint = pasteMessageHint || "If you like you can paste a message from your clipboard";
|
|
75
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebookWithPasteMessageHint"), "SocialSharing", "shareViaFacebookWithPasteMessageHint", [message, null, this._asArray(fileOrFileArray), url, pasteMessageHint]);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
SocialSharing.prototype.shareViaWhatsApp = function (message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
79
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsApp"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null, null]);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
SocialSharing.prototype.shareViaWhatsAppToReceiver = function (receiver, message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
83
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToReceiver"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, receiver, null]);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
SocialSharing.prototype.shareViaWhatsAppToPhone = function (phone, message, fileOrFileArray, url, successCallback, errorCallback) {
|
|
87
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToPhone"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null, phone]);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
SocialSharing.prototype.shareViaSMS = function (options, phonenumbers, successCallback, errorCallback) {
|
|
91
|
+
var opts = options;
|
|
92
|
+
if (typeof options === "string") {
|
|
93
|
+
opts = {"message":options}; // for backward compatibility as the options param used to be the message
|
|
94
|
+
}
|
|
95
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaSMS"), "SocialSharing", "shareViaSMS", [opts, phonenumbers]);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
SocialSharing.prototype.shareViaEmail = function (message, subject, toArray, ccArray, bccArray, fileOrFileArray, successCallback, errorCallback) {
|
|
99
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaEmail"), "SocialSharing", "shareViaEmail", [message, subject, this._asArray(toArray), this._asArray(ccArray), this._asArray(bccArray), this._asArray(fileOrFileArray)]);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
SocialSharing.prototype.canShareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
|
|
103
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareVia"), "SocialSharing", "canShareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
SocialSharing.prototype.canShareViaEmail = function (successCallback, errorCallback) {
|
|
107
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareViaEmail"), "SocialSharing", "canShareViaEmail", []);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
SocialSharing.prototype.shareViaInstagram = function (message, fileOrFileArray, successCallback, errorCallback) {
|
|
111
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaInstagram"), "SocialSharing", "shareViaInstagram", [message, null, this._asArray(fileOrFileArray), null]);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
SocialSharing.prototype.shareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
|
|
115
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareVia"), "SocialSharing", "shareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
SocialSharing.prototype.saveToPhotoAlbum = function (fileOrFileArray, successCallback, errorCallback) {
|
|
119
|
+
cordova.exec(successCallback, this._getErrorCallback(errorCallback, "saveToPhotoAlbum"), "SocialSharing", "saveToPhotoAlbum", [this._asArray(fileOrFileArray)]);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
SocialSharing.prototype._asArray = function (param) {
|
|
123
|
+
if (param == null) {
|
|
124
|
+
param = [];
|
|
125
|
+
} else if (typeof param === 'string') {
|
|
126
|
+
param = new Array(param);
|
|
127
|
+
}
|
|
128
|
+
return param;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
SocialSharing.prototype._getErrorCallback = function (ecb, functionName) {
|
|
132
|
+
if (typeof ecb === 'function') {
|
|
133
|
+
return ecb;
|
|
134
|
+
} else {
|
|
135
|
+
return function (result) {
|
|
136
|
+
console.log("The injected error callback of '" + functionName + "' received: " + JSON.stringify(result));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
SocialSharing.install = function () {
|
|
142
|
+
if (!window.plugins) {
|
|
143
|
+
window.plugins = {};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
window.plugins.socialsharing = new SocialSharing();
|
|
147
|
+
|
|
148
|
+
// Note only polyfill navigator.share if it is not defined, since shareW3C implements L1 of the spec,
|
|
149
|
+
// and an existing navigator.share method could implement L2.
|
|
150
|
+
if (!navigator.share) {
|
|
151
|
+
navigator.share = window.plugins.socialsharing.shareW3C;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return window.plugins.socialsharing;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
cordova.addConstructor(SocialSharing.install);
|