UNPKG

@mornya/react-social-libs

Version:

The project of React.js Social Share and Widget modules.

74 lines (73 loc) 3.42 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { BaseShareComponent } from '../utils/BaseShareComponent'; import { initFacebookSDK, destroyFacebookSDK } from '../utils/Loader'; import { openShareWindow } from '../utils/UI'; var Facebook = (function (_super) { __extends(Facebook, _super); function Facebook() { return _super !== null && _super.apply(this, arguments) || this; } Facebook.prototype.onInit = function () { this.initialize('Facebook', { title: function (OG) { var _a; return (_a = OG.title) !== null && _a !== void 0 ? _a : ''; }, message: function (_OG) { return ''; }, appId: '', permissions: ['public_profile', 'email', 'user_friends'], caption: '', admins: '', isUseOAuth: true, isDebug: false, }); }; Facebook.prototype.onMount = function (extra) { var _this = this; if (extra.isUseOAuth) { initFacebookSDK(extra.appId, extra.isDebug) .then(function () { return _this.setApiStep(); }) .catch(console.error); } else { this.setApiStep(); } }; Facebook.prototype.onShare = function (extra, OG) { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h; if (extra.isUseOAuth && window.FB) { window.FB.ui({ method: 'feed', name: (_c = (_b = (_a = extra.title) === null || _a === void 0 ? void 0 : _a.call(extra, OG)) !== null && _b !== void 0 ? _b : OG.title) !== null && _c !== void 0 ? _c : '', caption: (_d = extra.caption) !== null && _d !== void 0 ? _d : OG.url, link: (_e = OG.url) !== null && _e !== void 0 ? _e : '', description: (_f = OG.description) !== null && _f !== void 0 ? _f : '', picture: OG.image, message: (_h = (_g = extra.message) === null || _g === void 0 ? void 0 : _g.call(extra, OG)) !== null && _h !== void 0 ? _h : '', }, function (response) { return _this.onComplete(true, response); }); } else { openShareWindow(this.mapToParam(Facebook.LINK_URL, { u: OG.url }), 'facebook', this.deviceInfo.isMobile ? [] : [550, 440]) .then(function () { return _this.onComplete(true, null); }) .catch(function (error) { return console.error(error); }); } }; Facebook.prototype.onUnmount = function (_extra) { destroyFacebookSDK(); }; Facebook.LINK_URL = 'https://www.facebook.com/sharer/sharer.php'; return Facebook; }(BaseShareComponent)); export default Facebook;