-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProcessTracyAdminer.module.php
More file actions
152 lines (125 loc) · 6.49 KB
/
ProcessTracyAdminer.module.php
File metadata and controls
152 lines (125 loc) · 6.49 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
141
142
143
144
145
146
147
148
149
150
151
152
<?php
class ProcessTracyAdminer extends Process implements Module {
public static function getModuleInfo() {
return array(
'title' => __('Process Tracy Adminer', __FILE__),
'summary' => __('Adminer page for TracyDebugger.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/topic/12208-tracy-debugger/',
'version' => '2.0.3',
'autoload' => false,
'singular' => true,
'icon' => 'database',
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4, TracyDebugger, ProcessTracyAdminerRenderer',
'installs' => array('ProcessTracyAdminerRenderer'),
'page' => array(
'name' => 'adminer',
'parent' => 'setup',
'title' => 'Adminer'
)
);
}
public function ___execute() {
$data = $this->wire('modules')->getModuleConfigData('TracyDebugger');
if(isset($data['adminerStandAlone']) && $data['adminerStandAlone'] === 1) {
return $this->wire('modules')->get('ProcessTracyAdminerRenderer')->execute();
}
else {
return '
<iframe id="adminer-iframe" src="'.str_replace('/adminer/', '/adminer-renderer/', $_SERVER['REQUEST_URI']).'" style="width:100vw; border: none; padding:0; margin:0;"></iframe>
<script>
const adminer_iframe = document.getElementById("adminer-iframe");
window.addEventListener("popstate", function (event) {
adminer_iframe.src = location.href.replace("/adminer/", "/adminer-renderer/");
});
const baseUrl = window.location.href.split("?")[0];
const allowedOrigin = new URL(window.location.href).origin;
const serviceTitle = document.title;
const adminneoFrame = document.getElementById("adminer-iframe");
window.addEventListener("message", function (event) {
if (!event.isTrusted || event.origin !== allowedOrigin || event.source !== adminneoFrame.contentWindow) {
return;
}
const data = event.data;
if (typeof data === "object" && data.event === "adminneo-loading") {
const search = new URL(data.url).search;
document.title = `${data.title} - ${serviceTitle}`;
history.replaceState(null, null, baseUrl + search);
}
});
window.addEventListener("load", function(event) {
var masthead = document.getElementById("pw-masthead");
if (masthead && adminer_iframe) {
var mastheadHeight = masthead.offsetHeight;
adminer_iframe.style.height = `calc(100vh - ${mastheadHeight}px)`;
}
});
// determine scrollbarWidth
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.overflow = "scroll";
div.style.visibility = "hidden";
document.body.appendChild(div);
const scrollbarWidth = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
// move tracy debug bar to up and left to accommodate iframe scrollbars if needed
function adjustTracyDebugBar(iframe) {
if (!iframe) return;
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDoc) return;
const body = iframeDoc.body;
const html = iframeDoc.documentElement;
const hasHorizontalScrollbar = body.scrollWidth > body.clientWidth || html.scrollWidth > html.clientWidth;
const hasVerticalScrollbar = body.scrollHeight > body.clientHeight || html.scrollHeight > html.clientHeight;
const tracyDebugBar = document.getElementById("tracy-debug-bar");
if (tracyDebugBar) {
if (hasHorizontalScrollbar) {
tracyDebugBar.style.setProperty("bottom", scrollbarWidth + "px", "important");
}
else {
tracyDebugBar.style.removeProperty("bottom");
}
if (hasVerticalScrollbar) {
tracyDebugBar.style.setProperty("right", scrollbarWidth + "px", "important");
}
else {
tracyDebugBar.style.removeProperty("right");
}
}
}
function observeIframeChanges(iframe) {
if (!iframe) return;
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDoc) return;
const mutationObserver = new MutationObserver(() => adjustTracyDebugBar(iframe));
mutationObserver.observe(iframeDoc.body, { childList: true, subtree: true });
const resizeObserver = new ResizeObserver(() => adjustTracyDebugBar(iframe));
resizeObserver.observe(iframeDoc.documentElement);
iframe._tracyMutationObserver = mutationObserver;
iframe._tracyResizeObserver = resizeObserver;
}
if (adminer_iframe) {
adminer_iframe.onload = () => {
adjustTracyDebugBar(adminer_iframe);
observeIframeChanges(adminer_iframe);
};
window.addEventListener("resize", () => adjustTracyDebugBar(adminer_iframe));
}
</script>
<style>
#pw-content-head, #pw-content-title, #pw-footer, #notices {
display: none;
}
#main {
padding: 0 !important;
margin: 0 !important;
}
/* Fallback in case automatic JS adjustment fails - 73px is the height of the standard UiKit masthead */
#adminer-iframe {
height: calc(100vh - 73px);
}
</style>';
}
}
}