From dbf409f9d396e2e3bf8707edfabee8c00a3ebf8c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 29 Apr 2021 01:57:39 +0200 Subject: [PATCH] dumper.js: initializes lazy dumps on click [Closes #482] --- src/Tracy/Dumper/assets/dumper.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Tracy/Dumper/assets/dumper.js b/src/Tracy/Dumper/assets/dumper.js index 1b3986dfe..ff8aec093 100644 --- a/src/Tracy/Dumper/assets/dumper.js +++ b/src/Tracy/Dumper/assets/dumper.js @@ -27,23 +27,13 @@ class Dumper el.classList.remove('tracy-collapsed'); }); - // lazy - (context || document).querySelectorAll('[data-tracy-snapshot]').forEach((el) => { //
-			let snapshot = JSON.parse(el.getAttribute('data-tracy-snapshot'));
-			el.removeAttribute('data-tracy-snapshot');
-			el.querySelectorAll('[data-tracy-dump]').forEach((el) => { // 
-				if (!el.nextSibling) {
-					el.after(document.createTextNode('\n')); // enforce \n after toggler
-				}
-				el.nextSibling.after(buildStruct(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el, true, []));
-				el.removeAttribute('data-tracy-dump');
-			});
-		});
-
 		// snapshots
 		(context || document).querySelectorAll('meta[itemprop=tracy-snapshot]').forEach((el) => {
 			let snapshot = JSON.parse(el.getAttribute('content'));
 			el.parentElement.querySelectorAll('[data-tracy-dump]').forEach((el) => { // 
+				if (el.closest('[data-tracy-snapshot]')) { // ignore unrelated 
+					return;
+				}
 				el.appendChild(build(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el.classList.contains('tracy-collapsed')));
 				el.removeAttribute('data-tracy-dump');
 				el.classList.remove('tracy-collapsed');
@@ -55,13 +45,26 @@ class Dumper
 		}
 		Dumper.inited = true;
 
-		// enables  & ctrl key
 		document.documentElement.addEventListener('click', (e) => {
 			let el;
+			// enables  & ctrl key
 			if (e.ctrlKey && (el = e.target.closest('[data-tracy-href]'))) {
 				location.href = el.getAttribute('data-tracy-href');
 				return false;
 			}
+
+			// initializes lazy  inside 
+			if ((el = e.target.closest('[data-tracy-snapshot]'))) {
+				let snapshot = JSON.parse(el.getAttribute('data-tracy-snapshot'));
+				el.removeAttribute('data-tracy-snapshot');
+				el.querySelectorAll('[data-tracy-dump]').forEach((el) => {
+					if (!el.nextSibling) {
+						el.after(document.createTextNode('\n')); // enforce \n after toggler
+					}
+					el.nextSibling.after(buildStruct(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el, true, []));
+					el.removeAttribute('data-tracy-dump');
+				});
+			}
 		});
 
 		document.documentElement.addEventListener('tracy-toggle', (e) => {