1
0

Added new (clean) yii boilerplate

This commit is contained in:
2014-05-13 12:40:42 +02:00
parent 1d6d975a16
commit 99d29b432b
1983 changed files with 653465 additions and 17 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* CJuiAccordion class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiAccordion displays an accordion widget.
*
* CJuiAccordion encapsulates the {@link http://jqueryui.com/accordion/ JUI Accordion}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiAccordion',array(
* 'panels'=>array(
* 'panel 1'=>'content for panel 1',
* 'panel 2'=>'content for panel 2',
* // panel 3 contains the content rendered by a partial view
* 'panel 3'=>$this->renderPartial('_partial',null,true),
* ),
* // additional javascript options for the accordion plugin
* 'options'=>array(
* 'animated'=>'bounceslide',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI accordion plugin. Please refer to
* the {@link http://api.jqueryui.com/accordion/ JUI Accordion API}
* documentation for possible options (name-value pairs) and
* {@link http://jqueryui.com/accordion/ JUI Accordion page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiAccordion extends CJuiWidget
{
/**
* @var array list of panels (panel title=>panel content).
* Note that neither panel title nor panel content will be HTML-encoded.
*/
public $panels=array();
/**
* @var string the name of the container element that contains all panels. Defaults to 'div'.
*/
public $tagName='div';
/**
* @var string the template that is used to generated every panel header.
* The token "{title}" in the template will be replaced with the panel title.
* Note that if you make change to this template, you may also need to adjust
* the 'header' setting in {@link options}.
*/
public $headerTemplate='<h3><a href="#">{title}</a></h3>';
/**
* @var string the template that is used to generated every panel content.
* The token "{content}" in the template will be replaced with the panel content.
*/
public $contentTemplate='<div>{content}</div>';
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
foreach($this->panels as $title=>$content)
{
echo strtr($this->headerTemplate,array('{title}'=>$title))."\n";
echo strtr($this->contentTemplate,array('{content}'=>$content))."\n";
}
echo CHtml::closeTag($this->tagName);
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').accordion($options);");
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* CJuiAutoComplete class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiInputWidget');
/**
* CJuiAutoComplete displays an autocomplete field.
*
* CJuiAutoComplete encapsulates the {@link http://jqueryui.com/autocomplete/ JUI
* autocomplete} plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
* 'name'=>'city',
* 'source'=>array('ac1','ac2','ac3'),
* // additional javascript options for the autocomplete plugin
* 'options'=>array(
* 'minLength'=>'2',
* ),
* 'htmlOptions'=>array(
* 'style'=>'height:20px;',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI autocomplete plugin. Please refer to
* the {@link http://api.jqueryui.com/autocomplete/ JUI AutoComplete API}
* documentation for possible options (name-value pairs) and
* {@link http://jqueryui.com/autocomplete/ JUI AutoComplete page} for
* general description and demo.
*
* By configuring the {@link source} property, you may specify where to search
* the autocomplete options for each item. If source is an array, the list is
* used for autocomplete. You may also configure {@link sourceUrl} to retrieve
* autocomplete items from an ajax response.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1.2
*/
class CJuiAutoComplete extends CJuiInputWidget
{
/**
* @var mixed the entries that the autocomplete should choose from. This can be
* <ul>
* <li>an Array with local data</li>
* <li>a String, specifying a URL that returns JSON data as the entries.</li>
* <li>a javascript callback. Please make sure you wrap the callback with
* {@link CJavaScriptExpression} in this case.</li>
* </ul>
*/
public $source=array();
/**
* @var mixed the URL that will return JSON data as the autocomplete items.
* CHtml::normalizeUrl() will be applied to this property to convert the property
* into a proper URL. When this property is set, the {@link source} property will be ignored.
*/
public $sourceUrl;
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
if($this->hasModel())
echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
else
echo CHtml::textField($name,$this->value,$this->htmlOptions);
if($this->sourceUrl!==null)
$this->options['source']=CHtml::normalizeUrl($this->sourceUrl);
else
$this->options['source']=$this->source;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').autocomplete($options);");
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* CJuiButton class file.
*
* @author Sebastian Thierer <sebas@artfos.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiInputWidget');
/**
* CJuiButton displays a button widget.
*
* CJuiButton encapsulates the {@link http://jqueryui.com/button/ JUI Button}
* plugin.
*
* To use this widget as a submit button, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiButton',array(
* 'buttonType'=>'submit',
* 'name'=>'btnSubmit',
* 'value'=>'1',
* 'caption'=>'Submit form',
* 'htmlOptions'=>array('class'=>'ui-button-primary')
* ),
* ));
* </pre>
*
* To use this widget as a button, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiButton',array(
* 'buttonType'=>'button',
* 'name'=>'btnSave',
* 'caption'=>'Save',
* 'onclick'=>new CJavaScriptExpression('function(){alert("Save button clicked"); this.blur(); return false;}'),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI button plugin. Please refer to
* the {@link http://api.jqueryui.com/button/ JUI Button API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/button/ JUI Button page} for general description
* and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1.3
*/
class CJuiButton extends CJuiInputWidget
{
/**
* @var string The button type (possible types: submit, button, link, radio, checkbox, buttonset).
* "submit" is used as default.
*/
public $buttonType='submit';
/**
* @var string The default html tag for the buttonset
*/
public $htmlTag='div';
/**
* @var mixed a URL or an action route that can be used to create a URL. Used when a buttonType "link" is selected.
* See {@link normalizeUrl} for more details about how to specify this parameter.
*/
public $url=null;
/**
* @var mixed The value of the current item. Used only for "radio" and "checkbox"
*/
public $value;
/**
* @var string The button text
*/
public $caption="";
/**
* @var string The javascript function to be raised when this item is clicked (client event).
*/
public $onclick;
/**
* (non-PHPdoc)
* @see framework/zii/widgets/jui/CJuiWidget::init()
*/
public function init()
{
parent::init();
if($this->buttonType=='buttonset')
{
if(!isset($this->htmlOptions['id']))
$this->htmlOptions['id']=$this->getId();
echo CHtml::openTag($this->htmlTag,$this->htmlOptions);
}
}
/**
* (non-PHPdoc)
* @see framework/CWidget::run()
*/
public function run()
{
$cs=Yii::app()->getClientScript();
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
else
$this->htmlOptions['name']=$name;
if($this->buttonType=='buttonset')
{
echo CHtml::closeTag($this->htmlTag);
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').buttonset();");
}
else
{
switch($this->buttonType)
{
case 'submit':
echo CHtml::submitButton($this->caption,$this->htmlOptions)."\n";
break;
case 'button':
echo CHtml::htmlButton($this->caption,$this->htmlOptions)."\n";
break;
case 'link':
echo CHtml::link($this->caption,$this->url,$this->htmlOptions)."\n";
break;
case 'radio':
if($this->hasModel())
{
echo CHtml::activeRadioButton($this->model,$this->attribute,$this->htmlOptions);
echo CHtml::label($this->caption,CHtml::activeId($this->model,$this->attribute))."\n";
}
else
{
echo CHtml::radioButton($name,$this->value,$this->htmlOptions);
echo CHtml::label($this->caption,$id)."\n";
}
break;
case 'checkbox':
if($this->hasModel())
{
echo CHtml::activeCheckbox($this->model,$this->attribute,$this->htmlOptions);
echo CHtml::label($this->caption,CHtml::activeId($this->model,$this->attribute))."\n";
}
else
{
echo CHtml::checkbox($name,$this->value,$this->htmlOptions);
echo CHtml::label($this->caption,$id)."\n";
}
break;
default:
throw new CException(Yii::t('zii','The button type "{type}" is not supported.',array('{type}'=>$this->buttonType)));
}
$options=CJavaScript::encode($this->options);
if($this->onclick!==null)
{
if(!($this->onclick instanceof CJavaScriptExpression))
$this->onclick=new CJavaScriptExpression($this->onclick);
$click=CJavaScript::encode($this->onclick);
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').button($options).click($click);");
}
else
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').button($options);");
}
}
}

View File

@@ -0,0 +1,128 @@
<?php
/**
* CJuiDatePicker class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiInputWidget');
/**
* CJuiDatePicker displays a datepicker.
*
* CJuiDatePicker encapsulates the {@link http://jqueryui.com/datepicker/ JUI
* datepicker} plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiDatePicker',array(
* 'name'=>'publishDate',
* // additional javascript options for the date picker plugin
* 'options'=>array(
* 'showAnim'=>'fold',
* ),
* 'htmlOptions'=>array(
* 'style'=>'height:20px;'
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI datepicker plugin. Please refer to
* the {@link http://api.jqueryui.com/datepicker/ JUI DatePicker API}
* documentation for possible options (name-value pairs) and
* {@link http://jqueryui.com/datepicker/ JUI DatePicker page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiDatePicker extends CJuiInputWidget
{
/**
* @var string the locale ID (eg 'fr', 'de') for the language to be used by the date picker.
* If this property is not set, I18N will not be involved. That is, the date picker will show in English.
* You can force English language by setting the language attribute as '' (empty string)
*/
public $language;
/**
* @var string The i18n Jquery UI script file. It uses scriptUrl property as base url.
*/
public $i18nScriptFile='jquery-ui-i18n.min.js';
/**
* @var array The default options called just one time per request. This options will alter every other CJuiDatePicker instance in the page.
* It has to be set at the first call of CJuiDatePicker widget in the request.
*/
public $defaultOptions;
/**
* @var boolean If true, shows the widget as an inline calendar and the input as a hidden field.
*/
public $flat=false;
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
if($this->flat===false)
{
if($this->hasModel())
echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
else
echo CHtml::textField($name,$this->value,$this->htmlOptions);
}
else
{
if($this->hasModel())
{
echo CHtml::activeHiddenField($this->model,$this->attribute,$this->htmlOptions);
$attribute=$this->attribute;
$this->options['defaultDate']=$this->model->$attribute;
}
else
{
echo CHtml::hiddenField($name,$this->value,$this->htmlOptions);
$this->options['defaultDate']=$this->value;
}
$this->options['altField']='#'.$id;
$id=$this->htmlOptions['id']=$id.'_container';
$this->htmlOptions['name']=$name.'_container';
echo CHtml::tag('div',$this->htmlOptions,'');
}
$options=CJavaScript::encode($this->options);
$js = "jQuery('#{$id}').datepicker($options);";
if($this->language!='' && $this->language!='en')
{
$this->registerScriptFile($this->i18nScriptFile);
$js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional['{$this->language}'],{$options}));";
}
$cs = Yii::app()->getClientScript();
if(isset($this->defaultOptions))
{
$this->registerScriptFile($this->i18nScriptFile);
$cs->registerScript(__CLASS__,$this->defaultOptions!==null?'jQuery.datepicker.setDefaults('.CJavaScript::encode($this->defaultOptions).');':'');
}
$cs->registerScript(__CLASS__.'#'.$id,$js);
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* CJuiDialog class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiDialog displays a dialog widget.
*
* CJuiDialog encapsulates the {@link http://jqueryui.com/dialog/ JUI Dialog}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
* 'id'=>'mydialog',
* // additional javascript options for the dialog plugin
* 'options'=>array(
* 'title'=>'Dialog box 1',
* 'autoOpen'=>false,
* ),
* ));
*
* echo 'dialog content here';
*
* $this->endWidget('zii.widgets.jui.CJuiDialog');
*
* // the link that may open the dialog
* echo CHtml::link('open dialog', '#', array(
* 'onclick'=>'$("#mydialog").dialog("open"); return false;',
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI dialog plugin. Please refer to
* the {@link http://api.jqueryui.com/dialog/ JUI Dialog API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/dialog/ JUI Dialog page} for general description
* and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiDialog extends CJuiWidget
{
/**
* @var string the name of the container element that contains all panels. Defaults to 'div'.
*/
public $tagName='div';
/**
* Renders the open tag of the dialog.
* This method also registers the necessary javascript code.
*/
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
/**
* Renders the close tag of the dialog.
*/
public function run()
{
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* CJuiDraggable class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiDraggable displays a draggable widget.
*
* CJuiDraggable encapsulates the {@link http://jqueryui.com/draggable/ JUI Draggable}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->beginWidget('zii.widgets.jui.CJuiDraggable',array(
* // additional javascript options for the draggable plugin
* 'options'=>array(
* 'scope'=>'myScope',
* ),
* ));
* echo 'Your draggable content here';
*
* $this->endWidget();
*
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI Draggable plugin. Please refer to
* the {@link http://api.jqueryui.com/draggable/ JUI Draggable API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/draggable/ JUI Draggable page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiDraggable extends CJuiWidget
{
/**
* @var string the name of the Draggable element. Defaults to 'div'.
*/
public $tagName='div';
/**
* Renders the open tag of the draggable element.
* This method also registers the necessary javascript code.
*/
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').draggable($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
/**
* Renders the close tag of the draggable element.
*/
public function run()
{
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* CJuiDroppable class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiDroppable displays a droppable widget.
*
* CJuiDroppable encapsulates the {@link http://jqueryui.com/droppable/ JUI Droppable}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->beginWidget('zii.widgets.jui.CJuiDroppable',array(
* // additional javascript options for the droppable plugin
* 'options'=>array(
* 'scope'=>'myScope',
* ),
* ));
* echo 'Your droppable content here';
*
* $this->endWidget();
*
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI Droppable plugin. Please refer to
* the {@link http://api.jqueryui.com/droppable/ JUI Droppable API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/droppable/ JUI Droppable page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiDroppable extends CJuiWidget
{
/**
* @var string the HTML tag name of the Droppable element. Defaults to 'div'.
*/
public $tagName='div';
/**
* Renders the open tag of the droppable element.
* This method also registers the necessary javascript code.
*/
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').droppable($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
/**
* Renders the close tag of the droppable element.
*/
public function run()
{
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* CJuiInputWidget class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiInputWidget is the base class for JUI widgets that can collect user input.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
abstract class CJuiInputWidget extends CJuiWidget
{
/**
* @var CModel the data model associated with this widget.
*/
public $model;
/**
* @var string the attribute associated with this widget.
* The name can contain square brackets (e.g. 'name[1]') which is used to collect tabular data input.
*/
public $attribute;
/**
* @var string the input name. This must be set if {@link model} is not set.
*/
public $name;
/**
* @var string the input value.
*/
public $value;
/**
* Resolves name and ID of the input. Source property of the name and/or source property of the attribute
* could be customized by specifying first and/or second parameter accordingly.
* @param string $nameProperty class property name which holds element name to be used. This parameter
* is available since 1.1.14.
* @param string $attributeProperty class property name which holds model attribute name to be used. This
* parameter is available since 1.1.14.
* @return array name and ID of the input: array('name','id').
* @throws CException in case model and attribute property or name property cannot be resolved.
*/
protected function resolveNameID($nameProperty='name',$attributeProperty='attribute')
{
if($this->$nameProperty!==null)
$name=$this->$nameProperty;
elseif(isset($this->htmlOptions[$nameProperty]))
$name=$this->htmlOptions[$nameProperty];
elseif($this->hasModel())
$name=CHtml::activeName($this->model,$this->$attributeProperty);
else
throw new CException(Yii::t('zii','{class} must specify "model" and "{attribute}" or "{name}" property values.',
array('{class}'=>get_class($this),'{attribute}'=>$attributeProperty,'{name}'=>$nameProperty)));
if(($id=$this->getId(false))===null)
{
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$id=CHtml::getIdByName($name);
}
return array($name,$id);
}
/**
* @return boolean whether this widget is associated with a data model.
*/
protected function hasModel()
{
return $this->model instanceof CModel && $this->attribute!==null;
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* CJuiProgressBar class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiProgressBar displays a progress bar widget.
*
* CJuiProgressBar encapsulates the {@link http://jqueryui.com/progressbar/ JUI
* Progressbar} plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiProgressBar',array(
* 'value'=>75,
* // additional javascript options for the progress bar plugin
* 'options'=>array(
* 'change'=>new CJavaScriptExpression('function(event, ui) {...}'),
* ),
* 'htmlOptions'=>array(
* 'style'=>'height:20px;',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI progressbar plugin. Please refer to
* the {@link http://api.jqueryui.com/progressbar/ JUI ProgressBar} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/progressbar/ JUI ProgressBar page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiProgressBar extends CJuiWidget
{
/**
* @var string the name of the container element that contains the progress bar. Defaults to 'div'.
*/
public $tagName='div';
/**
* @var integer the percentage of the progress. This must be an integer between 0 and 100. Defaults to 0.
*/
public $value=0;
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
echo CHtml::openTag($this->tagName,$this->htmlOptions);
echo CHtml::closeTag($this->tagName);
$this->options['value']=$this->value;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').progressbar($options);");
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* CJuiResizable class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiResizable displays a resizable widget.
*
* CJuiResizable encapsulates the {@link http://jqueryui.com/resizable/ JUI Resizable}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->beginWidget('zii.widgets.jui.CJuiResizable',array(
* // additional javascript options for the resizable plugin
* 'options'=>array(
* 'minHeight'=>'150',
* ),
* ));
* echo 'Your Resizable content here';
*
* $this->endWidget();
*
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI Resizable plugin. Please refer to
* the {@link http://api.jqueryui.com/resizable/ JUI Resizable API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/resizable/ JUI Resizable page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiResizable extends CJuiWidget
{
/**
* @var string the name of the Resizable element. Defaults to 'div'.
*/
public $tagName='div';
/**
* Renders the open tag of the resizable element.
* This method also registers the necessary javascript code.
*/
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').resizable($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
/**
* Renders the close tag of the resizable element.
*/
public function run()
{
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* CJuiSelectable class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiSelectable displays an accordion widget.
*
* CJuiSelectable encapsulates the {@link http://jqueryui.com/selectable/ JUI Selectable}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiSelectable',array(
* 'items'=>array(
* 'id1'=>'Item 1',
* 'id2'=>'Item 2',
* 'id3'=>'Item 3',
* ),
* // additional javascript options for the selectable plugin
* 'options'=>array(
* 'delay'=>'300',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI Selectable plugin. Please refer to
* the {@link http://api.jqueryui.com/selectable/ JUI Selectable API}
* documentation for possible options (name-value pairs) and
* {@link http://jqueryui.com/selectable/ JUI Selectable page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiSelectable extends CJuiWidget {
/**
* @var array list of selectable items (id=>item content).
* Note that the item contents will not be HTML-encoded.
*/
public $items=array();
/**
* @var string the name of the container element that contains all items. Defaults to 'ol'.
*/
public $tagName='ol';
/**
* @var string the template that is used to generated every selectable item.
* The token "{content}" in the template will be replaced with the item content,
* while "{id}" will be replaced with the item ID.
*/
public $itemTemplate='<li id="{id}">{content}</li>';
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').selectable({$options});");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
foreach($this->items as $id=>$content)
echo strtr($this->itemTemplate,array('{id}'=>$id,'{content}'=>$content))."\n";
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* CJuiSlider class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiSlider displays a slider.
*
* CJuiSlider encapsulates the {@link http://jqueryui.com/slider/ JUI
* slider} plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiSlider',array(
* 'value'=>37,
* // additional javascript options for the slider plugin
* 'options'=>array(
* 'min'=>10,
* 'max'=>50,
* ),
* 'htmlOptions'=>array(
* 'style'=>'height:20px;',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI slider plugin. Please refer to
* the {@link http://api.jqueryui.com/slider/ JUI Slider API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/slider/ JUI Slider page} for general
* description and demo.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiSlider extends CJuiWidget
{
/**
* @var string the name of the container element that contains the slider. Defaults to 'div'.
*/
public $tagName='div';
/**
* @var integer determines the value of the slider, if there's only one handle. If there is more than one handle, determines the value of the first handle.
*/
public $value;
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
echo CHtml::tag($this->tagName,$this->htmlOptions,'');
if($this->value!==null)
$this->options['value']=$this->value;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').slider($options);");
}
}

View File

@@ -0,0 +1,168 @@
<?php
/**
* CJuiSliderInput class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiInputWidget');
/**
* CJuiSliderInput displays a slider. It can be used in forms and post its value.
*
* CJuiSlider encapsulates the {@link http://jqueryui.com/slider/ JUI
* slider} plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiSliderInput',array(
* 'name'=>'rate',
* 'value'=>37,
* // additional javascript options for the slider plugin
* 'options'=>array(
* 'min'=>10,
* 'max'=>50,
* ),
* 'htmlOptions'=>array(
* 'style'=>'height:20px;',
* ),
* ));
* </pre>
*
* The widget can also be used in range mode which uses 2 sliders to set a range.
* In this mode, {@link attribute} and {@link maxAttribute} will define the attribute
* names for the minimum and maximum range values, respectively. For example:
*
* <pre>
* $this->widget('zii.widgets.jui.CJuiSliderInput',array(
* 'model'=>$model,
* 'attribute'=>'timeMin',
* 'maxAttribute'=>'timeMax',
* // additional javascript options for the slider plugin
* 'options'=>array(
* 'range'=>true,
* 'min'=>0,
* 'max'=>24,
* ),
* ));
* </pre>
*
* If you need to use the slider event, please change the event value for 'stop' or 'change'.
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI slider plugin. Please refer to
* the {@link http://api.jqueryui.com/slider/ JUI Slider API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/slider/ JUI Slider page} for general
* description and demo.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiSliderInput extends CJuiInputWidget
{
/**
* @var string the name of the container element that contains the slider. Defaults to 'div'.
*/
public $tagName='div';
/**
* @var integer determines the value of the slider, if there's only one handle. If there is more than one handle,
* determines the value of the first handle.
*/
public $value;
/**
* @var string the name of the event where the input will be attached to the slider. It
* can be 'slide', 'stop' or 'change'. If you want to use 'slide' event change $event property to 'change'.
*/
public $event='slide';
/**
* @var string name of attribute for max value if slider is used in range mode.
*/
public $maxAttribute;
/**
* @var string the input name to be used for max value attribute when using slider in range mode.
* This must be set in case {@link model} isn't used.
* @since 1.1.14
*/
public $maxName;
/**
* @var integer determines the max value of the slider, if there's two handles (range mode). Ignored if there's
* only one handle.
* @since 1.1.14
*/
public $maxValue;
/**
* @var string the suffix to be appended to the ID of the max value input element
* when slider used in range mode.
* @since 1.1.14
*/
public $maxIdSuffix='_end';
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$isRange=isset($this->options['range']) && $this->options['range'] &&
$this->options['range']!=='max' && $this->options['range']!=='min';
if($this->hasModel())
{
$attribute=$this->attribute;
if($isRange)
{
$options=$this->htmlOptions;
echo CHtml::activeHiddenField($this->model,$this->attribute,$options);
$options['id'].=$this->maxIdSuffix;
echo CHtml::activeHiddenField($this->model,$this->maxAttribute,$options);
$maxAttribute=$this->maxAttribute;
$this->options['values']=array($this->model->$attribute,$this->model->$maxAttribute);
}
else
{
echo CHtml::activeHiddenField($this->model,$this->attribute,$this->htmlOptions);
$this->options['value']=$this->model->$attribute;
}
}
else
{
if($isRange)
{
list($maxName,$maxId)=$this->resolveNameID('maxName','maxAttribute');
$options=$this->htmlOptions;
echo CHtml::hiddenField($name,$this->value,$options);
$options['id'].=$this->maxIdSuffix;
echo CHtml::hiddenField($maxName,$this->maxValue,$options);
$this->options['values']=array($this->value,$this->maxValue);
}
else
{
echo CHtml::hiddenField($name,$this->value,$this->htmlOptions);
if($this->value!==null)
$this->options['value']=$this->value;
}
}
$idHidden=$this->htmlOptions['id'];
$this->htmlOptions['id']=$idHidden.'_slider';
echo CHtml::tag($this->tagName,$this->htmlOptions,'');
$this->options[$this->event]=$isRange
? new CJavaScriptExpression("function(e,ui){ v=ui.values; jQuery('#{$idHidden}').val(v[0]); jQuery('#{$idHidden}{$this->maxIdSuffix}').val(v[1]); }")
: new CJavaScriptExpression("function(event, ui) { jQuery('#{$idHidden}').val(ui.value); }");
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}_slider').slider($options);");
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* CJuiSortable class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiSortable makes selected elements sortable by dragging with the mouse.
*
* CJuiSortable encapsulates the {@link http://jqueryui.com/sortable/ JUI Sortable}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiSortable',array(
* 'items'=>array(
* 'id1'=>'Item 1',
* 'id2'=>'Item 2',
* 'id3'=>'Item 3',
* ),
* // additional javascript options for the JUI Sortable plugin
* 'options'=>array(
* 'delay'=>'300',
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI Sortable plugin. Please refer to
* the {@link http://api.jqueryui.com/sortable/ JUI Sortable API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/sortable/ JUI Sortable page} for general
* description and demo.
*
* If you are using JavaScript expressions anywhere in the code, please wrap it
* with {@link CJavaScriptExpression} and Yii will use it as code.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiSortable extends CJuiWidget
{
/**
* @var array list of sortable items (id=>item content).
* Note that the item contents will not be HTML-encoded.
*/
public $items=array();
/**
* @var string the name of the container element that contains all items. Defaults to 'ul'.
*/
public $tagName='ul';
/**
* @var string the template that is used to generated every sortable item.
* The token "{content}" in the template will be replaced with the item content,
* while "{id}" be replaced with the item ID.
*/
public $itemTemplate='<li id="{id}">{content}</li>';
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').sortable({$options});");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
foreach($this->items as $id=>$content)
echo strtr($this->itemTemplate,array('{id}'=>$id,'{content}'=>$content))."\n";
echo CHtml::closeTag($this->tagName);
}
}

View File

@@ -0,0 +1,149 @@
<?php
/**
* CJuiTabs class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* CJuiTabs displays a tabs widget.
*
* CJuiTabs encapsulates the {@link http://jqueryui.com/tabs/ JUI tabs}
* plugin.
*
* To use this widget, you may insert the following code in a view:
* <pre>
* $this->widget('zii.widgets.jui.CJuiTabs',array(
* 'tabs'=>array(
* 'StaticTab 1'=>'Content for tab 1',
* 'StaticTab 2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),
* // panel 3 contains the content rendered by a partial view
* 'AjaxTab'=>array('ajax'=>$ajaxUrl),
* ),
* // additional javascript options for the tabs plugin
* 'options'=>array(
* 'collapsible'=>true,
* ),
* ));
* </pre>
*
* By configuring the {@link options} property, you may specify the options
* that need to be passed to the JUI tabs plugin. Please refer to
* the {@link http://api.jqueryui.com/tabs/ JUI Tabs API} documentation
* for possible options (name-value pairs) and
* {@link http://jqueryui.com/tabs/ JUI Tabs page} for general
* description and demo.
*
* Note, in case you're using &lt;base/&gt; HTML tag you may run into the
* issue when jQuery UI uses altered base URL to load content, but not
* the base URL content was loaded from. (Developer may expect both behavior
* in different cases.) For this occasion consider using absolute URL
* generation as follows:
*
* <pre>
* $this->widget('zii.widgets.jui.CJuiTabs',array(
* 'tabs'=>array(
* 'Dynamic Tab'=>array('ajax'=>$this->createAbsoluteUrl('tab/content/route')),
* ),
* ));
* </pre>
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
class CJuiTabs extends CJuiWidget
{
/**
* @var array list of tabs (tab title=>tab content).
* Note that the tab title will not be HTML-encoded.
* The tab content can be either a string or an array. When it is an array, it can
* be in one of the following two formats:
* <pre>
* array('id'=>'myTabID', 'content'=>'tab content')
* array('id'=>'myTabID', 'ajax'=>URL)
* </pre>
* where the 'id' element is optional. The second format allows the tab content
* to be dynamically fetched from the specified URL via AJAX. The URL can be either
* a string or an array. If an array, it will be normalized into a URL using {@link CHtml::normalizeUrl}.
*/
public $tabs=array();
/**
* @var string the name of the container element that contains all panels. Defaults to 'div'.
*/
public $tagName='div';
/**
* @var string the template that is used to generated every panel title.
* The token "{title}" in the template will be replaced with the panel title and
* the token "{url}" will be replaced with "#TabID" or with the url of the ajax request.
*/
public $headerTemplate='<li><a href="{url}" title="{id}">{title}</a></li>';
/**
* @var string the template that is used to generated every tab content.
* The token "{content}" in the template will be replaced with the panel content
* and the token "{id}" with the tab ID.
*/
public $contentTemplate='<div id="{id}">{content}</div>';
/**
* Run this widget.
* This method registers necessary javascript and renders the needed HTML code.
*/
public function run()
{
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$tabsOut="";
$contentOut="";
$tabCount=0;
foreach($this->tabs as $title=>$content)
{
$tabId=(is_array($content) && isset($content['id']))?$content['id']:$id.'_tab_'.$tabCount++;
if(!is_array($content))
{
$tabsOut.=strtr($this->headerTemplate,array('{title}'=>$title,'{url}'=>'#'.$tabId,'{id}'=>'#'.$tabId))."\n";
$contentOut.=strtr($this->contentTemplate,array('{content}'=>$content,'{id}'=>$tabId))."\n";
}
elseif(isset($content['ajax']))
{
$tabsOut.=strtr($this->headerTemplate,array('{title}'=>$title,'{url}'=>CHtml::normalizeUrl($content['ajax']),'{id}'=>'#'.$tabId))."\n";
}
else
{
$tabsOut.=strtr($this->headerTemplate,array('{title}'=>$title,'{url}'=>'#'.$tabId,'{id}'=>$tabId))."\n";
if(isset($content['content']))
$contentOut.=strtr($this->contentTemplate,array('{content}'=>$content['content'],'{id}'=>$tabId))."\n";
}
}
echo "<ul>\n".$tabsOut."</ul>\n";
echo $contentOut;
echo CHtml::closeTag($this->tagName)."\n";
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').tabs($options);");
}
/**
* Registers the core script files.
* This method overrides the parent implementation by registering the cookie plugin when cookie option is used.
*/
protected function registerCoreScripts()
{
parent::registerCoreScripts();
if(isset($this->options['cookie']))
Yii::app()->getClientScript()->registerCoreScript('cookie');
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* CJuiWidget class file.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* This is the base class for all JUI widget classes.
*
* @author Sebastian Thierer <sebathi@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @package zii.widgets.jui
* @since 1.1
*/
abstract class CJuiWidget extends CWidget
{
/**
* @var string the root URL that contains all JUI JavaScript files.
* If this property is not set (default), Yii will publish the JUI package included in the zii release and use
* that to infer the root script URL. You should set this property if you intend to use
* a JUI package whose version is different from the one included in zii.
* Note that under this URL, there must be a file whose name is specified by {@link scriptFile}.
* Do not append any slash character to the URL.
*/
public $scriptUrl;
/**
* @var string the root URL that contains all JUI theme folders.
* If this property is not set (default), Yii will publish the JUI package included in the zii release and use
* that to infer the root theme URL. You should set this property if you intend to use
* a theme that is not found in the JUI package included in zii.
* Note that under this URL, there must be a directory whose name is specified by {@link theme}.
* Do not append any slash character to the URL.
*/
public $themeUrl;
/**
* @var string the JUI theme name. Defaults to 'base'. Make sure that under {@link themeUrl} there
* is a directory whose name is the same as this property value (case-sensitive).
*/
public $theme='base';
/**
* @var mixed the main JUI JavaScript file. Defaults to 'jquery-ui.min.js'.
* Note the file must exist under the URL specified by {@link scriptUrl}.
* If you need to include multiple script files (e.g. during development, you want to include individual
* plugin script files rather than the minized JUI script file), you may set this property
* as an array of the script file names.
* This property can also be set as false, which means the widget will not include any script file,
* and it is your responsibility to explicitly include it somewhere else.
*/
public $scriptFile='jquery-ui.min.js';
/**
* @var mixed the theme CSS file name. Defaults to 'jquery-ui.css'.
* Note the file must exist under the URL specified by {@link themeUrl}/{@link theme}.
* If you need to include multiple theme CSS files (e.g. during development, you want to include individual
* plugin CSS files), you may set this property as an array of the CSS file names.
* This property can also be set as false, which means the widget will not include any theme CSS file,
* and it is your responsibility to explicitly include it somewhere else.
*/
public $cssFile='jquery-ui.css';
/**
* @var array the initial JavaScript options that should be passed to the JUI plugin.
*/
public $options=array();
/**
* @var array the HTML attributes that should be rendered in the HTML tag representing the JUI widget.
*/
public $htmlOptions=array();
/**
* Initializes the widget.
* This method will publish JUI assets if necessary.
* It will also register jquery and JUI JavaScript files and the theme CSS file.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
$this->resolvePackagePath();
$this->registerCoreScripts();
parent::init();
}
/**
* Determine the JUI package installation path.
* This method will identify the JavaScript root URL and theme root URL.
* If they are not explicitly specified, it will publish the included JUI package
* and use that to resolve the needed paths.
*/
protected function resolvePackagePath()
{
if($this->scriptUrl===null || $this->themeUrl===null)
{
$cs=Yii::app()->getClientScript();
if($this->scriptUrl===null)
$this->scriptUrl=$cs->getCoreScriptUrl().'/jui/js';
if($this->themeUrl===null)
$this->themeUrl=$cs->getCoreScriptUrl().'/jui/css';
}
}
/**
* Registers the core script files.
* This method registers jquery and JUI JavaScript files and the theme CSS file.
*/
protected function registerCoreScripts()
{
$cs=Yii::app()->getClientScript();
if(is_string($this->cssFile))
$cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$this->cssFile);
elseif(is_array($this->cssFile))
{
foreach($this->cssFile as $cssFile)
$cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$cssFile);
}
$cs->registerCoreScript('jquery');
if(is_string($this->scriptFile))
$this->registerScriptFile($this->scriptFile);
elseif(is_array($this->scriptFile))
{
foreach($this->scriptFile as $scriptFile)
$this->registerScriptFile($scriptFile);
}
}
/**
* Registers a JavaScript file under {@link scriptUrl}.
* Note that by default, the script file will be rendered at the end of a page to improve page loading speed.
* @param string $fileName JavaScript file name
* @param integer $position the position of the JavaScript file. Valid values include the following:
* <ul>
* <li>CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.</li>
* <li>CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.</li>
* <li>CClientScript::POS_END : the script is inserted at the end of the body section.</li>
* </ul>
*/
protected function registerScriptFile($fileName,$position=CClientScript::POS_END)
{
Yii::app()->getClientScript()->registerScriptFile($this->scriptUrl.'/'.$fileName,$position);
}
}