diff options
author | wei <> | 2006-01-15 11:04:00 +0000 |
---|---|---|
committer | wei <> | 2006-01-15 11:04:00 +0000 |
commit | abc5bbd9c771dcecfa41ba3590cce1c1ef190cdd (patch) | |
tree | 45884a9f15efb190144165d50f79bab6fa914494 /framework/Web/UI/TClientScriptManager.php | |
parent | 5af330b442f15be0f0535a9e3c053b8e6eb5a202 (diff) |
Diffstat (limited to 'framework/Web/UI/TClientScriptManager.php')
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 61 |
1 files changed, 60 insertions, 1 deletions
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) |