how to register jquery ui script? is it bundled with yii 1.1.1?
how to register jquery ui script? is it bundled with yii 1.1.1?
I did this in a past project
<?php
/**
* ClientScript class file.
*/
class ClientScript extends CClientScript
{
public $juiDefaultTheme = 'base';
public $juiScriptFile = 'jquery-ui.min.js';
public $juiCssFile = 'jquery.ui.all.css';
public $juiI18nScriptFile = 'jquery-ui-i18n.js';
public $juiPathAlias = 'zii.vendors.jui';
public function registerJuiScripts($cssFile = '', $theme = '', $useI18n = false, $position=ClientScript::POS_END)
{
if($cssFile === '')
$cssFile = $this->juiCssFile;
if($theme === '')
$theme = $this->juiDefaultTheme;
$basePath=Yii::getPathOfAlias($this->juiPathAlias);
$baseUrl=Yii::app()->getAssetManager()->publish($basePath, true);
$scriptUrl=$baseUrl.'/js';
$cssUrl=$baseUrl.'/css';
$this->registerCssFile($cssUrl.'/'.$theme.'/'.$cssFile);
$this->registerCoreScript('jquery');
$this->registerScriptFile($scriptUrl.'/'.$this->juiScriptFile, $position);
if($useI18n)
$this->registerScriptFile($scriptUrl.'/'.$this->juiI18nScriptFile, $position);
}
}
set the class for your coreScript component
'coreScript'=>array(
'class'=>'ClientScript',
),
to register it, call
Yii::app()->clientScript->registerJuiScripts();
thanks
Thank you (both) for posting this - very timely, because I just happened to have the same question today.
One thing I am still wondering, though: I am using yii-1.1.1.r1907, and my jQuery UI base theme is
/framework/zii/vendors/jui/css/base/jquery-ui.css
However, I noticed you have jquery.ui.all.css. Did you download that from jQueryUI’s themeroller tool? Or did it come with your version of Yii?
I also ran into this yesterday. Default css in framework/zii CJuiWidget (as of r2049) seemingly has changed from jquery-ui.css to jquery.ui.all.css (the files turned out to be identical). The themes download contains both, framework/zii (r2049) only the latter.
/Tommy
Oh ok, I see. Thanks!
Yes, the name was changed in svn after the last release. You can set the properties in your component config e.g.
...
'clientScript'=>array(
'class'=>'ClientScript',
'juiCssFile'=>'css filename',
),
...
I just made a small change to the code in the first post so you can also set the path to the jui files as an alias in the component config.
I also changed property $defaultJuiTheme to $juiDefaultTheme for naming consistency.
Nice! Thanks again for this extension. It is very useful to me.
If just need some function from ui…
$jui=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.vendors.jui.js').DIRECTORY_SEPARATOR.'jquery-ui.min.js');
$cs=Yii::app()->clientScript;
$cs->registerScriptFile($jui);
It seems to have been moved, at least as of 1.1.6, likely before. Now it would be:
$jui=$cs->getCoreScriptUrl().’/jui/js’.DIRECTORY_SEPARATOR.‘jquery-ui.min.js’;
Why not simply
Yii::app()->clientScript->registerCoreScript('jquery.ui');
You have just to be carefull in including jquery too and the css file.
If you want to do your custom implementation, is better to place a css file for jui widget and manage it with clientscript, in order to be independed to changes in the framework.
Nice zaccaria
Thanks Zaccaria for a very simple solutions
Are you really the best? or is it me only who think so?
The full solution with css
$cs = Yii::app()->clientScript;
$cs->registerCoreScript(‘jquery.ui’);
$cs->registerCssFile($cs->getCoreScriptUrl(). ‘/jui/css/base/jquery-ui.css’);