From abc5bbd9c771dcecfa41ba3590cce1c1ef190cdd Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 15 Jan 2006 11:04:00 +0000 Subject: --- framework/Web/UI/TClientScriptManager.php | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'framework/Web/UI/TClientScriptManager.php') diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 9537859d..f7778de9 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -163,7 +163,7 @@ class TClientScriptManager extends TComponent return $javascriptPrefix?'javascript:'.$postback:$postback; } - public function registerPradoScript($script) + /*public function registerPradoScript($script) { foreach(TPradoClientScript::getScripts($script) as $scriptFile) { @@ -181,8 +181,67 @@ class TClientScriptManager extends TComponent } } //return $url; + }*/ + + /** + * Register Prado client scripts. + */ + public function registerPradoScript($script) + { + static $scripts = array(); + $scripts = array_unique(array_merge($scripts, + TPradoClientScript::getScripts($script))); + + $this->publishClientScriptAssets($scripts); + + //create the client script url + $url = $this->publishClientScriptCompressorAsset(); + $url .= '?js='.implode(',', $scripts); + if(Prado::getApplication()->getMode() == TApplication::STATE_DEBUG) + $url .= '&nocache'; + $this->registerScriptFile('prado:gzipscripts', $url); } + /** + * Publish each individual javascript file. + */ + private function publishClientScriptAssets($scripts) + { + foreach($scripts as $lib) + { + if(!isset($this->_publishedScriptFiles[$lib])) + { + $base = Prado::getFrameworkPath(); + $clientScripts = self::SCRIPT_DIR; + $assetManager = $this->_page->getService()->getAssetManager(); + $file = "{$base}/{$clientScripts}/{$lib}.js"; + $assetManager->publishFilePath($file); + $this->_publishedScriptFiles[$lib] = true; + } + } + } + + /** + * @return string URL of the compressor asset script. + */ + private function publishClientScriptCompressorAsset() + { + $scriptFile = 'clientscripts.php'; + if(isset($this->_publishedScriptFiles[$scriptFile])) + return $this->_publishedScriptFiles[$scriptFile]; + else + { + $base = Prado::getFrameworkPath(); + $clientScripts = self::SCRIPT_DIR; + $assetManager = $this->_page->getService()->getAssetManager(); + $file = "{$base}/{$clientScripts}/{$scriptFile}"; + $url= $assetManager->publishFilePath($file); + $this->_publishedScriptFiles[$scriptFile] = $url; + return $url; + } + } + + protected function registerPostBackScript() { if(!$this->_postBackScriptRegistered) -- cgit v1.2.3