summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TStyleSheet.php
blob: 5b4cc944cfd15e16f4f1c3263eaa6a94b35f4d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
	}
}
?>