summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TClientScriptManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/TClientScriptManager.php')
-rw-r--r--framework/Web/UI/TClientScriptManager.php82
1 files changed, 81 insertions, 1 deletions
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 88e7bb62..c2e73b63 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -31,6 +31,10 @@ class TClientScriptManager extends TApplicationComponent
*/
const PACKAGES_FILE='Web/Javascripts/packages.php';
/**
+ * file containing css packages and their cross dependencies
+ */
+ const CSS_PACKAGES_FILE='Web/Javascripts/css-packages.php';
+ /**
* @var TPage page who owns this manager
*/
private $_page;
@@ -80,12 +84,27 @@ class TClientScriptManager extends TApplicationComponent
* @var array
*/
private static $_pradoPackages;
+ /**
+ * @var array registered PRADO style libraries
+ */
+ private $_registeredPradoStyles=array();
+ /**
+ * Client-side style library dependencies, loads from PACKAGES_FILE;
+ * @var array
+ */
+ private static $_pradoStyles;
+ /**
+ * Client-side style library packages, loads from CSS_PACKAGES_FILE;
+ * @var array
+ */
+ private static $_pradoStylePackages;
private $_renderedHiddenFields;
private $_renderedScriptFiles=array();
private $_expandedPradoScripts;
+ private $_expandedPradoStyles;
/**
* Constructor.
@@ -214,7 +233,7 @@ class TClientScriptManager extends TApplicationComponent
}
/**
- * @param string javascript package path.
+ * @param string javascript or css package path.
* @return array tuple($path,$url).
*/
protected function getPackagePathUrl($base)
@@ -348,6 +367,67 @@ class TClientScriptManager extends TApplicationComponent
}
/**
+ * Registers Prado style by library name. See "Web/Javascripts/packages.php"
+ * for library names.
+ * @param string style library name.
+ */
+ public function registerPradoStyle($name)
+ {
+ $this->registerPradoStyleInternal($name);
+ $params=func_get_args();
+ $this->_page->registerCachingAction('Page.ClientScript','registerPradoStyle',$params);
+ }
+
+ /**
+ * Registers a Prado style library to be loaded.
+ */
+ protected function registerPradoStyleInternal($name)
+ {
+ // $this->checkIfNotInRender();
+ if(!isset($this->_registeredPradoStyles[$name]))
+ {
+ $base = $this->getPradoScriptAssetUrl();
+
+ if(self::$_pradoStyles === null)
+ {
+ $packageFile = Prado::getFrameworkPath().DIRECTORY_SEPARATOR.self::CSS_PACKAGES_FILE;
+ list($packages,$deps)= include($packageFile);
+ self::$_pradoStyles = $deps;
+ self::$_pradoStylePackages = $packages;
+ }
+
+ if (isset(self::$_pradoStyles[$name]))
+ $this->_registeredPradoStyles[$name]=true;
+ else
+ throw new TInvalidOperationException('csmanager_pradostyle_invalid',$name);
+
+ if(($packages=array_keys($this->_registeredPradoStyles))!==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)
+ {
+ foreach (self::$_pradoStyles[$p] as $dep)
+ {
+ foreach (self::$_pradoStylePackages[$dep] as $style)
+ if (!isset($this->_expandedPradoStyles[$style]))
+ {
+ $this->_expandedPradoStyles[$style] = true;
+ // TODO minify css?
+ if (!in_array($url=$baseUrl.'/'.$style,$packagesUrl))
+ $packagesUrl[]=$url;
+ }
+ }
+ }
+ foreach($packagesUrl as $url)
+ $this->registerStyleSheetFile($url,$url);
+ }
+ }
+ }
+
+ /**
* Registers a CSS file to be rendered in the page head
*
* The CSS files in themes are registered in {@link OnPreRenderComplete onPreRenderComplete} if you want to override