Add method for adding custom javascript files

I add a method whichs allows adding javascript-files to the layout. It's realized exactly like the custom css method.
This commit is contained in:
bas tey
2020-04-27 21:21:36 +02:00
committed by GitHub
parent 91b85b4091
commit a830a65b67
+26
View File
@@ -50,6 +50,13 @@ class PrettyPageHandler extends Handler
*/
private $customCss = null;
/**
* The name of the custom js file.
*
* @var string
*/
private $customJs = null;
/**
* @var array[]
*/
@@ -193,6 +200,10 @@ class PrettyPageHandler extends Handler
$customCssFile = $this->getResource($this->customCss);
}
if ($this->customJs) {
$customJsFile = $this->getResource($this->customJs);
}
$inspector = $this->getInspector();
$frames = $this->getExceptionFrames();
$code = $this->getExceptionCode();
@@ -252,6 +263,10 @@ class PrettyPageHandler extends Handler
$vars["stylesheet"] .= file_get_contents($customCssFile);
}
if (isset($customJsFile)) {
$vars["javascript"] .= file_get_contents($customJsFile);
}
// Add extra entries list of data tables:
// @todo: Consolidate addDataTable and addDataTableCallback
$extraTables = array_map(function ($table) use ($inspector) {
@@ -593,6 +608,17 @@ class PrettyPageHandler extends Handler
$this->customCss = $name;
}
/**
* Adds a custom js file to be loaded.
*
* @param string $name
* @return void
*/
public function addCustomJs($name)
{
$this->customJs = $name;
}
/**
* @return array
*/