Completed
Push — master ( 7e2555...471b5b )
by Fabio
18:22
created

TStyleSheet::setStyleSheetUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * TStyleSheet class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
 * @link https://github.com/pradosoft/prado
7
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
8
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
 * @package System.Web.UI.WebControls
10
 */
11
12
/**
13
 * TStyleSheet class.
14
 *
15
 * TStyleSheet represents the link to a stylesheet file and/or a piece of
16
 * stylesheet code. To specify the link to a CSS file, set {@link setStyleSheetUrl
17
 * StyleSheetUrl}.
18
 * Since Prado 3.3.1, it' possible to import css libraries bundled with
19
 * Prado from template via the {@link setPradoStyles PradoStyles} property.
20
 * Multiple Prado libraries can be specified using comma delimited string of the
21
 * css library to include on the page. For example,
22
 *
23
 * <code>
24
 * <com:TStyleSheet PradoStyles="bootstrap, jquery.ui.progressbar" />
25
 * </code>
26
 *
27
 * The child rendering result of TStyleSheet is treated as CSS code and
28
 * is rendered within an appropriate style HTML element.
29
 * Therefore, if the child content is not empty, you should place the TStyleSheet
30
 * control in the head section of your page to conform to the HTML standard.
31
 * If only CSS file URL is specified, you may place the control anywhere on your page
32
 * and the style element will be rendered in the right position.
33
 *
34
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
35
 * @version : $  Tue Jul  4 04:38:16 EST 2006 $
36
 * @package System.Web.UI.WebControls
37
 * @since 3.0.2
38
 */
39
class TStyleSheet extends TControl
40
{
41
	/**
42
	 * @return string comma delimited list of css libraries to include
43
	 * on the page.
44
	 * @since 3.3.1
45
	 */
46
	public function getPradoStyles()
47
	{
48
		return $this->getViewState('PradoStyles', '');
49
	}
50
51
	/**
52
	 * Include css library to the current page. The current supported
53
	 * libraries are: "jquery-ui", "bootstrap" and all the split
54
	 * jquery.ui.componentname libraries. 
55
	 *
56
	 * @param string comma delimited list of css libraries to include.
57
	 * @since 3.3.1
58
	 */
59
	public function setPradoStyles($value)
60
	{
61
		$this->setViewState('PradoStyles', $value, '');
62
	}
63
64
	/**
65
	 * @param string URL to the stylesheet file
66
	 */
67
	public function setStyleSheetUrl($value)
68
	{
69
		$this->setViewState('StyleSheetUrl', $value);
70
	}
71
72
	/**
73
	 * @return string URL to the stylesheet file
74
	 */
75
	public function getStyleSheetUrl()
76
	{
77
		return $this->getViewState('StyleSheetUrl', '');
78
	}
79
80
	/**
81
	 * @return string media type of the CSS (such as 'print', 'screen', etc.). Defaults to empty, meaning the CSS applies to all media types.
82
	 */
83
	public function getMediaType()
84
	{
85
		return $this->getViewState('MediaType','');
86
	}
87
88
	/**
89
	 * @param string media type of the CSS (such as 'print', 'screen', etc.). If empty, it means the CSS applies to all media types.
90
	 */
91
	public function setMediaType($value)
92
	{
93
		$this->setViewState('MediaType',$value,'');
94
	}
95
96
	/**
97
	 * Registers the stylesheet file and content to be rendered.
98
	 * This method overrides the parent implementation and is invoked right before rendering.
99
	 * @param mixed event parameter
100
	 */
101
	public function onPreRender($param)
102
	{
103
		$cs = $this->getPage()->getClientScript();
104
105
		$styles = preg_split('/,|\s+/', $this->getPradoStyles());
106
		foreach($styles as $style)
107
		{
108
			if(($style = trim($style))!=='')
109
				$cs->registerPradoStyle($style);
110
		}
111
112
		if(($url=$this->getStyleSheetUrl())!=='')
113
			$cs->registerStyleSheetFile($url,$url,$this->getMediaType());
114
	}
115
116
	/**
117
	 * Renders the control.
118
	 * This method overrides the parent implementation and renders nothing.
119
	 * @param ITextWriter writer
120
	 */
121
	public function render($writer)
122
	{
123
		if($this->getHasControls())
124
		{
125
			$writer->write("<style type=\"text/css\">\n/*<![CDATA[*/\n");
126
			$this->renderChildren($writer);
127
			$writer->write("\n/*]]>*/\n</style>\n");
128
		}
129
	}
130
}
131
132