1: <?php
2: /**
3: * CJuiDroppable 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: * CJuiDroppable displays a droppable widget.
15: *
16: * CJuiDroppable encapsulates the {@link http://jqueryui.com/droppable/ JUI Droppable}
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.CJuiDroppable',array(
22: * // additional javascript options for the droppable plugin
23: * 'options'=>array(
24: * 'scope'=>'myScope',
25: * ),
26: * ));
27: * echo 'Your droppable 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 Droppable plugin. Please refer to
35: * the {@link http://api.jqueryui.com/droppable/ JUI Droppable API} documentation
36: * for possible options (name-value pairs) and
37: * {@link http://jqueryui.com/droppable/ JUI Droppable 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 CJuiDroppable extends CJuiWidget
45: {
46: /**
47: * @var string the HTML tag name of the Droppable element. Defaults to 'div'.
48: */
49: public $tagName='div';
50:
51: /**
52: * Renders the open tag of the droppable 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}').droppable($options);");
67:
68: echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
69: }
70:
71: /**
72: * Renders the close tag of the droppable element.
73: */
74: public function run()
75: {
76: echo CHtml::closeTag($this->tagName);
77: }
78: }