btcpayserver/BTCPayServer/wwwroot/checkout/js/coinswitchComponent.js

67 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-12-11 12:47:38 +01:00
var CoinSwitchComponent =
{
2018-12-18 19:01:58 +01:00
props: ["toCurrency", "toCurrencyDue", "toCurrencyAddress", "merchantId", "autoload", "mode"],
2018-12-11 12:47:38 +01:00
data: function () {
2018-12-20 14:33:31 +01:00
return {
opened: false
};
2018-12-11 12:47:38 +01:00
},
computed: {
2018-12-20 14:33:31 +01:00
showInlineIFrame: function(){
return this.url && this.opened;
},
2018-12-11 12:47:38 +01:00
url: function () {
return window.location.origin + "/checkout/coinswitch.html?" +
"&toCurrency=" +
this.toCurrency +
"&toCurrencyAddress=" +
this.toCurrencyAddress +
"&toCurrencyDue=" +
this.toCurrencyDue +
2018-12-20 14:33:31 +01:00
"&mode=" +
this.mode +
2018-12-11 12:47:38 +01:00
(this.merchantId ? "&merchant_id=" + this.merchantId : "");
}
},
methods: {
openDialog: function (e) {
if (e && e.preventDefault) {
e.preventDefault();
}
2018-12-20 14:33:31 +01:00
if(this.mode === 'inline'){
this.opened = true;
}else if(this.mode ==="popup"){
var coinSwitchWindow = window.open(
this.url,
'CoinSwitch',
'width=360,height=650,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');
coinSwitchWindow.opener = null;
coinSwitchWindow.focus();
}
},
closeDialog(){
if(this.mode === 'inline'){
this.opened = false;
}
},
onLoadIframe(event){
$("#prettydropdown-DefaultLang").hide();
var c = this.closeDialog.bind(this);
event.currentTarget.contentWindow.addEventListener("message", function(evt){
if(evt && evt.data == "popup-closed"){
c();
$("#prettydropdown-DefaultLang").show();
}
});
2018-12-11 12:47:38 +01:00
}
},
mounted: function () {
2018-12-20 14:33:31 +01:00
if(this.autoload){
2018-12-11 12:47:38 +01:00
this.openDialog();
}
2018-12-18 19:01:58 +01:00
}
2018-12-11 12:47:38 +01:00
};