summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-08-02 12:06:13 +0000
committerxue <>2006-08-02 12:06:13 +0000
commitdc76ce6c04347a42bdd03b2c6060395d071ddb0e (patch)
tree4329e844da42e72190041f58221793b0fdbbb3ac
parent38fc83fb70a87f0f8a1b4bc0f4753e3063749522 (diff)
Fixed #316.
-rw-r--r--HISTORY1
-rw-r--r--demos/quickstart/protected/pages/Advanced/Themes.page3
-rw-r--r--framework/Web/UI/TClientScriptManager.php17
-rw-r--r--framework/Web/UI/TPage.php21
-rw-r--r--framework/Web/UI/WebControls/TStyleSheet.php18
5 files changed, 53 insertions, 7 deletions
diff --git a/HISTORY b/HISTORY
index 7e28aaad..f90a37a8 100644
--- a/HISTORY
+++ b/HISTORY
@@ -22,6 +22,7 @@ ENH: Ticket#277 - Added TControl.CustomData property (Qiang)
ENH: Ticket#287 - TControl::broadcastEvent() may raise events now (Qiang)
ENH: Ticket#292 - Added THttpRequest::parseUrl() so that it is easier to be extended (Qiang)
ENH: Ticket#309 - Added THttpRequest.UrlParamSeparator property (Qiang)
+ENH: Ticket#316 - Added media type support to CSS files in a theme (Qiang)
NEW: Added TStyleSheet (Wei)
diff --git a/demos/quickstart/protected/pages/Advanced/Themes.page b/demos/quickstart/protected/pages/Advanced/Themes.page
index 5ba0a121..07435928 100644
--- a/demos/quickstart/protected/pages/Advanced/Themes.page
+++ b/demos/quickstart/protected/pages/Advanced/Themes.page
@@ -28,6 +28,9 @@ This will apply the 'Blue' skin to the button. Note, the initial property values
<p>
To use the Javascript files and CSS files contained in a theme, a <tt>THead</tt> control must be placed on the page template. This is because the theme will register those files with the page and <tt>THead</tt> is the right place to load those files.
</p>
+<p>
+It is possible to specify media types of CSS files contained in a theme. By default, a CSS file applies to all media types. If the CSS file is named like <tt>mystyle.print.css</tt>, it will be applied only to <tt>print</tt> media type. As another example, <tt>mystyle.screen.css</tt> applies to <tt>screen</tt> media only, and <tt>mystyle.css</tt> applies to all media types.
+</p>
<h2 id="5905">Theme Storage</h2>
<p>
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 752b61ea..9a83c550 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -215,10 +215,14 @@ class TClientScriptManager extends TApplicationComponent
* Registers a CSS file to be rendered in the page head
* @param string a unique key identifying the file
* @param string URL to the CSS file
+ * @param string media type of the CSS (such as 'print', 'screen', etc.). Defaults to empty, meaning the CSS applies to all media types.
*/
- public function registerStyleSheetFile($key,$url)
+ public function registerStyleSheetFile($key,$url,$media='')
{
- $this->_styleSheetFiles[$key]=$url;
+ if($media==='')
+ $this->_styleSheetFiles[$key]=$url;
+ else
+ $this->_styleSheetFiles[$key]=array($url,$media);
}
/**
@@ -226,7 +230,7 @@ class TClientScriptManager extends TApplicationComponent
* @param string a unique key identifying the CSS block
* @param string CSS block
*/
- public function registerStyleSheet($key,$css)
+ public function registerStyleSheet($key,$css,$media='')
{
$this->_styleSheets[$key]=$css;
}
@@ -373,7 +377,12 @@ class TClientScriptManager extends TApplicationComponent
{
$str='';
foreach($this->_styleSheetFiles as $url)
- $str.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".THttpUtility::htmlEncode($url)."\" />\n";
+ {
+ if(is_array($url))
+ $str.="<link rel=\"stylesheet\" type=\"text/css\" media=\"{$url[1]}\" href=\"".THttpUtility::htmlEncode($url[0])."\" />\n";
+ else
+ $str.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".THttpUtility::htmlEncode($url)."\" />\n";
+ }
$writer->write($str);
}
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 1fa9330c..8c01a501 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -490,20 +490,37 @@ class TPage extends TTemplateControl
if($this->_theme instanceof ITheme)
{
foreach($this->_theme->getStyleSheetFiles() as $url)
- $cs->registerStyleSheetFile($url,$url);
+ $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
foreach($this->_theme->getJavaScriptFiles() as $url)
$cs->registerHeadScriptFile($url,$url);
}
if($this->_styleSheet instanceof ITheme)
{
foreach($this->_styleSheet->getStyleSheetFiles() as $url)
- $cs->registerStyleSheetFile($url,$url);
+ $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url));
foreach($this->_styleSheet->getJavaScriptFiles() as $url)
$cs->registerHeadScriptFile($url,$url);
}
}
/**
+ * Determines the media type of the CSS file.
+ * The media type is determined according to the following file name pattern:
+ * xxx.media-type.extension
+ * For example, 'mystyle.print.css' means its media type is 'print'.
+ * @param string CSS URL
+ * @return string media type of the CSS file
+ */
+ private function getCssMediaType($url)
+ {
+ $segs=explode('.',basename($url));
+ if(isset($segs[2]))
+ return $segs[count($segs)-2];
+ else
+ return '';
+ }
+
+ /**
* Raises OnSaveStateComplete event.
* This method is invoked right after {@link onSaveState OnSaveState} stage.
* You may override this method to provide additional logic after page state is saved.
diff --git a/framework/Web/UI/WebControls/TStyleSheet.php b/framework/Web/UI/WebControls/TStyleSheet.php
index 5925645c..3e172697 100644
--- a/framework/Web/UI/WebControls/TStyleSheet.php
+++ b/framework/Web/UI/WebControls/TStyleSheet.php
@@ -46,6 +46,22 @@ class TStyleSheet extends TControl
}
/**
+ * @return string media type of the CSS (such as 'print', 'screen', etc.). Defaults to empty, meaning the CSS applies to all media types.
+ */
+ public function getMediaType()
+ {
+ return $this->getViewState('MediaType','');
+ }
+
+ /**
+ * @param string media type of the CSS (such as 'print', 'screen', etc.). If empty, it means the CSS applies to all media types.
+ */
+ public function setMediaType($value)
+ {
+ $this->setViewState('MediaType',$value,'');
+ }
+
+ /**
* Registers the stylesheet file and content to be rendered.
* This method overrides the parent implementation and is invoked right before rendering.
* @param mixed event parameter
@@ -53,7 +69,7 @@ class TStyleSheet extends TControl
public function onPreRender($param)
{
if(($url=$this->getStyleSheetUrl())!=='')
- $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url,$this->getMediaType());
}
/**