From 674353eec4d0a2ee006302720bf6df07ae3e9852 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 3 Jul 2006 04:12:56 +0000 Subject: Add TStylesheet and update TClientScript --- framework/Web/UI/WebControls/TStyleSheet.php | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 framework/Web/UI/WebControls/TStyleSheet.php (limited to 'framework/Web/UI/WebControls/TStyleSheet.php') diff --git a/framework/Web/UI/WebControls/TStyleSheet.php b/framework/Web/UI/WebControls/TStyleSheet.php new file mode 100644 index 00000000..5b4cc944 --- /dev/null +++ b/framework/Web/UI/WebControls/TStyleSheet.php @@ -0,0 +1,75 @@ + + * @version : $ Tue Jul 4 04:38:16 EST 2006 $ + * @package System.Web.UI.WebControl + * @since 3.0.2 + */ +class TStyleSheet extends TControl +{ + /** + * @param string stylesheet url or asset resource. + */ + public function setStyleUrl($value) + { + $this->setViewState('StyleUrl', $value); + } + + /** + * @return string stylesheet url. + */ + public function getStyleUrl() + { + return $this->getViewState('StyleUrl', ''); + } + + /** + * Registers the stylesheet urls. Calls {@link renderChildren} to capture + * the body content to render the stylesheet in the head. + * @param mixed event parameter + */ + public function onPreRender($param) + { + if($this->getEnabled(true)) + { + $this->registerCustomStyleSheetFile(); + $this->registerCustomStyleSheet(); + } + } + + /** + * Overrides parent implementation, renders nothing. + */ + public function renderChildren($writer) + { + + } + + /** + * Register custom stylesheet file. + */ + protected function registerCustomStyleSheetFile() + { + $cs = $this->getPage()->getClientScript(); + $url = $this->getStyleUrl(); + if(strlen($url) > 0) + $cs->registerStyleSheetFile($url, $url); + } + + /** + * Registers the body content as stylesheet. + */ + protected function registerCustomStyleSheet() + { + $cs = $this->getPage()->getClientScript(); + $textWriter=new TTextWriter; + parent::renderChildren(new THtmlWriter($textWriter)); + $text = $textWriter->flush(); + if(strlen($text)>0) + $cs->registerStyleSheet(sprintf('%08X', crc32($text)), $text); + } +} +?> \ No newline at end of file -- cgit v1.2.3