Tracy does not get var defined, but on generated page is defined. how can tracy get this var?
- alnux
- Member | 139
Hi,
I am adapting LiveTranslator to nette
3.1 but I have a tracy error showing me in the console the error
?_tracy_bar=js&v=2.9.5&XDEBUG_SESSION_STOP=1
indicating a reference error
Uncaught ReferenceError: translationPanel is not defined
on the lines
538 and 544 of the evalScripts function
function evalScripts(elem) {
elem.querySelectorAll('script').forEach((script) => { // <--------- line 538
if ((!script.hasAttribute('type') |/ script.type === 'text/javascript' |/ script.type === 'application/javascript') && !script.tracyEvaluated) {
let document = script.ownerDocument;
let dolly = document.createElement('script');
dolly.textContent = script.textContent;
dolly.setAttribute('nonce', nonce);
(document.body |/ document.documentElement).appendChild(dolly); // <-------- line 544
script.tracyEvaluated = true;
}
});
}
and 403 of the init function
static init(content) {
Debug.bar = new bar;
Debug.panel = {};
Debug.layer = document.createElement('tracy-div');
Debug.layer.setAttribute('id', 'tracy-debug');
Debug.layer.innerHTML = content;
(document.body |/ document.documentElement).appendChild(Debug.layer);
evalScripts(Debug.layer); // <-------------------------------------- line 403
Debug.layer.style.display = 'block';
Debug.bar.init();
Debug.layer.querySelectorAll('.tracy-panel').forEach((panel) => {
Debug.panels[panel.id ] = new Panel(panel.id );
Debug.panels[panel.id ].restorePosition();
});
Debug.captureWindow();
Debug.captureAjax();
Tracy.TableSort.init();
}
but I see in the source of the generated page that the variable is defined (down part of generated code),
]);\n\treturn temp;\n}\n\n\nvar translationPanel = {\n\tstrings: {\"text to translate\":false},\n\tvariants: 1,\n\n\tupdatedStrings:
wich is generated by
/**
* Returns the code for the panel.
* @return string
*/
public function getPanel()
{
$latte = $this->createTemplate();
$file = $this->translator->isCurrentLangDefault() ? '/panel.inactive.phtml' : '/panel.phtml';
$parameters = array();
$parameters['panel'] = $this;
$parameters['translator'] = $this->translator;
$parameters['lang'] = $this->translator->getCurrentLang();
if ($this->translator->getPresenterLanguageParam()){
$parameters['availableLangs'] = $this->translator->getAvailableLanguages();
}
else {
$parameters['availableLangs'] = NULL;
}
return $latte->renderToString(__DIR__ . $file, $parameters);
}
/**
* Returns the code for the panel tab.
* @return string
*/
public function getTab()
{
//$template = new Nette\Templating\FileTemplate(__DIR__ . '/tab.phtml');
$template = new Latte\Loaders\FileLoader(__DIR__);
return $template->getContent('tab.phtml');
//return $template->__toString();
}
panel.phtml
code and tab.phtml
code
after several modifications everything seems to be going well (screenshot), only the
definition of this variable (translationPanel) towards tracy is missing.
how can I pass this variable to tracy or how can tracy get this var?
thanks
Last edited by alnux (2022-12-19 18:43)