I dont want to use jQuery on registerScript

Hi,

I want to add an inline javascript at the end of a html page, so i use registerScript(), something like this :




Yii::app()->clientScript->registerScript('formcheckLanguage', '

	formcheckLanguage = {

		required: "'.Yii::t('validation', 'This field is required').'.",

		alpha: "'.Yii::t('validation', 'This field accepts alphabetic characters only').'.",

		alphanum: "'.Yii::t('validation', 'This field accepts alphanumeric characters only').'.",

		nodigit: "'.Yii::t('validation', 'No digits are accepted').'."

	}

');



The registerScript is doing great, but the problem is the script generated in jQuery(document).ready() function.

I just want have something like this :




<script type="text/javascript">

/*<![CDATA[*/

formcheckLanguage = {

	required: "This field is required.",

	alpha: "This field accepts alphabetic characters only.",

	alphanum: "This field accepts alphanumeric characters only.",

	nodigit: "No digits are accepted."

}

/*]]>*/

</script>



Is there any suggestion on how to remove the jQuery(document).ready() ?

I’m sorry for my bad english. Thanks you.

Best regards.

Hi Sulaeman,

Have a look at the CClientScript class reference, you will find that there is an option for that.

CClientScript::POS_READY is the default, hence your script being inserted within a jQuery.document.ready().

You want to use CClientScript::POS_HEAD to achieve what you want.

So your script would read like :




Yii::app()->clientScript->registerScript('formcheckLanguage', '

	formcheckLanguage = {

		required: "'.Yii::t('validation', 'This field is required').'.",

		alpha: "'.Yii::t('validation', 'This field accepts alphabetic characters only').'.",

		alphanum: "'.Yii::t('validation', 'This field accepts alphanumeric characters only').'.",

		nodigit: "'.Yii::t('validation', 'No digits are accepted').'."

	}

'), CClientScript::POS_HEAD;



Julien

There’s a third parameter which specify script placement.

http://www.yiiframework.com/doc/api/CClientScript#registerScript-detail

/Tommy

Edit: Strange, I must have missed the above answer.

Julien,

According to Yahoo’s performance tips, it is better to place javascript at POS_END.

Thanks ^_^.

I miss to read that third parameter, now it’s what i wanted.

Best regards.