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