Yii Framework Forum: I dont want to use jQuery on registerScript - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I dont want to use jQuery on registerScript Rate Topic: -----

#1 User is offline   Sulaeman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 29-July 09

Posted 09 August 2009 - 12:57 AM

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.
0

#2 User is offline   Julien 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 19-July 09
  • Location:Paris, France

Posted 09 August 2009 - 04:40 AM

View PostSulaeman, on 09 August 2009 - 12:57 AM, said:


...

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() ?



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
Julien
0

#3 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 09 August 2009 - 04:43 AM

There's a third parameter which specify script placement.

http://www.yiiframew...erScript-detail

/Tommy

Edit: Strange, I must have missed the above answer.
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#4 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 09 August 2009 - 04:54 AM

Julien,
According to Yahoo's performance tips, it is better to place javascript at POS_END.
0

#5 User is offline   Sulaeman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 29-July 09

Posted 09 August 2009 - 06:49 AM

Thanks ^_^.

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

Best regards.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users