CJuiResizable.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * CJuiResizable class file.
  4. *
  5. * @author Sebastian Thierer <sebathi@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. * CJuiResizable displays a resizable widget.
  13. *
  14. * CJuiResizable encapsulates the {@link http://jqueryui.com/resizable/ JUI Resizable}
  15. * plugin.
  16. *
  17. * To use this widget, you may insert the following code in a view:
  18. * <pre>
  19. * $this->beginWidget('zii.widgets.jui.CJuiResizable',array(
  20. * // additional javascript options for the resizable plugin
  21. * 'options'=>array(
  22. * 'minHeight'=>'150',
  23. * ),
  24. * ));
  25. * echo 'Your Resizable content here';
  26. *
  27. * $this->endWidget();
  28. *
  29. * </pre>
  30. *
  31. * By configuring the {@link options} property, you may specify the options
  32. * that need to be passed to the JUI Resizable plugin. Please refer to
  33. * the {@link http://api.jqueryui.com/resizable/ JUI Resizable API} documentation
  34. * for possible options (name-value pairs) and
  35. * {@link http://jqueryui.com/resizable/ JUI Resizable page} for general
  36. * description and demo.
  37. *
  38. * @author Sebastian Thierer <sebathi@gmail.com>
  39. * @package zii.widgets.jui
  40. * @since 1.1
  41. */
  42. class CJuiResizable extends CJuiWidget
  43. {
  44. /**
  45. * @var string the name of the Resizable element. Defaults to 'div'.
  46. */
  47. public $tagName='div';
  48. /**
  49. * Renders the open tag of the resizable element.
  50. * This method also registers the necessary javascript code.
  51. */
  52. public function init()
  53. {
  54. parent::init();
  55. $id=$this->getId();
  56. if(isset($this->htmlOptions['id']))
  57. $id=$this->htmlOptions['id'];
  58. else
  59. $this->htmlOptions['id']=$id;
  60. $options=CJavaScript::encode($this->options);
  61. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').resizable($options);");
  62. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  63. }
  64. /**
  65. * Renders the close tag of the resizable element.
  66. */
  67. public function run()
  68. {
  69. echo CHtml::closeTag($this->tagName);
  70. }
  71. }