summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TStyleSheet.php
diff options
context:
space:
mode:
authorwei <>2006-07-03 04:12:56 +0000
committerwei <>2006-07-03 04:12:56 +0000
commit674353eec4d0a2ee006302720bf6df07ae3e9852 (patch)
tree41969f2e513b9e7ec957507c5cc45de6e625010c /framework/Web/UI/WebControls/TStyleSheet.php
parentb359ed2bbd48ed4c9000eb507ee2d78aa5130cc0 (diff)
Add TStylesheet and update TClientScript
Diffstat (limited to 'framework/Web/UI/WebControls/TStyleSheet.php')
-rw-r--r--framework/Web/UI/WebControls/TStyleSheet.php75
1 files changed, 75 insertions, 0 deletions
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 @@
+<?php
+
+/**
+ * TStyleSheet class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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