support.js
5.3 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
jQuery.noConflict();
jQuery(document).ready(function () {
getWidgetFaq();
initTroubleshootTool();
if (window.location.href.match('b2s-support-system-check') != null) {
jQuery('.b2s-support-check-sytem').trigger('click');
}
if (window.location.href.match('b2s-support-sharing-debugger') != null) {
jQuery('.b2s-support-sharing-debugger').trigger('click');
}
jQuery(document).on('click', '.b2s-btn-sharing-debugger', function () {
var networkId = jQuery(this).attr('data-network-id');
if (networkId != 2) {
var url = jQuery(this).attr('b2s-url-query') + encodeURIComponent(jQuery('#b2s-debug-url[data-network-id="' + networkId + '"').val());
} else {
var url = jQuery(this).attr('b2s-url-query');
}
window.open(url, '_blank');
return false;
});
});
function getWidgetFaq() {
jQuery('.b2s-faq-area').show();
if (typeof wp.heartbeat == "undefined") {
jQuery('#b2s-heartbeat-fail').show();
}
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: "json",
cache: false,
data: {
'action': 'b2s_get_faq_entries',
'b2s_security_nonce': jQuery('#b2s_security_nonce').val()
},
error: function () {
jQuery('.b2s-faq-area').hide();
return false;
},
success: function (data) {
if (data.result == true) {
jQuery('.b2s-loading-area-faq').hide();
jQuery('.b2s-faq-content').html(data.content);
} else {
if (data.error == 'nonce') {
jQuery('.b2s-nonce-check-fail').show();
}
jQuery('.b2s-faq-area').hide();
}
}
});
}
function base64EncodeUnicode(str) {
var utf8Bytes = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode('0x' + p1);
});
return btoa(utf8Bytes);
}
function initTroubleshootTool() {
firstClick = false;
jQuery(document).on('click', '.b2s-support-check-sytem', function () {
if (!firstClick) {
jQuery('#b2s-reload-debug-btn').trigger('click');
firstClick = true;
}
});
jQuery(document).on('click', '#b2s-reload-debug-btn', function () {
jQuery('.b2s-server-connection-fail').hide();
jQuery('.b2s-support-fail').hide();
jQuery('#b2s-main-debug').hide();
jQuery('.b2s-loading-area').show();
jQuery.ajax({
url: ajaxurl,
type: "GET",
dataType: "json",
cache: false,
data: {'action': 'b2s_support_systemrequirements', 'b2s_security_nonce': jQuery('#b2s_security_nonce').val()},
error: function () {
jQuery('.b2s-server-connection-fail').show();
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-main-debug').show();
return false;
},
success: function (data) {
if (typeof data === 'undefined' || data === null) {
jQuery('.b2s-server-connection-fail').show();
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-main-debug').show();
return false;
} else if (data.result != true) {
if (data.error == 'nonce') {
jQuery('.b2s-nonce-check-fail').show();
}
if (data.error == 'admin') {
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-support-no-admin').show();
} else {
jQuery('.b2s-server-connection-fail').show();
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-main-debug').show();
return false;
}
} else {
if (typeof data.htmlData !== 'undefined') {
jQuery('#b2s-debug-htmlData').html(data.htmlData);
if (typeof data.blogData !== 'undefined') {
jQuery('#b2s-debug-export').removeClass('b2s-support-link-not-active');
jQuery('#b2s-debug-export').attr(
"href", "data:application/octet-stream;charset=utf-8;base64," +
base64EncodeUnicode(JSON.stringify(data.blogData, undefined, 2))
);
} else {
jQuery('#b2s-debug-export').addClass('b2s-support-link-not-active');
}
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-main-debug').show();
return true;
} else {
jQuery('.b2s-server-connection-fail').show();
jQuery('.b2s-loading-area').hide();
jQuery('#b2s-main-debug').show();
return false;
}
}
}
});
});
}