diff options
author | ctrlaltca <> | 2012-06-25 09:25:11 +0000 |
---|---|---|
committer | ctrlaltca <> | 2012-06-25 09:25:11 +0000 |
commit | b2b24e4c5d2c2db803fe7abf47b5a37744d46146 (patch) | |
tree | 5c094ab4e1240bf52f6344b2b03415ce361e0203 /framework/Web/UI | |
parent | 7fee4f81fc62253d49b36cdf79b6a1ff97184742 (diff) |
committed patch for #410
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 0096e169..c43b7181 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -208,43 +208,8 @@ class TClientScriptManager extends TApplicationComponent */ public function getScriptUrls() { - $scripts = array(); - - $packages=array_keys($this->_registeredPradoScripts); - $base = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::SCRIPT_PATH; - list($path,$baseUrl)=$this->getPackagePathUrl($base); - $isDebug=$this->getApplication()->getMode()===TApplicationMode::Debug; - foreach ($packages as $p) - { - foreach (self::$_pradoScripts[$p] as $dep) - { - foreach (self::$_pradoPackages[$dep] as $script) - { - if($isDebug) - { - if (!in_array($url=$baseUrl.'/'.$script,$scripts)) - $scripts[]=$url; - } else { - if (!in_array($url=$baseUrl.'/min/'.$script,$scripts)) - { - 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); - } - $scripts[]=$url; - } - } - } - } - } - - $scripts = array_merge($scripts, array_values($this->_headScriptFiles)); + $scripts = array_values($this->_headScriptFiles); $scripts = array_merge($scripts, array_values($this->_scriptFiles)); - $scripts = array_unique($scripts); return $scripts; @@ -652,7 +617,7 @@ class TClientScriptManager extends TApplicationComponent */ public function renderHeadScriptFiles($writer) { - $writer->write(TJavaScript::renderScriptFiles($this->_headScriptFiles)); + $this->renderScriptFiles($writer,$this->_headScriptFiles); } /** @@ -665,25 +630,44 @@ class TClientScriptManager extends TApplicationComponent public function renderScriptFilesBegin($writer) { - $this->renderScriptFilesInt($writer); + $this->renderAllPendingScriptFiles($writer); } public function renderScriptFilesEnd($writer) { - $this->renderScriptFilesInt($writer); + $this->renderAllPendingScriptFiles($writer); + } + + public function markScriptFileAsRendered($url) + { + $this->_renderedScriptFiles[$url] = $url; + $params=func_get_args(); + $this->_page->registerCachingAction('Page.ClientScript','markScriptFileAsRendered',$params); + } + + protected function renderScriptFiles($writer, Array $scripts) + { + foreach($scripts as $script) + { + $writer->write(TJavaScript::renderScriptFile($script)); + $this->markScriptFileAsRendered($script); + } + } + + protected function getRenderedScriptFiles() + { + return $this->_renderedScriptFiles; } /** * @param THtmlWriter writer for the rendering purpose */ - public function renderScriptFilesInt($writer) + public function renderAllPendingScriptFiles($writer) { if(!empty($this->_scriptFiles)) { - $addedScripts = array_diff($this->_scriptFiles,$this->_renderedScriptFiles); - if (count($addedScripts)>0) - $writer->write(TJavaScript::renderScriptFiles($addedScripts)); - $this->_renderedScriptFiles = $this->_scriptFiles; + $addedScripts = array_diff($this->_scriptFiles,$this->getRenderedScriptFiles()); + $this->renderScriptFiles($writer,$addedScripts); } } @@ -721,7 +705,7 @@ class TClientScriptManager extends TApplicationComponent public function flushScriptFiles($writer, $control=null) { $this->_page->ensureRenderInForm($control); - $this->renderScriptFilesInt($writer,false); + $this->renderAllPendingScriptFiles($writer); } /** |