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
|
function historyApiBack() {
window.history && window.history.back();
}
function redirectToIframesView() {
var redirect_to,
subject = stateObj.pathname
//.replace(stateObj.subfolder, '')
.replace(`/src/views`, '')
.replace('.php', '');
if (subject.includes('/redirect/server')) {
subject = subject.replace('/redirect/server', '/servers');
}
subject += location.search;
redirect_to = `${subject}`;
var redirection_msg =
'location subject is ' + subject + ' will redirect_to ' + redirect_to;
console.log(
`redirect: ${stateObj.pathname}${location.search} -> ${redirect_to}`
);
return redirect_to;
}
$.ready
.then(() => {
// Need to open popup from parent document
stateObj.basePath =
window.parent.location.origin + (stateObj.subfolder || '');
let redirect_to = redirectToIframesView();
window.parent.document.title = window.document.title;
/* beautify preserve:start */
stateObj.realurl = location.href; //.replace(location.origin, '');
//path will only be defined inside a route
/* beautify preserve:end */
stateObj.redirect_to = redirect_to;
stateObj.parenturl = window.parent.location.href;
if (window.location.href.indexOf('servers?action=logout') !== -1) {
window.setTimeout(function () {
window.parent.location.replace(`${stateObj.basePath}/servers`);
}, 3000);
return { jqFn: {}, hljsFn: {} };
}
if (window.jsTree) {
return { jqFn: jQuery.fn || {}, hljsFn: globalThis.hljs || {} };
}
if (
shouldSkipRedirection() ||
window.parent.frames.length === 0 ||
stateObj.redirect_to === stateObj.parenturl
) {
if (
stateObj.method === 'GET' &&
stateObj.redirect_to !== stateObj.parenturl
) {
let { reload } = stateObj || {};
console.log('will pushState. Reload is ' + reload, stateObj);
window.parent.history.pushState(
stateObj,
document.title,
stateObj.redirect_to
);
}
return { jqFn: jQuery.fn || {}, hljsFn: globalThis.hljs || {} };
} else {
//console.log({ stateObj });
window.parent.location.replace(redirect_to);
}
return { jqFn: {}, hljsFn: {} };
})
.then(({ jqFn, hljsFn }) => {
if (jqFn.select2) {
jQuery('.select2').select2();
}
if (jqFn.DataTable) {
$('.will_be_datatable').DataTable({
pageLength: 100,
});
}
if (hljsFn.highlightBlock) {
$('pre code.hljs').each(function (i, block) {
hljsFn.highlightBlock(block);
});
}
let { reload } = stateObj || {};
if (reload && reload !== 'none') {
globalThis.postMessage(
{ reload_browser: true },
window.parent.location.origin
);
}
return;
})
.catch((err) => {
console.error(err);
});
|