diff options
author | emkael <emkael@tlen.pl> | 2016-04-29 15:37:31 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-04-29 15:37:31 +0200 |
commit | 90125e8b38323ea3fbd856ba565837a801677a7b (patch) | |
tree | c4cd463d6d0f0079bc36038b3250f2f6b5175424 /app | |
parent | 4077c281a95b9f53a52678e7f39e77f7e93544e2 (diff) |
* auto-registered stylesheets for controls
Diffstat (limited to 'app')
-rw-r--r-- | app/php/web/TemplateControl.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/app/php/web/TemplateControl.php b/app/php/web/TemplateControl.php index 952bd4f..213a680 100644 --- a/app/php/web/TemplateControl.php +++ b/app/php/web/TemplateControl.php @@ -8,6 +8,10 @@ class TemplateControl extends TTemplateControl { if (file_exists($scriptFile)) { $this->_registerScriptFile($scriptFile); } + $styleFile = $this->_getControlStylePath(get_class($this)); + if (file_exists($styleFile)) { + $this->_registerStyleFile($styleFile); + } } protected function getExternalScriptDependencies() { @@ -26,6 +30,18 @@ class TemplateControl extends TTemplateControl { return []; } + protected function getExternalStyleDependencies() { + return []; + } + + protected function getLibStyleDependencies() { + return []; + } + + protected function getControlStyleDependencies() { + return []; + } + private function _getControlScriptPath($className) { return Prado::getPathOfNamespace('Application.controls.scripts') . DIRECTORY_SEPARATOR @@ -33,6 +49,13 @@ class TemplateControl extends TTemplateControl { . '.js'; } + private function _getControlStylePath($className) { + return Prado::getPathOfNamespace('Application.controls.styles') + . DIRECTORY_SEPARATOR + . $className + . '.css'; + } + private function _getLibPath($identifier, $extension = '') { return Prado::getPathOfNamespace('Lib') . DIRECTORY_SEPARATOR @@ -95,6 +118,52 @@ class TemplateControl extends TTemplateControl { } } + private function _registerStyleFile($styleFile) { + $this->_registerExternalStyleDependencies( + $this->getExternalStyleDependencies() + ); + $this->_registerLibStyleDependencies( + $this->getLibStyleDependencies() + ); + $this->_registerControlStyleDependencies( + $this->getControlStyleDependencies() + ); + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . get_class($this), + $this->Application->AssetManager->publishFilePath($styleFile) + ); + } + + private function _registerExternalStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + $dependency, $dependency + ); + } + } + + private function _registerLibStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'LibStyle.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getLibPath($dependency, '.css') + ) + ); + } + } + + private function _registerControlStyleDependencies($dependencies) { + foreach ($dependencies as $dependency) { + $this->Page->ClientScript->registerStyleSheetFile( + 'TemplateControl.' . $dependency, + $this->Application->AssetManager->publishFilePath( + $this->_getControlStylePath($dependency) + ) + ); + } + } + } ?> |