@mornya/react-social-libs
Version:
The project of React.js Social Share and Widget modules.
257 lines (256 loc) • 9.9 kB
JavaScript
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 { initKakaoSDK, destroyKakaoSDK } from '../utils/Loader';
var KakaoTalk = (function (_super) {
__extends(KakaoTalk, _super);
function KakaoTalk() {
return _super !== null && _super.apply(this, arguments) || this;
}
KakaoTalk.prototype.onInit = function () {
this.initialize('KakaoTalk', {
appId: '',
type: '',
value: undefined,
isInstallTalk: true,
});
};
KakaoTalk.prototype.onMount = function (extra) {
var _this = this;
initKakaoSDK(extra.appId)
.then(function () { return _this.setApiStep(); })
.catch(console.error);
};
KakaoTalk.prototype.onShare = function (extra, _OG) {
var _a;
if ((_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.isInitialized()) {
switch (extra.type) {
case 'feed':
this.sendFeed(extra);
break;
case 'list':
this.sendList(extra);
break;
case 'location':
this.sendLocation(extra);
break;
case 'commerce':
this.sendCommerce(extra);
break;
case 'text':
this.sendText(extra);
break;
case 'scrap':
this.sendScrap(extra);
break;
case 'custom':
this.sendCustom(extra);
break;
default:
break;
}
}
else {
console.error('Kakao SDK was not initialized.');
}
};
KakaoTalk.prototype.onUnmount = function (_extra) {
destroyKakaoSDK();
};
KakaoTalk.prototype.sendFeed = function (extra) {
var _this = this;
var _a, _b;
var option = {
objectType: 'feed',
content: extra.value.content,
social: extra.value.social,
installTalk: (_a = extra.isInstallTalk) !== null && _a !== void 0 ? _a : true,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
if (extra.value.buttonTitle) {
option.buttonTitle = extra.value.buttonTitle;
}
else {
option.buttons = extra.value.buttons;
}
(_b = window.Kakao) === null || _b === void 0 ? void 0 : _b.Share.sendDefault(option);
};
KakaoTalk.prototype.sendList = function (extra) {
var _this = this;
var _a;
var option = {
objectType: 'list',
headerTitle: extra.value.headerTitle,
headerLink: extra.value.headerLink,
contents: extra.value.contents,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
if (extra.value.headerImageUrl) {
option.headerImageUrl = extra.value.headerImageUrl;
option.headerImageWidth = extra.value.headerImageWidth;
option.headerImageHeight = extra.value.headerImageHeight;
}
if (extra.value.buttonTitle) {
option.buttonTitle = extra.value.buttonTitle;
}
else {
option.buttons = extra.value.buttons;
}
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendDefault(option);
};
KakaoTalk.prototype.sendLocation = function (extra) {
var _this = this;
var _a;
var option = {
objectType: 'location',
content: extra.value.content,
address: extra.value.address,
addressTitle: extra.value.addressTitle,
social: extra.value.social,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
if (extra.value.buttonTitle) {
option.buttonTitle = extra.value.buttonTitle;
}
else {
option.buttons = extra.value.buttons;
}
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendDefault(option);
};
KakaoTalk.prototype.sendCommerce = function (extra) {
var _this = this;
var _a;
var option = {
objectType: 'commerce',
content: extra.value.content,
commerce: extra.value.commerce,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
if (extra.value.buttonTitle) {
option.buttonTitle = extra.value.buttonTitle;
}
else {
option.buttons = extra.value.buttons;
}
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendDefault(option);
};
KakaoTalk.prototype.sendText = function (extra) {
var _this = this;
var _a;
var option = {
objectType: 'text',
text: extra.value.text,
link: extra.value.link,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
if (extra.value.buttonTitle) {
option.buttonTitle = extra.value.buttonTitle;
}
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendDefault(option);
};
KakaoTalk.prototype.sendScrap = function (extra) {
var _this = this;
var _a;
var option = {
requestUrl: extra.value.requestUrl,
templateId: extra.value.templateId,
templateArgs: extra.value.templateArgs,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendScrap(option);
};
KakaoTalk.prototype.sendCustom = function (extra) {
var _this = this;
var _a;
var option = {
templateId: extra.value.templateId,
templateArgs: extra.value.templateArgs,
installTalk: !!extra.isInstallTalk,
success: function (messageObj) {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(true, messageObj);
},
fail: function () {
var _a;
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.cleanup();
_this.onComplete(false, null);
},
};
(_a = window.Kakao) === null || _a === void 0 ? void 0 : _a.Share.sendCustom(option);
};
return KakaoTalk;
}(BaseShareComponent));
export default KakaoTalk;