arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-x-socialsharing/www/SocialSharing.js
plugins/cordova-plugin-x-socialsharing/www/SocialSharing.jsRaw
  1function 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//   };
 10SocialSharing.prototype.iPadPopupCoordinates = function () {
 11  // left,top,width,height
 12  return "-1,-1,-1,-1";
 13};
 14
 15SocialSharing.prototype.setIPadPopupCoordinates = function (coords) {
 16  // left,top,width,height
 17  cordova.exec(function() {}, this._getErrorCallback(function() {}, "setIPadPopupCoordinates"), "SocialSharing", "setIPadPopupCoordinates", [coords]);
 18};
 19
 20SocialSharing.prototype.available = function (callback) {
 21  cordova.exec(function (avail) {
 22    callback(avail ? true : false);
 23  }, null, "SocialSharing", "available", []);
 24};
 25
 26// this is the recommended way to share as it is the most feature-rich with respect to what you pass in and get back
 27SocialSharing.prototype.shareWithOptions = function (options, successCallback, errorCallback) {
 28  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareWithOptions"), "SocialSharing", "shareWithOptions", [options]);
 29};
 30
 31SocialSharing.prototype.share = function (message, subject, fileOrFileArray, url, successCallback, errorCallback) {
 32  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "share"), "SocialSharing", "share", [message, subject, this._asArray(fileOrFileArray), url]);
 33};
 34
 35SocialSharing.prototype.shareViaTwitter = function (message, file /* multiple not allowed by twitter */, url, successCallback, errorCallback) {
 36  var fileArray = this._asArray(file);
 37  var ecb = this._getErrorCallback(errorCallback, "shareViaTwitter");
 38  if (fileArray.length > 1) {
 39    ecb("shareViaTwitter supports max one file");
 40  } else {
 41    cordova.exec(successCallback, ecb, "SocialSharing", "shareViaTwitter", [message, null, fileArray, url]);
 42  }
 43};
 44
 45SocialSharing.prototype.shareViaFacebook = function (message, fileOrFileArray, url, successCallback, errorCallback) {
 46  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebook"), "SocialSharing", "shareViaFacebook", [message, null, this._asArray(fileOrFileArray), url]);
 47};
 48
 49SocialSharing.prototype.shareViaFacebookWithPasteMessageHint = function (message, fileOrFileArray, url, pasteMessageHint, successCallback, errorCallback) {
 50  pasteMessageHint = pasteMessageHint || "If you like you can paste a message from your clipboard";
 51  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaFacebookWithPasteMessageHint"), "SocialSharing", "shareViaFacebookWithPasteMessageHint", [message, null, this._asArray(fileOrFileArray), url, pasteMessageHint]);
 52};
 53
 54SocialSharing.prototype.shareViaWhatsApp = function (message, fileOrFileArray, url, successCallback, errorCallback) {
 55  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsApp"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, null]);
 56};
 57
 58SocialSharing.prototype.shareViaWhatsAppToReceiver = function (receiver, message, fileOrFileArray, url, successCallback, errorCallback) {
 59  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaWhatsAppToReceiver"), "SocialSharing", "shareViaWhatsApp", [message, null, this._asArray(fileOrFileArray), url, receiver]);
 60};
 61
 62SocialSharing.prototype.shareViaSMS = function (options, phonenumbers, successCallback, errorCallback) {
 63  var opts = options;
 64  if (typeof options == "string") {
 65    opts = {"message":options}; // for backward compatibility as the options param used to be the message
 66  }
 67  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaSMS"), "SocialSharing", "shareViaSMS", [opts, phonenumbers]);
 68};
 69
 70SocialSharing.prototype.shareViaEmail = function (message, subject, toArray, ccArray, bccArray, fileOrFileArray, successCallback, errorCallback) {
 71  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaEmail"), "SocialSharing", "shareViaEmail", [message, subject, this._asArray(toArray), this._asArray(ccArray), this._asArray(bccArray), this._asArray(fileOrFileArray)]);
 72};
 73
 74SocialSharing.prototype.canShareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
 75  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareVia"), "SocialSharing", "canShareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
 76};
 77
 78SocialSharing.prototype.canShareViaEmail = function (successCallback, errorCallback) {
 79  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "canShareViaEmail"), "SocialSharing", "canShareViaEmail", []);
 80};
 81
 82SocialSharing.prototype.shareViaInstagram = function (message, fileOrFileArray, successCallback, errorCallback) {
 83  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareViaInstagram"), "SocialSharing", "shareViaInstagram", [message, null, this._asArray(fileOrFileArray), null]);
 84};
 85
 86SocialSharing.prototype.shareVia = function (via, message, subject, fileOrFileArray, url, successCallback, errorCallback) {
 87  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "shareVia"), "SocialSharing", "shareVia", [message, subject, this._asArray(fileOrFileArray), url, via]);
 88};
 89
 90SocialSharing.prototype.saveToPhotoAlbum = function (fileOrFileArray, successCallback, errorCallback) {
 91  cordova.exec(successCallback, this._getErrorCallback(errorCallback, "saveToPhotoAlbum"), "SocialSharing", "saveToPhotoAlbum", [this._asArray(fileOrFileArray)]);
 92};
 93
 94SocialSharing.prototype._asArray = function (param) {
 95  if (param == null) {
 96    param = [];
 97  } else if (typeof param === 'string') {
 98    param = new Array(param);
 99  }
100  return param;
101};
102
103SocialSharing.prototype._getErrorCallback = function (ecb, functionName) {
104  if (typeof ecb === 'function') {
105    return ecb;
106  } else {
107    return function (result) {
108      console.log("The injected error callback of '" + functionName + "' received: " + JSON.stringify(result));
109    }
110  }
111};
112
113SocialSharing.install = function () {
114  if (!window.plugins) {
115    window.plugins = {};
116  }
117
118  window.plugins.socialsharing = new SocialSharing();
119  return window.plugins.socialsharing;
120};
121
122cordova.addConstructor(SocialSharing.install);