summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TClientScriptManager.php
diff options
context:
space:
mode:
authorctrlaltca <>2012-06-01 18:01:40 +0000
committerctrlaltca <>2012-06-01 18:01:40 +0000
commit182630cd8c5d3db97dd4e3654540300b6d822e2d (patch)
tree4ddf9f443d7f638a03bbd600eeb953d89c95a3e0 /framework/Web/UI/TClientScriptManager.php
parentf337ba2bebcbe8f4a8493a482526131e6207bb6d (diff)
committed additional patch for #235
Diffstat (limited to 'framework/Web/UI/TClientScriptManager.php')
-rw-r--r--framework/Web/UI/TClientScriptManager.php102
1 files changed, 52 insertions, 50 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 3f1664ac..08b528b1 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -87,7 +87,7 @@ class TClientScriptManager extends TApplicationComponent
private $_renderedScriptFiles;
- private $_renderedPradoScripts;
+ private $_expandedPradoScripts;
/**
* Constructor.
@@ -133,7 +133,7 @@ class TClientScriptManager extends TApplicationComponent
/**
* Registers a Prado javascript library to be loaded.
*/
- private function registerPradoScriptInternal($name)
+ protected function registerPradoScriptInternal($name)
{
// $this->checkIfNotInRender();
if(!isset($this->_registeredPradoScripts[$name]))
@@ -146,70 +146,63 @@ class TClientScriptManager extends TApplicationComponent
self::$_pradoPackages = $packages;
}
- if(isset(self::$_pradoScripts[$name]))
+ if (isset(self::$_pradoScripts[$name]))
$this->_registeredPradoScripts[$name]=true;
else
throw new TInvalidOperationException('csmanager_pradoscript_invalid',$name);
- }
- }
-
- /**
- * @return string Prado javascript library base asset url.
- */
- public function getPradoScriptAssetUrl()
- {
- $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH;
- $assets = Prado::getApplication()->getAssetManager();
- return $assets->getPublishedUrl($base);
- }
-
- /**
- * Renders the HTML tags for PRADO js files
- * @param THtmlWriter writer
- */
- protected function renderPradoScriptsInt($writer, $initial)
- {
- if($initial) $this->_renderedPradoScripts = array();
- $addedScripts = array_diff($this->_registeredPradoScripts,$this->_renderedPradoScripts);
- if(($packages=array_keys($addedScripts))!==array())
- {
- $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH;
- list($path,$baseUrl)=$this->getPackagePathUrl($base);
- $packagesUrl=array();
- $isDebug=$this->getApplication()->getMode()===TApplicationMode::Debug;
- foreach ($packages as $p)
+
+ if(($packages=array_keys($this->_registeredPradoScripts))!==array())
{
- foreach (self::$_pradoScripts[$p] as $dep)
+ $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH;
+ list($path,$baseUrl)=$this->getPackagePathUrl($base);
+ $packagesUrl=array();
+ $isDebug=$this->getApplication()->getMode()===TApplicationMode::Debug;
+ foreach ($packages as $p)
{
- foreach (self::$_pradoPackages[$dep] as $script)
+ foreach (self::$_pradoScripts[$p] as $dep)
{
- if($isDebug)
+ foreach (self::$_pradoPackages[$dep] as $script)
+ if (!isset($this->_expandedPradoScripts[$script]))
{
- if (!in_array($url=$baseUrl.'/'.$script,$packagesUrl))
- $packagesUrl[]=$url;
- } else {
- if (!in_array($url=$baseUrl.'/min/'.$script,$packagesUrl))
+ $this->_expandedPradoScripts[$script] = true;
+ if($isDebug)
{
- if(!is_file($filePath=$path.'/min/'.$script))
+ if (!in_array($url=$baseUrl.'/'.$script,$packagesUrl))
+ $packagesUrl[]=$url;
+ } else {
+ if (!in_array($url=$baseUrl.'/min/'.$script,$packagesUrl))
{
- $dirPath=dirname($filePath);
- if(!is_dir($dirPath))
- mkdir($dirPath, PRADO_CHMOD, true);
- file_put_contents($filePath, TJavaScript::JSMin(file_get_contents($base.'/'.$script)));
- chmod($filePath, PRADO_CHMOD);
+ if(!is_file($filePath=$path.'/min/'.$script))
+ {
+ $dirPath=dirname($filePath);
+ if(!is_dir($dirPath))
+ mkdir($dirPath, PRADO_CHMOD, true);
+ file_put_contents($filePath, TJavaScript::JSMin(file_get_contents($base.'/'.$script)));
+ chmod($filePath, PRADO_CHMOD);
+ }
+ $packagesUrl[]=$url;
}
- $packagesUrl[]=$url;
}
}
}
}
+ foreach($packagesUrl as $url)
+ $this->registerScriptFile($url,$url);
}
- $writer->write(TJavaScript::renderScriptFiles($packagesUrl));
- $this->_renderedPradoScripts = $this->_registeredPradoScripts;
}
}
/**
+ * @return string Prado javascript library base asset url.
+ */
+ public function getPradoScriptAssetUrl()
+ {
+ $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH;
+ $assets = Prado::getApplication()->getAssetManager();
+ return $assets->getPublishedUrl($base);
+ }
+
+ /**
* Returns the URLs of all script files referenced on the page
* @return array Combined list of all script urls used in the page
*/
@@ -492,10 +485,10 @@ class TClientScriptManager extends TApplicationComponent
* @param string a unique key identifying the file
* @param string URL to the javascript file to be rendered
*/
- public function registerScriptFile($key,$url)
+ public function registerScriptFile($key, $url)
{
$this->_scriptFiles[$key]=$url;
-
+
$params=func_get_args();
$this->_page->registerCachingAction('Page.ClientScript','registerScriptFile',$params);
}
@@ -686,7 +679,6 @@ class TClientScriptManager extends TApplicationComponent
public function renderScriptFilesInt($writer, $initial)
{
if ($initial) $this->_renderedScriptFiles = array();
- $this->renderPradoScriptsInt($writer, $initial);
if(!empty($this->_scriptFiles))
{
$addedScripts = array_diff($this->_scriptFiles,$this->_renderedScriptFiles);
@@ -723,6 +715,16 @@ class TClientScriptManager extends TApplicationComponent
}
/**
+ * Flushes all pending script registrations
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function flushScriptFiles($writer)
+ {
+ assert($this->_page->InFormRender);
+ $this->renderScriptFilesInt($writer,false);
+ }
+
+ /**
* @param THtmlWriter writer for the rendering purpose
*/
protected function renderHiddenFieldsInt($writer, $initial)