diff --git a/CHANGELOG b/CHANGELOG index 8fadb110a..ba7c91203 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,8 @@ Version 1.0 to be released - Refactored UserIdentity generated by yiic webapp (Qiang) - Refactored CLinkPager (Qiang) - Refactored CFilter (Qiang) +- Removed CClientScript::registerBodyScript and CClientScript::registerBodyScriptFile; + Added a position parameter to CClientScript::registerScript and CClientScript::registerScriptFile (Qiang) - Fixed a bug in CNumberValidator about checking upper limit (Qiang) - Fixed a bug in CHtml::dropDownList() which doesn't render the 'name' attribute (Qiang) diff --git a/UPGRADE b/UPGRADE index d4069b38b..aa77df70c 100644 --- a/UPGRADE +++ b/UPGRADE @@ -11,8 +11,11 @@ for both A and B. Upgrading from v1.0rc --------------------- -- CLinkPager is changed significantly in appearance and the generated HTML code. +- CLinkPager is changed significantly in both the appearance and the generated HTML code. - CController::clientScript is removed. Please use Yii::app()->clientScript instead. +- CClientScript is changed. The methods registerBodyScript() and + registerBodyScriptFile() are removed. Please use registerScript() and + registerScriptFile() with appropriate position parameter. Upgrading from v1.0b diff --git a/framework/web/CClientScript.php b/framework/web/CClientScript.php index 6ea856abe..b6b44e77b 100644 --- a/framework/web/CClientScript.php +++ b/framework/web/CClientScript.php @@ -18,6 +18,27 @@ */ class CClientScript extends CApplicationComponent { + /** + * The script is rendered in the head section. + */ + const POS_HEAD=0; + /** + * The script is rendered at the beginning of the body section. + */ + const POS_BEGIN=1; + /** + * The script is rendered at the end of the body section. + */ + const POS_END=2; + /** + * The script is rendered inside window onload function. + */ + const POS_LOAD=3; + /** + * The body script is rendered inside a jQuery ready function. + */ + const POS_READY=4; + /** * @var boolean whether JavaScript should be enabled. Defaults to true. */ @@ -32,9 +53,6 @@ class CClientScript extends CApplicationComponent private $_css=array(); private $_scriptFiles=array(); private $_scripts=array(); - private $_bodyScriptFiles=array(); - private $_bodyScripts=array(); - /** * Cleans all registered scripts. @@ -47,8 +65,6 @@ class CClientScript extends CApplicationComponent $this->_css=array(); $this->_scriptFiles=array(); $this->_scripts=array(); - $this->_bodyScriptFiles=array(); - $this->_bodyScripts=array(); Yii::app()->getController()->recordCachingAction('clientScript','reset',array()); } @@ -59,19 +75,31 @@ class CClientScript extends CApplicationComponent * rendering content. CClientScript thus gets a chance to insert script tags * at head and body sections in the HTML output. * @param string the existing output that needs to be inserted with script tags - * @return string the modified output */ - public function render($output) + public function render(&$output) { if(!$this->_hasScripts) - return $output; + return; + $this->renderHead($output); + if($this->enableJavaScript) + { + $this->renderBodyBegin($output); + $this->renderBodyEnd($output); + } + } + + /** + * Inserts the scripts in the head section. + * @param string the output to be inserted with scripts. + */ + protected function renderHead(&$output) + { $html=''; - $html2=''; foreach($this->_cssFiles as $url=>$media) $html.=CHtml::cssFile($url,$media)."\n"; foreach($this->_css as $css) - $html.=CHtml::cssFile($css[0],$css[1])."\n"; + $html.=CHtml::css($css[0],$css[1])."\n"; if($this->enableJavaScript) { foreach($this->_coreScripts as $name) @@ -80,38 +108,80 @@ class CClientScript extends CApplicationComponent $html.=$this->renderCoreScript($name); } - foreach($this->_scriptFiles as $scriptFile) - $html.=CHtml::scriptFile($scriptFile)."\n"; + if(isset($this->_scriptFiles[self::POS_HEAD])) + { + foreach($this->_scriptFiles[self::POS_HEAD] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } - if(!empty($this->_scripts)) - $html.=CHtml::script(implode("\n",$this->_scripts))."\n"; - - foreach($this->_bodyScriptFiles as $scriptFile) - $html2.=CHtml::scriptFile($scriptFile)."\n"; - if(!empty($this->_bodyScripts)) - $html2.=CHtml::script(implode("\n",$this->_bodyScripts))."\n"; + if(isset($this->_scripts[self::POS_HEAD])) + $html.=CHtml::script(implode("\n",$this->_scripts[self::POS_HEAD]))."\n"; } if($html!=='') { - $output=preg_replace('/(.*?)()/is','$1'.$html.'$2',$output,1,$count); - if(!$count) - $output=preg_replace('/(.*?)(<\\/head\s*>)/is','$1'.$html.'$2',$output,1,$count); + $output=preg_replace('/(]*>|<\\/head\s*>)/is',$html.'$1',$output,1,$count); if(!$count) $output=$html.$output; } - - if($html2!=='') - { - $output=preg_replace('/(<\\/body\s*>.*?<\/html\s*>)/is',$html2.'$1',$output,1,$count); - if(!$count) - $output.=$html2; - } - - return $output; } /** + * Inserts the scripts at the beginning of the body section. + * @param string the output to be inserted with scripts. + */ + protected function renderBodyBegin(&$output) + { + $html=''; + if(isset($this->_scriptFiles[self::POS_BEGIN])) + { + foreach($this->_scriptFiles[self::POS_BEGIN] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } + if(isset($this->_scripts[self::POS_BEGIN])) + $html.=CHtml::script(implode("\n",$this->_scripts[self::POS_BEGIN]))."\n"; + + if($html!=='') + { + $output=preg_replace('/(]*>)/is','$1'.$html,$output,1,$count); + if(!$count) + $output=$html.$output; + } + } + + /** + * Inserts the scripts at the end of the body section. + * @param string the output to be inserted with scripts. + */ + protected function renderBodyEnd(&$output) + { + $html=''; + if(isset($this->_scriptFiles[self::POS_END])) + { + foreach($this->_scriptFiles[self::POS_END] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } + + $scripts=isset($this->_scripts[self::POS_END]) ? $this->_scripts[self::POS_END] : array(); + if(isset($this->_scripts[self::POS_READY])) + $scripts[]="jQuery(document).ready(function() {\n".implode("\n",$this->_scripts[self::POS_READY])."\n});"; + if(isset($this->_scripts[self::POS_LOAD])) + $scripts[]="window.onload=function() {\n".implode("\n",$this->_scripts[self::POS_LOAD])."\n};"; + if(!empty($scripts)) + $html.=CHtml::script(implode("\n",$scripts))."\n"; + + if($html!=='') + { + $output=preg_replace('/(<\\/body\s*>)/is',$html.'$1',$output,1,$count); + if(!$count) + $output=$output.$html; + } + } + + /** + * Returns the base URL of all core javascript files. + * If the base URL is not explicitly set, this method will publish the whole directory + * 'framework/web/js/source' and return the corresponding URL. * @return string the base URL of all core javascript files */ public function getCoreScriptUrl() @@ -214,55 +284,46 @@ class CClientScript extends CApplicationComponent } /** - * Registers a javascript file that should be inserted in the head section + * Registers a javascript file. * @param string URL of the javascript file + * @param integer the position of the JavaScript code. Valid values include the following: + *
    + *
  • CClientScript::POS_HEAD : the script is inserted in the head section.
  • + *
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • + *
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • + *
*/ - public function registerScriptFile($url) + public function registerScriptFile($url,$position=self::POS_HEAD) { $this->_hasScripts=true; - $this->_scriptFiles[$url]=$url; + $this->_scriptFiles[$position][$url]=$url; $params=func_get_args(); Yii::app()->getController()->recordCachingAction('clientScript','registerScriptFile',$params); } /** - * Registers a piece of javascript code that should be inserted in the head section + * Registers a piece of javascript code. * @param string ID that uniquely identifies this piece of JavaScript code * @param string the javascript code + * @param integer the position of the JavaScript code. Valid values include the following: + *
    + *
  • CClientScript::POS_HEAD : the script is inserted in the head section.
  • + *
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • + *
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • + *
  • CClientScript::POS_LOAD : the script is inserted in the window.onload() function.
  • + *
  • CClientScript::POS_READY : the script is inserted in the jQuery's ready function.
  • + *
*/ - public function registerScript($id,$script) + public function registerScript($id,$script,$position=self::POS_READY) { $this->_hasScripts=true; - $this->_scripts[$id]=$script; + $this->_scripts[$position][$id]=$script; + if($position===self::POS_READY) + $this->registerCoreScript('jquery'); $params=func_get_args(); Yii::app()->getController()->recordCachingAction('clientScript','registerScript',$params); } - /** - * Registers a javascript file that should be inserted in the body section - * @param string URL of the javascript file - */ - public function registerBodyScriptFile($url) - { - $this->_hasScripts=true; - $this->_bodyScriptFiles[$url]=$url; - $params=func_get_args(); - Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScriptFile',$params); - } - - /** - * Registers a piece of javascript code that should be inserted in the body section - * @param string ID that uniquely identifies this piece of JavaScript code - * @param string the javascript code - */ - public function registerBodyScript($id,$script) - { - $this->_hasScripts=true; - $this->_bodyScripts[$id]=$script; - $params=func_get_args(); - Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScript',$params); - } - /** * Checks whether the CSS file has been registered. * @param string URL of the CSS file @@ -284,42 +345,36 @@ class CClientScript extends CApplicationComponent } /** - * Checks whether the CSS code has been registered in the head section. + * Checks whether the JavaScript file has been registered. * @param string URL of the javascript file + * @param integer the position of the JavaScript code. Valid values include the following: + *
    + *
  • CClientScript::POS_HEAD : the script is inserted in the head section.
  • + *
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • + *
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • + *
* @return boolean whether the javascript file is already registered */ - public function isScriptFileRegistered($url) + public function isScriptFileRegistered($url,$position=self::POS_HEAD) { - return isset($this->_scriptFiles[$url]); + return isset($this->_bodyScriptFiles[$position][$url]); } /** - * Checks whether the JavaScript code has been registered in the head section. + * Checks whether the JavaScript code has been registered. * @param string ID that uniquely identifies the JavaScript code + * @param integer the position of the JavaScript code. Valid values include the following: + *
    + *
  • CClientScript::POS_HEAD : the script is inserted in the head section.
  • + *
  • CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
  • + *
  • CClientScript::POS_END : the script is inserted at the end of the body section.
  • + *
  • CClientScript::POS_LOAD : the script is inserted in the window.onload() function.
  • + *
  • CClientScript::POS_READY : the script is inserted in the jQuery's ready function.
  • + *
* @return boolean whether the javascript code is already registered */ - public function isScriptRegistered($id) + public function isScriptRegistered($id,$position=self::POS_READY) { - return isset($this->_scripts[$id]); - } - - /** - * Checks whether the JavaScript file has been registered in the body section. - * @param string URL of the javascript file - * @return boolean whether the javascript file is already registered - */ - public function isBodyScriptFileRegistered($url) - { - return isset($this->_bodyScriptFiles[$url]); - } - - /** - * Checks whether the JavaScript code has been registered in the body section. - * @param string ID that uniquely identifies the JavaScript code - * @return boolean whether the javascript code is already registered - */ - public function isBodyScriptRegistered($id) - { - return isset($this->_bodyScripts[$id]); + return isset($this->_scripts[$position][$id]); } } diff --git a/framework/web/CController.php b/framework/web/CController.php index fbac04fec..4b7245e70 100644 --- a/framework/web/CController.php +++ b/framework/web/CController.php @@ -226,7 +226,7 @@ class CController extends CBaseController */ public function processOutput($output) { - $output=Yii::app()->getClientScript()->render($output); + Yii::app()->getClientScript()->render($output); if($this->_dynamicOutput) { diff --git a/framework/web/helpers/CHtml.php b/framework/web/helpers/CHtml.php index c1355ba2a..4ba716afb 100644 --- a/framework/web/helpers/CHtml.php +++ b/framework/web/helpers/CHtml.php @@ -1210,7 +1210,7 @@ class CHtml unset($htmlOptions['confirm']); } - $cs->registerBodyScript('Yii.CHtml.#'.$id,"jQuery('#$id').$event(function(){{$handler}});"); + $cs->registerScript('Yii.CHtml.#'.$id,"jQuery('#$id').$event(function(){{$handler}});"); } } diff --git a/framework/web/widgets/CAutoComplete.php b/framework/web/widgets/CAutoComplete.php index 7f61ef593..9d8e72407 100644 --- a/framework/web/widgets/CAutoComplete.php +++ b/framework/web/widgets/CAutoComplete.php @@ -203,7 +203,7 @@ class CAutoComplete extends CInputWidget $url=CHtml::normalizeUrl($this->url); $data='"'.$url.'"'; } - $cs->registerBodyScript('Yii.CAutoComplete#'.$id,"jQuery(\"#{$id}\").autocomplete($data,{$options}){$this->methodChain};"); + $cs->registerScript('Yii.CAutoComplete#'.$id,"jQuery(\"#{$id}\").autocomplete($data,{$options}){$this->methodChain};"); if($this->cssFile===null) $cs->registerCssFile($cs->getCoreScriptUrl().'/autocomplete/jquery.autocomplete.css'); else if($this->cssFile!==false) diff --git a/framework/web/widgets/CMaskedTextField.php b/framework/web/widgets/CMaskedTextField.php index eff1fb6a7..a13c9c675 100644 --- a/framework/web/widgets/CMaskedTextField.php +++ b/framework/web/widgets/CMaskedTextField.php @@ -68,7 +68,7 @@ class CMaskedTextField extends CInputWidget $cs=Yii::app()->getClientScript(); $cs->registerCoreScript('maskedinput'); - $cs->registerBodyScript('Yii.CMaskedTextField#'.$id,$js); + $cs->registerScript('Yii.CMaskedTextField#'.$id,$js); if($this->hasModel()) echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions); diff --git a/framework/web/widgets/CMultiFileUpload.php b/framework/web/widgets/CMultiFileUpload.php index 7e37a7f7a..ae5cd7fba 100644 --- a/framework/web/widgets/CMultiFileUpload.php +++ b/framework/web/widgets/CMultiFileUpload.php @@ -98,7 +98,7 @@ class CMultiFileUpload extends CWidget $cs=Yii::app()->getClientScript(); $cs->registerCoreScript('multifile'); - $cs->registerBodyScript('Yii.CMultiFileUpload#'.$id,"jQuery(\"#{$id}\").MultiFile({$options});"); + $cs->registerScript('Yii.CMultiFileUpload#'.$id,"jQuery(\"#{$id}\").MultiFile({$options});"); echo CHtml::fileField($name,'',$this->htmlOptions); } diff --git a/framework/web/widgets/CStarRating.php b/framework/web/widgets/CStarRating.php index fdc659dbf..ebb47826d 100644 --- a/framework/web/widgets/CStarRating.php +++ b/framework/web/widgets/CStarRating.php @@ -122,7 +122,7 @@ class CStarRating extends CInputWidget $js="jQuery('#{$id} > input').rating({$jsOptions});"; $cs=Yii::app()->getClientScript(); $cs->registerCoreScript('rating'); - $cs->registerBodyScript('Yii.CStarRating#'.$id,$js); + $cs->registerScript('Yii.CStarRating#'.$id,$js); if($this->cssFile===null) $cs->registerCssFile($cs->getCoreScriptUrl().'/rating/jquery.rating.css'); else if($this->cssFile!==false) diff --git a/framework/web/widgets/CTabView.php b/framework/web/widgets/CTabView.php index 02affd292..1f5e8591c 100644 --- a/framework/web/widgets/CTabView.php +++ b/framework/web/widgets/CTabView.php @@ -151,7 +151,7 @@ class CTabView extends CWidget else if($this->cssFile!==false) $cs->registerCssFile($this->cssFile); $id=$this->getId(); - $cs->registerBodyScript('Yii.CTabView#'.$id,"jQuery(\"#{$id}\").yiitab();"); + $cs->registerScript('Yii.CTabView#'.$id,"jQuery(\"#{$id}\").yiitab();"); } /** diff --git a/framework/web/widgets/CTreeView.php b/framework/web/widgets/CTreeView.php index c20e924de..4619efdc2 100644 --- a/framework/web/widgets/CTreeView.php +++ b/framework/web/widgets/CTreeView.php @@ -142,7 +142,7 @@ class CTreeView extends CWidget $cs->registerCoreScript('treeview'); $options=$this->getClientOptions(); $options=$options===array()?'{}' : CJavaScript::encode($options); - $cs->registerBodyScript('Yii.CTreeView#'.$id,"jQuery(\"#{$id}\").treeview($options);"); + $cs->registerScript('Yii.CTreeView#'.$id,"jQuery(\"#{$id}\").treeview($options);"); if($this->cssFile===null) $cs->registerCssFile($cs->getCoreScriptUrl().'/treeview/jquery.treeview.css'); else if($this->cssFile!==false) diff --git a/framework/yiilite.php b/framework/yiilite.php index 56ff813cc..91f71d7d3 100644 --- a/framework/yiilite.php +++ b/framework/yiilite.php @@ -2248,7 +2248,7 @@ class CController extends CBaseController } public function processOutput($output) { - $output=Yii::app()->getClientScript()->render($output); + Yii::app()->getClientScript()->render($output); if($this->_dynamicOutput) { $output=preg_replace_callback('/<###dynamic-(\d+)###>/',array($this,'replaceDynamicOutput'),$output); @@ -3555,7 +3555,7 @@ class CHtml $handler="return $confirm;"; unset($htmlOptions['confirm']); } - $cs->registerBodyScript('Yii.CHtml.#'.$id,"jQuery('#$id').$event(function(){{$handler}});"); + $cs->registerScript('Yii.CHtml.#'.$id,"jQuery('#$id').$event(function(){{$handler}});"); } } protected static function resolveNameID($model,&$attribute,&$htmlOptions) @@ -3643,6 +3643,11 @@ class CWidget extends CBaseController } class CClientScript extends CApplicationComponent { + const POS_HEAD=0; + const POS_BEGIN=1; + const POS_END=2; + const POS_LOAD=3; + const POS_READY=4; public $enableJavaScript=true; private $_hasScripts=false; private $_packages; @@ -3653,8 +3658,6 @@ class CClientScript extends CApplicationComponent private $_css=array(); private $_scriptFiles=array(); private $_scripts=array(); - private $_bodyScriptFiles=array(); - private $_bodyScripts=array(); public function reset() { $this->_hasScripts=false; @@ -3663,20 +3666,26 @@ class CClientScript extends CApplicationComponent $this->_css=array(); $this->_scriptFiles=array(); $this->_scripts=array(); - $this->_bodyScriptFiles=array(); - $this->_bodyScripts=array(); Yii::app()->getController()->recordCachingAction('clientScript','reset',array()); } - public function render($output) + public function render(&$output) { if(!$this->_hasScripts) - return $output; + return; + $this->renderHead($output); + if($this->enableJavaScript) + { + $this->renderBodyBegin($output); + $this->renderBodyEnd($output); + } + } + protected function renderHead(&$output) + { $html=''; - $html2=''; foreach($this->_cssFiles as $url=>$media) $html.=CHtml::cssFile($url,$media)."\n"; foreach($this->_css as $css) - $html.=CHtml::cssFile($css[0],$css[1])."\n"; + $html.=CHtml::css($css[0],$css[1])."\n"; if($this->enableJavaScript) { foreach($this->_coreScripts as $name) @@ -3684,30 +3693,59 @@ class CClientScript extends CApplicationComponent if(is_string($name)) $html.=$this->renderCoreScript($name); } - foreach($this->_scriptFiles as $scriptFile) - $html.=CHtml::scriptFile($scriptFile)."\n"; - if(!empty($this->_scripts)) - $html.=CHtml::script(implode("\n",$this->_scripts))."\n"; - foreach($this->_bodyScriptFiles as $scriptFile) - $html2.=CHtml::scriptFile($scriptFile)."\n"; - if(!empty($this->_bodyScripts)) - $html2.=CHtml::script(implode("\n",$this->_bodyScripts))."\n"; + if(isset($this->_scriptFiles[self::POS_HEAD])) + { + foreach($this->_scriptFiles[self::POS_HEAD] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } + if(isset($this->_scripts[self::POS_HEAD])) + $html.=CHtml::script(implode("\n",$this->_scripts[self::POS_HEAD]))."\n"; } if($html!=='') { - $output=preg_replace('/(.*?)()/is','$1'.$html.'$2',$output,1,$count); - if(!$count) - $output=preg_replace('/(.*?)(<\\/head\s*>)/is','$1'.$html.'$2',$output,1,$count); + $output=preg_replace('/(]*>|<\\/head\s*>)/is',$html.'$1',$output,1,$count); if(!$count) $output=$html.$output; } - if($html2!=='') + } + protected function renderBodyBegin(&$output) + { + $html=''; + if(isset($this->_scriptFiles[self::POS_BEGIN])) { - $output=preg_replace('/(<\\/body\s*>.*?<\/html\s*>)/is',$html2.'$1',$output,1,$count); - if(!$count) - $output.=$html2; + foreach($this->_scriptFiles[self::POS_BEGIN] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } + if(isset($this->_scripts[self::POS_BEGIN])) + $html.=CHtml::script(implode("\n",$this->_scripts[self::POS_BEGIN]))."\n"; + if($html!=='') + { + $output=preg_replace('/(]*>)/is','$1'.$html,$output,1,$count); + if(!$count) + $output=$html.$output; + } + } + protected function renderBodyEnd(&$output) + { + $html=''; + if(isset($this->_scriptFiles[self::POS_END])) + { + foreach($this->_scriptFiles[self::POS_END] as $scriptFile) + $html.=CHtml::scriptFile($scriptFile)."\n"; + } + $scripts=isset($this->_scripts[self::POS_END]) ? $this->_scripts[self::POS_END] : array(); + if(isset($this->_scripts[self::POS_READY])) + $scripts[]="jQuery(document).ready(function() {\n".implode("\n",$this->_scripts[self::POS_READY])."\n});"; + if(isset($this->_scripts[self::POS_LOAD])) + $scripts[]="window.onload=function() {\n".implode("\n",$this->_scripts[self::POS_LOAD])."\n};"; + if(!empty($scripts)) + $html.=CHtml::script(implode("\n",$scripts))."\n"; + if($html!=='') + { + $output=preg_replace('/(<\\/body\s*>)/is',$html.'$1',$output,1,$count); + if(!$count) + $output=$output.$html; } - return $output; } public function getCoreScriptUrl() { @@ -3771,34 +3809,22 @@ class CClientScript extends CApplicationComponent $params=func_get_args(); Yii::app()->getController()->recordCachingAction('clientScript','registerCss',$params); } - public function registerScriptFile($url) + public function registerScriptFile($url,$position=self::POS_HEAD) { $this->_hasScripts=true; - $this->_scriptFiles[$url]=$url; + $this->_scriptFiles[$position][$url]=$url; $params=func_get_args(); Yii::app()->getController()->recordCachingAction('clientScript','registerScriptFile',$params); } - public function registerScript($id,$script) + public function registerScript($id,$script,$position=self::POS_READY) { $this->_hasScripts=true; - $this->_scripts[$id]=$script; + $this->_scripts[$position][$id]=$script; + if($position===self::POS_READY) + $this->registerCoreScript('jquery'); $params=func_get_args(); Yii::app()->getController()->recordCachingAction('clientScript','registerScript',$params); } - public function registerBodyScriptFile($url) - { - $this->_hasScripts=true; - $this->_bodyScriptFiles[$url]=$url; - $params=func_get_args(); - Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScriptFile',$params); - } - public function registerBodyScript($id,$script) - { - $this->_hasScripts=true; - $this->_bodyScripts[$id]=$script; - $params=func_get_args(); - Yii::app()->getController()->recordCachingAction('clientScript','registerBodyScript',$params); - } public function isCssFileRegistered($url) { return isset($this->_cssFiles[$url]); @@ -3807,21 +3833,13 @@ class CClientScript extends CApplicationComponent { return isset($this->_css[$id]); } - public function isScriptFileRegistered($url) + public function isScriptFileRegistered($url,$position=self::POS_HEAD) { - return isset($this->_scriptFiles[$url]); + return isset($this->_bodyScriptFiles[$position][$url]); } - public function isScriptRegistered($id) + public function isScriptRegistered($id,$position=self::POS_READY) { - return isset($this->_scripts[$id]); - } - public function isBodyScriptFileRegistered($url) - { - return isset($this->_bodyScriptFiles[$url]); - } - public function isBodyScriptRegistered($id) - { - return isset($this->_bodyScripts[$id]); + return isset($this->_scripts[$position][$id]); } } class CList extends CComponent implements IteratorAggregate,ArrayAccess,Countable