forked from bitrequest/bitrequest.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassets_js_lib_bitrequest_checkout.js
More file actions
111 lines (99 loc) · 2.79 KB
/
assets_js_lib_bitrequest_checkout.js
File metadata and controls
111 lines (99 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
$(document).ready(function() {
checkout();
window.addEventListener("message", crossframe);
keyup();
closeloader_trigger();
});
function checkout() {
$(document).on("click", ".br_checkout", function(e) {
e.preventDefault();
let checkout_url = $(this).attr("href"),
br_frame = $("#br_framebox iframe");
if (br_frame.length > 0) {
showloader();
br_frame.attr("src", checkout_url);
} else {
append_iframe(checkout_url);
showloader();
}
});
}
function append_iframe(framesrc) {
$("body").append("<div id='br_framebox'><iframe src='" + framesrc + "'></iframe></div><div id='br_loadbox'><div id='br_loadpanel'><div id='br_loader'></div><p>Loading request...</p></div></div>");
iframe_loaded();
}
function iframe_loaded() {
let requestframe = $("#br_framebox iframe");
requestframe.on("load", function() {
if (requestframe.attr("src") !== undefined) {
showframe();
}
});
}
function crossframe(e) {
let data = e.data;
if (data == "close_loader") {
closeloader();
} else if (data == "close_request") {
setTimeout(function() {
closeframe_confirm();
}, 200);
} else if (data.id == "result") {
result_callback(data.data);
}
}
function result_callback(post_data) {
// overwrite this function for your callback
console.log("overwrite this function for your callback");
console.log(post_data);
}
function showframe() {
$("html").addClass("showframe zoomframe");
}
function closeframe_confirm() {
let result = confirm("Close request?");
if (result === true) {
closeframe();
}
}
function closeframe() {
let html_node = $("html");
if (html_node.hasClass("zoomframe")) {
html_node.removeClass("zoomframe");
setTimeout(function() {
html_node.removeClass("showframe");
$("#br_framebox iframe").removeAttr("src");
}, 400);
}
}
function showloader() {
$("html").addClass("slide_loader fade_loader");
}
function closeloader_trigger() {
$(document).on("click", "#br_loadbox", function() {
closeloader();
});
}
function closeloader() {
let html_node = $("html");
if (html_node.hasClass("fade_loader")) {
html_node.removeClass("fade_loader");
setTimeout(function() {
html_node.removeClass("slide_loader");
}, 1000);
}
}
function keyup() {
$(document).keyup(function(e) {
if (e.keyCode == 27) {
if (html.hasClass("slide_loader")) {
closeloader();
return false;
}
if (html.hasClass("showframe")) {
closeframe_confirm();
return false;
}
}
});
}