summaryrefslogtreecommitdiff
path: root/lib/prado/framework/Web/UI/WebControls/TStyleSheet.php
blob: 021b9117d4a36d59ddc878ddcd45b4f77d52c24d (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
 * TStyleSheet class file.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @package System.Web.UI.WebControls
 */

/**
 * TStyleSheet class.
 *
 * TStyleSheet represents the link to a stylesheet file and/or a piece of
 * stylesheet code. To specify the link to a CSS file, set {@link setStyleSheetUrl
 * StyleSheetUrl}.
 * Since Prado 3.3.1, it' possible to import css libraries bundled with
 * Prado from template via the {@link setPradoStyles PradoStyles} property.
 * Multiple Prado libraries can be specified using comma delimited string of the
 * css library to include on the page. For example,
 *
 * <code>
 * <com:TStyleSheet PradoStyles="bootstrap, jquery.ui.progressbar" />
 * </code>
 *
 * The child rendering result of TStyleSheet is treated as CSS code and
 * is rendered within an appropriate style HTML element.
 * Therefore, if the child content is not empty, you should place the TStyleSheet
 * control in the head section of your page to conform to the HTML standard.
 * If only CSS file URL is specified, you may place the control anywhere on your page
 * and the style element will be rendered in the right position.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version : $  Tue Jul  4 04:38:16 EST 2006 $
 * @package System.Web.UI.WebControls
 * @since 3.0.2
 */
class TStyleSheet extends TControl
{
	/**
	 * @return string comma delimited list of css libraries to include
	 * on the page.
	 * @since 3.3.1
	 */
	public function getPradoStyles()
	{
		return $this->getViewState('PradoStyles', '');
	}

	/**
	 * Include css library to the current page. The current supported
	 * libraries are: "jquery-ui", "bootstrap" and all the split
	 * jquery.ui.componentname libraries. 
	 *
	 * @param string comma delimited list of css libraries to include.
	 * @since 3.3.1
	 */
	public function setPradoStyles($value)
	{
		$this->setViewState('PradoStyles', $value, '');
	}

	/**
	 * @param string URL to the stylesheet file
	 */
	public function setStyleSheetUrl($value)
	{
		$this->setViewState('StyleSheetUrl', $value);
	}

	/**
	 * @return string URL to the stylesheet file
	 */
	public function getStyleSheetUrl()
	{
		return $this->getViewState('StyleSheetUrl', '');
	}

	/**
	 * @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
	 */
	public function onPreRender($param)
	{
		$cs = $this->getPage()->getClientScript();

		$styles = preg_split('/,|\s+/', $this->getPradoStyles());
		foreach($styles as $style)
		{
			if(($style = trim($style))!=='')
				$cs->registerPradoStyle($style);
		}

		if(($url=$this->getStyleSheetUrl())!=='')
			$cs->registerStyleSheetFile($url,$url,$this->getMediaType());
	}

	/**
	 * Renders the control.
	 * This method overrides the parent implementation and renders nothing.
	 * @param ITextWriter writer
	 */
	public function render($writer)
	{
		if($this->getHasControls())
		{
			$writer->write("<style type=\"text/css\">\n/*<![CDATA[*/\n");
			$this->renderChildren($writer);
			$writer->write("\n/*]]>*/\n</style>\n");
		}
	}
}