[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TClientScript class file 4 * 5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TClientScript.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * TClientScript class 15 * 16 * Allows importing of Prado Client Scripts from template via the 17 * {@link setPradoScripts PradoScripts} property. Multiple Prado 18 * client-scripts can be specified using comma delimited string of the 19 * javascript library to include on the page. For example, 20 * 21 * <code> 22 * <com:TClientScript PradoScripts="effects, rico" /> 23 * </code> 24 * 25 * Custom javascript files can be register using the {@link setScriptUrl ScriptUrl} 26 * property. 27 * <code> 28 * <com:TClientScript ScriptUrl=<%~ test.js %> /> 29 * </code> 30 * 31 * Contents within TClientScript will be treated as javascript code and will be 32 * rendered in place. 33 * 34 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 35 * @version $Id: TClientScript.php 1397 2006-09-07 07:55:53Z wei $ 36 * @package System.Web.UI.WebControls 37 * @since 3.0 38 */ 39 class TClientScript extends TControl 40 { 41 /** 42 * @return string comma delimited list of javascript libraries to included 43 * on the page. 44 */ 45 public function getPradoScripts() 46 { 47 return $this->getViewState('PradoScripts', ''); 48 } 49 50 /** 51 * Include javascript library to the current page. The current supported 52 * libraries are: "prado", "effects", "ajax", "validator", "logger", 53 * "datepicker", "rico", "colorpicker". Library dependencies are 54 * automatically resolved. 55 * 56 * @param string comma delimited list of javascript libraries to include. 57 */ 58 public function setPradoScripts($value) 59 { 60 $this->setViewState('PradoScripts', $value, ''); 61 } 62 63 /** 64 * @return string custom javascript file url. 65 */ 66 public function getScriptUrl() 67 { 68 return $this->getViewState('ScriptUrl', ''); 69 } 70 71 /** 72 * @param string custom javascript file url. 73 */ 74 public function setScriptUrl($value) 75 { 76 $this->setViewState('ScriptUrl', $value, ''); 77 } 78 79 /** 80 * Calls the client script manager to add each of the requested client 81 * script libraries. 82 * @param mixed event parameter 83 */ 84 public function onPreRender($param) 85 { 86 parent::onPreRender($param); 87 $scripts = preg_split('/,|\s+/', $this->getPradoScripts()); 88 $cs = $this->getPage()->getClientScript(); 89 foreach($scripts as $script) 90 { 91 if(($script = trim($script))!=='') 92 $cs->registerPradoScript($script); 93 } 94 } 95 96 /** 97 * Renders the body content as javascript block. 98 * Overrides parent implementation, parent renderChildren method is called during 99 * {@link registerCustomScript}. 100 * @param THtmlWriter the renderer 101 */ 102 public function render($writer) 103 { 104 $this->renderCustomScriptFile($writer); 105 $this->renderCustomScript($writer); 106 } 107 108 /** 109 * Renders the custom script file. 110 * @param THtmLWriter the renderer 111 */ 112 protected function renderCustomScriptFile($writer) 113 { 114 if(($scriptUrl = $this->getScriptUrl())!=='') 115 $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n"); 116 } 117 118 /** 119 * Registers the body content as javascript. 120 * @param THtmlWriter the renderer 121 */ 122 protected function renderCustomScript($writer) 123 { 124 if($this->getHasControls()) 125 { 126 $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n"); 127 $this->renderChildren($writer); 128 $writer->write("\n/*]]>*/\n</script>\n"); 129 } 130 } 131 } 132 133 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |