forked from YL20181120/yii2-dwz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tabs.php
64 lines (59 loc) · 1.66 KB
/
Tabs.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
<?php
namespace yii\dwz;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
*
*/
class Tabs extends Widget
{
public $items;
public $currentIndex = 0;
public $eventType = 'click';
public $contentStyle = '';
private $headers = [];
private $contents = [];
public function init(){
parent::init();
$this->options['class'] = 'tabs';
$this->options['currentIndex'] = $this->currentIndex;
$this->options['eventType'] = $this->eventType;
echo Html::beginTag('div',$this->options);
}
public function run(){
echo $this->render();
echo Html::tag('div',Html::tag('div','',['class' => 'tabsFooterContent']),['class' => 'tabsFooter']);
echo Html::endTag('div');
}
public function render(){
$this->renderItems();
$tabs = '';
echo Html::beginTag('div',['class'=>'tabsHeader']);
echo Html::beginTag('div',['class'=>'tabsHeaderContent']);
echo Html::beginTag('ul');
echo implode('',$this->headers);
echo Html::endTag('ul');
echo Html::endTag('div');
echo Html::endTag('div');
echo Html::beginTag('div',['class'=>'tabsContent','style'=>$this->contentStyle]);
echo implode('',$this->contents);
echo Html::endTag('div');
}
protected function renderItems(){
foreach ($this->items as $v) {
$tab = new Tab($v);
$this->headers[] = $this->renderHeader($tab->title,$tab->url);
$this->contents[]= $this->renderContent($tab->content);
}
}
protected function renderHeader($title,$url){
if(empty($url))
$url = 'javascript:;';
else
$this->options['class'] = 'j-ajax';
return Html::tag('li',Html::a(Html::tag('span',$title),$url,$this->options));
}
protected function renderContent($content){
return Html::tag('div',$content);
}
}