UNPKG

@mornya/react-social-libs

Version:

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

71 lines (70 loc) 3.35 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 React from 'react'; import { BaseWidgetComponent } from '../utils/BaseWidgetComponent'; import { initFacebookSDK, destroyFacebookSDK } from '../utils/Loader'; var FacebookLike = (function (_super) { __extends(FacebookLike, _super); function FacebookLike() { return _super !== null && _super.apply(this, arguments) || this; } FacebookLike.prototype.onInit = function () { this.initialize('Facebook-Like', { appId: '', pageUrl: '', isDark: false, isDebug: false, onLogin: function () { }, onLogout: function () { }, onLike: function () { }, onUnlike: function () { }, }); }; FacebookLike.prototype.onRender = function (extra) { return (React.createElement("div", { id: this.id, className: "fb-like", "data-href": extra.pageUrl, "data-colorscheme": extra.isDark ? 'dark' : 'light', "data-layout": "button_count", "data-action": "like", "data-show-faces": "false", "data-share": "false", "data-send": "false", "data-width": "98", "data-height": "21" }, "Facebook Like")); }; FacebookLike.prototype.onMount = function (extra) { var _this = this; initFacebookSDK(extra.appId, extra.isDebug) .then(function () { if (window.FB) { window.FB.Event.unsubscribe('auth.login', extra.onLogin); window.FB.Event.unsubscribe('auth.logout', extra.onLogout); window.FB.Event.unsubscribe('edge.create', extra.onLike); window.FB.Event.unsubscribe('edge.remove', extra.onUnlike); window.FB.Event.subscribe('auth.login', extra.onLogin); window.FB.Event.subscribe('auth.logout', extra.onLogout); window.FB.Event.subscribe('edge.create', extra.onLike); window.FB.Event.subscribe('edge.remove', extra.onUnlike); window.FB.XFBML.parse(); _this.setApiStep(); } return true; }) .catch(console.error); }; FacebookLike.prototype.onUnmount = function (extra) { if (window.FB) { window.FB.Event.unsubscribe('auth.login', extra.onLogin); window.FB.Event.unsubscribe('auth.logout', extra.onLogout); window.FB.Event.unsubscribe('edge.create', extra.onLike); window.FB.Event.unsubscribe('edge.remove', extra.onUnlike); destroyFacebookSDK(); } }; return FacebookLike; }(BaseWidgetComponent)); export default FacebookLike;