1 <?php
2 3 4 5 6 7 8 9
10
11 12 13 14
15 class TbModal extends CWidget
16 {
17 18 19
20 public $autoOpen = false;
21 22 23
24 public $fade = true;
25 26 27
28 public $options = array();
29 30 31
32 public $events = array();
33 34 35
36 public $htmlOptions = array();
37
38 39 40
41 public function init()
42 {
43 if (!isset($this->htmlOptions['id']))
44 $this->htmlOptions['id'] = $this->getId();
45
46 if ($this->autoOpen === false && !isset($this->options['show']))
47 $this->options['show'] = false;
48
49 $classes = array('modal');
50
51 if ($this->fade === true)
52 $classes[] = 'fade';
53
54 if (!empty($classes))
55 {
56 $classes = implode(' ', $classes);
57 if (isset($this->htmlOptions['class']))
58 $this->htmlOptions['class'] .= ' '.$classes;
59 else
60 $this->htmlOptions['class'] = $classes;
61 }
62
63 echo CHtml::openTag('div', $this->htmlOptions);
64 }
65
66 67 68
69 public function run()
70 {
71 $id = $this->htmlOptions['id'];
72
73 echo '</div>';
74
75
76 $cs = Yii::app()->getClientScript();
77
78 $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
79 $cs->registerScript(__CLASS__.'#'.$id, "jQuery('#{$id}').modal({$options});");
80
81 foreach ($this->events as $name => $handler)
82 {
83 $handler = CJavaScript::encode($handler);
84 $cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('{$name}', {$handler});");
85 }
86 }
87 }
88