From 4acb87bdc04fc2062d5af5f1a174c399c4c832eb Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Mon, 14 Feb 2011 14:21:38 +0000 Subject: [PATCH] + add the feature of split css and js for every module. --- framework/control.class.php | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/framework/control.class.php b/framework/control.class.php index 54b59a1baa..d10a08be1b 100755 --- a/framework/control.class.php +++ b/framework/control.class.php @@ -298,6 +298,50 @@ class control return false; } + /** + * Get css code for a method. + * + * @param string $moduleName + * @param string $methodName + * @access private + * @return string + */ + private function getCSS($moduleName, $methodName) + { + $moduleName = strtolower(trim($moduleName)); + $methodName = strtolower(trim($methodName)); + $modulePath = $this->app->getModulePath($moduleName); + + $css = ''; + $mainCssFile = $modulePath . 'css' . $this->pathFix . 'common.css'; + $methodCssFile = $modulePath . 'css' . $this->pathFix . $methodName . '.css'; + if(file_exists($mainCssFile)) $css .= file_get_contents($mainCssFile); + if(file_exists($methodCssFile)) $css .= file_get_contents($methodCssFile); + return $css; + } + + /** + * Get js code for a method. + * + * @param string $moduleName + * @param string $methodName + * @access private + * @return string + */ + private function getJS($moduleName, $methodName) + { + $moduleName = strtolower(trim($moduleName)); + $methodName = strtolower(trim($methodName)); + $modulePath = $this->app->getModulePath($moduleName); + + $js = ''; + $mainJsFile = $modulePath . 'js' . $this->pathFix . 'common.js'; + $methodJsFile = $modulePath . 'js' . $this->pathFix . $methodName . '.js'; + if(file_exists($mainJsFile)) $js .= file_get_contents($mainJsFile); + if(file_exists($methodJsFile)) $js .= file_get_contents($methodJsFile); + return $js; + } + /** * Assign one var to the view vars. * @@ -384,6 +428,12 @@ class control $viewFile = $this->setViewFile($moduleName, $methodName); if(is_array($viewFile)) extract($viewFile); + /* Get css and js. */ + $css = $this->getCSS($moduleName, $methodName); + $js = $this->getJS($moduleName, $methodName); + if($css) $this->view->pageCss = $css; + if($js) $this->view->pageJS = $js; + /* Change the dir to the view file to keep the relative pathes work. */ $currentPWD = getcwd(); chdir(dirname($viewFile));