From 7a2a894fab8414200b53da9d2d6959c80271cad8 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 29 Apr 2016 11:24:11 +0200 Subject: * JS libraries as control dependencies --- app/php/web/TemplateControl.php | 29 ++++++++++++++++++++++++----- http/index.php | 4 +++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/php/web/TemplateControl.php b/app/php/web/TemplateControl.php index e3c9e26..a397f6f 100644 --- a/app/php/web/TemplateControl.php +++ b/app/php/web/TemplateControl.php @@ -9,10 +9,30 @@ class TemplateControl extends TTemplateControl { . '.js'; } + private function _getLibScriptPath($identifier) { + return Prado::getPathOfNamespace('Lib') + . DIRECTORY_SEPARATOR + . $identifier + . '.js'; + } + public function onPreRender($param) { parent::onPreRender($param); $scriptFile = $this->_getControlScriptPath(get_class($this)); if (file_exists($scriptFile)) { + foreach ($this->getExternalScriptDependencies() as $dependency) { + $this->Page->ClientScript->registerHeadScriptFile( + $dependency, $dependency + ); + } + foreach ($this->getLibScriptDependencies() as $dependency) { + $this->Page->ClientScript->registerScriptFile( + 'LibScript.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibScriptPath($dependency) + ) + ); + } foreach ($this->getPradoScriptDependencies() as $dependency) { $this->Page->ClientScript->registerPradoScript($dependency); } @@ -24,11 +44,6 @@ class TemplateControl extends TTemplateControl { ) ); } - foreach ($this->getExternalScriptDependencies() as $dependency) { - $this->Page->ClientScript->registerHeadScriptFile( - $dependency, $dependency - ); - } $this->Page->ClientScript->registerScriptFile( 'TemplateControl.' . get_class($this), $this->Application->AssetManager->publishFilePath($scriptFile) @@ -44,6 +59,10 @@ class TemplateControl extends TTemplateControl { return []; } + protected function getLibScriptDependencies() { + return []; + } + protected function getExternalScriptDependencies() { return []; } diff --git a/http/index.php b/http/index.php index f5e04d6..5519aa6 100644 --- a/http/index.php +++ b/http/index.php @@ -1,12 +1,14 @@ run(); -- cgit v1.2.3