CJuiSlider.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * CJuiSlider class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. Yii::import('zii.widgets.jui.CJuiWidget');
  11. /**
  12. * CJuiSlider displays a slider.
  13. *
  14. * CJuiSlider encapsulates the {@link http://jqueryui.com/slider/ JUI
  15. * slider} plugin.
  16. *
  17. * To use this widget, you may insert the following code in a view:
  18. * <pre>
  19. * $this->widget('zii.widgets.jui.CJuiSlider',array(
  20. * 'value'=>37,
  21. * // additional javascript options for the slider plugin
  22. * 'options'=>array(
  23. * 'min'=>10,
  24. * 'max'=>50,
  25. * ),
  26. * 'htmlOptions'=>array(
  27. * 'style'=>'height:20px;',
  28. * ),
  29. * ));
  30. * </pre>
  31. *
  32. * By configuring the {@link options} property, you may specify the options
  33. * that need to be passed to the JUI slider plugin. Please refer to
  34. * the {@link http://api.jqueryui.com/slider/ JUI Slider API} documentation
  35. * for possible options (name-value pairs) and
  36. * {@link http://jqueryui.com/slider/ JUI Slider page} for general
  37. * description and demo.
  38. *
  39. * @author Qiang Xue <qiang.xue@gmail.com>
  40. * @package zii.widgets.jui
  41. * @since 1.1
  42. */
  43. class CJuiSlider extends CJuiWidget
  44. {
  45. /**
  46. * @var string the name of the container element that contains the slider. Defaults to 'div'.
  47. */
  48. public $tagName='div';
  49. /**
  50. * @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.
  51. */
  52. public $value;
  53. /**
  54. * Run this widget.
  55. * This method registers necessary javascript and renders the needed HTML code.
  56. */
  57. public function run()
  58. {
  59. $id=$this->getId();
  60. if(isset($this->htmlOptions['id']))
  61. $id=$this->htmlOptions['id'];
  62. else
  63. $this->htmlOptions['id']=$id;
  64. echo CHtml::tag($this->tagName,$this->htmlOptions,'');
  65. if($this->value!==null)
  66. $this->options['value']=$this->value;
  67. $options=CJavaScript::encode($this->options);
  68. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').slider($options);");
  69. }
  70. }