Skip to content

Commit ef7453f

Browse files
committed
Improve file handler loading.
1 parent f87a5e2 commit ef7453f

File tree

4 files changed

+97
-64
lines changed

4 files changed

+97
-64
lines changed

TracyDebugger.module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function getModuleInfo() {
2727
'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__),
2828
'author' => 'Adrian Jones',
2929
'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/',
30-
'version' => '4.26.83',
30+
'version' => '4.26.84',
3131
'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first
3232
'singular' => true,
3333
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',

scripts/adminer.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,31 @@ function openAdminer(queryStr) {
1919
}
2020
}
2121

22-
document.addEventListener('DOMContentLoaded', function() {
23-
document.body.addEventListener("click", function(e) {
24-
if(e.target) {
25-
var curEl = e.target;
26-
while(curEl && curEl.tagName != "A") {
27-
curEl = curEl.parentNode;
28-
}
29-
if(curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) {
30-
e.preventDefault();
31-
var queryStr = curEl.href.split('?')[1];
32-
if (e.shiftKey) {
33-
window.location = curEl.href.replace("adminer://", window.AdminerUrl);
34-
} else {
35-
openAdminer(queryStr);
22+
(function initAdminerHandler() {
23+
function setupAdminerClickHandler() {
24+
document.body.addEventListener("click", function(e) {
25+
if (e.target) {
26+
let curEl = e.target;
27+
while (curEl && curEl.tagName !== "A") {
28+
curEl = curEl.parentNode;
29+
}
30+
31+
if (curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) {
32+
e.preventDefault();
33+
const queryStr = curEl.href.split('?')[1];
34+
if (e.shiftKey) {
35+
window.location = curEl.href.replace("adminer://", window.AdminerUrl);
36+
} else {
37+
openAdminer(queryStr);
38+
}
3639
}
3740
}
38-
}
39-
});
40-
});
41+
});
42+
}
43+
44+
if (document.readyState === 'loading') {
45+
document.addEventListener('DOMContentLoaded', setupAdminerClickHandler);
46+
} else {
47+
setupAdminerClickHandler();
48+
}
49+
})();

scripts/exception-loader.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,47 @@ if(!tracyExceptionLoader) {
7171
}
7272
};
7373

74-
document.addEventListener('DOMContentLoaded', function() {
75-
// click event added to body because of links on bluescreen
76-
const htmlElement = document.documentElement;
77-
var doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
78-
doc.addEventListener("click", function(e) {
79-
if(e.target) {
80-
var curEl = e.target;
81-
while(curEl && curEl.tagName != "A") {
82-
curEl = curEl.parentNode;
83-
}
84-
if(curEl && curEl.href && curEl.href.indexOf("tracyexception://") !== -1) {
85-
e.preventDefault();
86-
var queryStr = curEl.href.split('?')[1];
87-
var fullFilePath = tracyExceptionLoader.getFileLineVars(queryStr, "f");
88-
tracyExceptionLoader.loadExceptionFile(fullFilePath);
89-
}
74+
(function initTracyExceptionHandler() {
75+
function setupTracyClickHandler() {
76+
const htmlElement = document.documentElement;
77+
const doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
9078

91-
let tracyExceptionFiles = document.getElementById("tracyExceptionFiles");
92-
if(tracyExceptionFiles) {
93-
let tracyExceptions = tracyExceptionFiles.getElementsByTagName("li");
94-
var length = tracyExceptions.length;
95-
for (var i = 0; i < length; i++) {
96-
var queryStr = tracyExceptions[i].getElementsByTagName("a")[0].href.split('?')[1];
97-
var currentFilePath = decodeURI(queryStr.replace('f=','').replace('&l=1','')).replace('site/assets/logs/tracy/', '');
98-
tracyExceptions[i].getElementsByTagName("a")[0].className = document.getElementById('panelTitleFilePath').innerHTML == currentFilePath ? "active" : "";
79+
doc.addEventListener("click", function(e) {
80+
if (e.target) {
81+
let curEl = e.target;
82+
83+
while (curEl && curEl.tagName !== "A") {
84+
curEl = curEl.parentNode;
85+
}
86+
87+
if (curEl && curEl.href && curEl.href.indexOf("tracyexception://") !== -1) {
88+
e.preventDefault();
89+
const queryStr = curEl.href.split('?')[1];
90+
const fullFilePath = tracyExceptionLoader.getFileLineVars(queryStr, "f");
91+
tracyExceptionLoader.loadExceptionFile(fullFilePath);
92+
}
93+
94+
const tracyExceptionFiles = document.getElementById("tracyExceptionFiles");
95+
if (tracyExceptionFiles) {
96+
const tracyExceptions = tracyExceptionFiles.getElementsByTagName("li");
97+
const length = tracyExceptions.length;
98+
for (let i = 0; i < length; i++) {
99+
const queryStr = tracyExceptions[i].getElementsByTagName("a")[0].href.split('?')[1];
100+
const currentFilePath = decodeURI(queryStr.replace('f=', '').replace('&l=1', '')).replace('site/assets/logs/tracy/', '');
101+
tracyExceptions[i].getElementsByTagName("a")[0].className =
102+
document.getElementById('panelTitleFilePath').innerHTML === currentFilePath ? "active" : "";
103+
}
99104
}
100105
}
101-
}
102-
});
103-
});
106+
});
107+
}
108+
109+
if (document.readyState === 'loading') {
110+
document.addEventListener('DOMContentLoaded', setupTracyClickHandler);
111+
} else {
112+
// DOM already loaded
113+
setupTracyClickHandler();
114+
}
115+
})();
116+
104117
}

scripts/file-editor.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,37 @@ if(!tracyFileEditorLoader) {
157157
};
158158
tracyFileEditorLoader.initializeEditor();
159159

160-
document.addEventListener('DOMContentLoaded', function() {
160+
(function initTracyFileEditorHandler() {
161+
function setupTracyFileEditorClickHandler() {
162+
const htmlElement = document.documentElement;
163+
const doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
161164

162-
// click event added to body because of links on bluescreen
163-
const htmlElement = document.documentElement;
164-
var doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
165-
doc.addEventListener("click", function(e) {
165+
doc.addEventListener("click", function(e) {
166+
if (e.target) {
167+
let curEl = e.target;
166168

167-
if(e.target) {
168-
var curEl = e.target;
169-
while(curEl && curEl.tagName != "A") {
170-
curEl = curEl.parentNode;
171-
}
172-
if(curEl && curEl.href && curEl.href.indexOf("tracy://") !== -1) {
173-
e.preventDefault();
174-
var queryStr = curEl.href.split('?')[1];
175-
var fullFilePath = tracyFileEditorLoader.getFileLineVars(queryStr, "f");
176-
tracyFileEditorLoader.loadFileEditor(fullFilePath, tracyFileEditorLoader.getFileLineVars(queryStr, "l"));
177-
tracyFileEditorLoader.addRecentlyOpenedFile(fullFilePath);
169+
while (curEl && curEl.tagName !== "A") {
170+
curEl = curEl.parentNode;
171+
}
172+
173+
if (curEl && curEl.href && curEl.href.indexOf("tracy://") !== -1) {
174+
e.preventDefault();
175+
176+
const queryStr = curEl.href.split('?')[1];
177+
const fullFilePath = tracyFileEditorLoader.getFileLineVars(queryStr, "f");
178+
const line = tracyFileEditorLoader.getFileLineVars(queryStr, "l");
179+
180+
tracyFileEditorLoader.loadFileEditor(fullFilePath, line);
181+
tracyFileEditorLoader.addRecentlyOpenedFile(fullFilePath);
182+
}
178183
}
179-
}
180-
});
181-
});
184+
});
185+
}
186+
187+
if (document.readyState === 'loading') {
188+
document.addEventListener('DOMContentLoaded', setupTracyFileEditorClickHandler);
189+
} else {
190+
setupTracyFileEditorClickHandler();
191+
}
192+
})();
182193
}

0 commit comments

Comments
 (0)