forked from VisualAppeal/YiiBootstrap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EBootstrapModal.php
120 lines (97 loc) · 2.61 KB
/
EBootstrapModal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/*
* Shows a modal popup
* http://twitter.github.com/bootstrap/javascript.html#modals
*
* @author Tim Helfensdörfer <tim@visualappeal.de>
* @version 0.3.7
* @package bootstrap.widgets
*/
class EBootstrapModal extends EBootstrapWidget {
/*
* Javascript file to hide the alert.
*
* If its set to false, no file will be included
*/
public $jsFile = null;
/*
* Includes backdrop
*/
public $backdrop = true;
/*
* Close modal with ESC key
*/
public $keyboard = true;
/*
* Show the modal on startup
*/
public $show = true;
/*
* Header
*/
public $header = '';
/*
* Footer
*/
public $footer = array();
/*
* Close value
*/
public $close = "×";
/*
* Fade in effect
*/
public $fade = true;
/*
* Init the widget and render header
*/
public function init() {
parent::init();
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId();
EBootstrap::mergeClass($this->htmlOptions, array('modal'));
if (!$this->show)
EBootstrap::mergeClass($this->htmlOptions, array('hide'));
if ($this->fade)
EBootstrap::mergeClass($this->htmlOptions, array('fade'));
Yii::app()->clientScript->registerCoreScript('jquery');
if (is_null($this->jsFile)) {
$jsFile = dirname(__FILE__).'/js/bootstrap.min.js';
$this->jsFile = Yii::app()->getAssetManager()->publish($jsFile);
Yii::app()->clientScript->registerScriptFile($this->jsFile);
}
elseif ($this->jsFile !== false) {
Yii::app()->clientScript->registerScriptFile($this->jsFile);
}
$backdrop = ($this->backdrop) ? 'true' : 'false';
$keyboard = ($this->keyboard) ? 'true' : 'false';
$show = ($this->show) ? 'true' : 'false';
Yii::app()->clientScript->registerScript('ebootstrap-model-'.$this->htmlOptions['id'], '
$("#'.$this->htmlOptions['id'].'").modal({
backdrop: '.$backdrop.',
keyboard: '.$keyboard.',
show: '.$show.',
});
', CClientScript::POS_READY);
echo EBootstrap::openTag('div', $this->htmlOptions);
echo EBootstrap::openTag('div', array('class' => 'modal-header'));
echo EBootstrap::tag('a', array('class' => 'close', 'data-dismiss' => 'modal', 'href' => '#'), $this->close);
echo EBootstrap::tag('h3', array(), $this->header);
echo EBootstrap::closeTag('div');
echo EBootstrap::openTag('div', array('class' => 'modal-body'));
}
/*
* Render footer
*/
public function run() {
parent::run();
echo EBootstrap::closeTag('div');
echo EBootstrap::openTag('div', array('class' => 'modal-footer'));
foreach ($this->footer as $action) {
echo $action." \n";
}
echo EBootstrap::closeTag('div');
echo EBootstrap::closeTag('div');
}
}
?>