Yii Framework Forum: Including jQuery and JUI - Yii Framework Forum

Jump to content

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

Including jQuery and JUI Rate Topic: ***** 1 Votes

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 02:04 PM

I have a slight issue with regards to including jQuery and jQueryUI.

Instead of Yii widgets/extensions auto-including jQuery files I want to include these files manually (using my own versions) so that they are always available.

This is how I've configured it in my main.php layout file:

<?php
$cs=Yii::app()->clientScript;
	
$cs->scriptMap=array(
	'jquery.js'=>Yii::app()->request->baseUrl.'/js/jquery-1.4.2.min.js',
	'jquery-ui-1.7.2.custom.min.js'=>Yii::app()->request->baseUrl.'/js/jquery-ui-1.7.2.custom.min.js',
);

$cs->registerScriptFile('jquery-ui-1.7.2.custom.min.js');
?>

The problem I'm having at the moment is that 'jquery-ui-1.7.2.custom.min.js' is being added last. I am using a widget which registers a script file and this file depends on jQueryUI and therefore needs to be added after 'jquery-ui-1.7.2.custom.min.js'.

So how do I get the two jQuery files to be included together, and all other additional scripts to be added at the end?
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 20 July 2010 - 06:30 AM

Anybody have any suggestions for this?
0

#3 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 20 July 2010 - 09:32 AM

View PostGSTAR, on 20 July 2010 - 06:30 AM, said:

Anybody have any suggestions for this?



If it is always going to be needed you could just add it to the layout file as html.
0

#4 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 20 July 2010 - 10:28 AM

View PostDarkNSF, on 20 July 2010 - 09:32 AM, said:

If it is always going to be needed you could just add it to the layout file as html.

Ah yes, you're right. So I basically add the scripts in using CHtml::scriptFile() and then do:

Yii::app()->clientScript->scriptMap=array(
	'jquery.js'=>false,
);

to prevent Yii from loading it's own jQuery file.
0

#5 User is offline   daonhack 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 02-June 09

Posted 20 July 2010 - 04:28 PM

View PostGSTAR, on 19 July 2010 - 02:04 PM, said:

I have a slight issue with regards to including jQuery and jQueryUI.

Instead of Yii widgets/extensions auto-including jQuery files I want to include these files manually (using my own versions) so that they are always available.

This is how I've configured it in my main.php layout file:

<?php
$cs=Yii::app()->clientScript;
	
$cs->scriptMap=array(
	'jquery.js'=>Yii::app()->request->baseUrl.'/js/jquery-1.4.2.min.js',
	'jquery-ui-1.7.2.custom.min.js'=>Yii::app()->request->baseUrl.'/js/jquery-ui-1.7.2.custom.min.js',
);

$cs->registerScriptFile('jquery-ui-1.7.2.custom.min.js');
?>

The problem I'm having at the moment is that 'jquery-ui-1.7.2.custom.min.js' is being added last. I am using a widget which registers a script file and this file depends on jQueryUI and therefore needs to be added after 'jquery-ui-1.7.2.custom.min.js'.

So how do I get the two jQuery files to be included together, and all other additional scripts to be added at the end?


registerScriptFile() method
public void registerScriptFile(string $url, integer $position=0)
$url string URL of the javascript file
$position integer the position of the JavaScript code. Valid values include the following:

* CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
* 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.

Plus more position for them.
0

#6 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,037
  • Joined: 30-October 09
  • Location:UK

Posted 20 July 2010 - 04:32 PM

daonhack - I was talking about the positioning of the scripts within the HEAD section, not within the document.
0

#7 User is offline   daonhack 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 02-June 09

Posted 20 July 2010 - 04:32 PM

View PostGSTAR, on 20 July 2010 - 10:28 AM, said:

Ah yes, you're right. So I basically add the scripts in using CHtml::scriptFile() and then do:

Yii::app()->clientScript->scriptMap=array(
	'jquery.js'=>false,
);

to prevent Yii from loading it's own jQuery file.


Plus more
'jquery.min.js'=>false,	//if you disabled YII_DEBUG :) 

1

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