-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTopBar.php
96 lines (75 loc) · 2.08 KB
/
TopBar.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
<?php
/**
* @copyright Copyright © Digisin soc. coop, digisin.it 2014
* @package nonzod/yii2-foundation
* @version 1.0.0
*/
namespace nonzod\foundation;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
* Description of TopBar
*
* @author Nicola Tomassoni <[email protected]>
*/
class TopBar extends Widget {
/**
* @var array
* @see http://foundation.zurb.com/docs/components/topbar.html
*/
public $options;
/**
* @var array
* @see http://foundation.zurb.com/docs/components/topbar.html#positioning-the-bar
*/
public $containerOptions = [];
public $titleLabel;
public $titleUrl;
public $titleOptions = [];
public $toggleText = 'Menu';
public $showToggleIcon = true;
public $toggleOptions = ['class' => 'toggle-topbar'];
/**
*
*/
public function init() {
parent::init();
Html::addCssClass($this->options, 'top-bar');
if (empty($this->options['role'])) {
$this->options['role'] = 'navigation';
}
$this->options['data-topbar'] = 1;
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'nav');
if (!empty($this->containerOptions)) {
echo Html::beginTag('div', $this->containerOptions);
}
echo Html::beginTag($tag, $options);
echo Html::tag('ul', implode("\n", $this->headerItems()), ['class' => 'title-area']);
}
/**
*
*/
public function run() {
$tag = ArrayHelper::remove($this->options, 'tag', 'nav');
echo Html::endTag($tag);
if (!empty($this->containerOptions)) {
echo Html::endTag('div');
}
$this->registerPlugin('topbar');
}
/**
*
*/
protected function headerItems() {
Html::addCssClass($this->titleOptions, 'name');
$title = !empty($this->titleLabel) ? Html::tag('h1', Html::a($this->titleLabel, $this->titleUrl)) : '';
if ($this->showToggleIcon) {
Html::addCssClass($this->toggleOptions, 'menu-icon');
}
return [
Html::tag('li', $title, $this->titleOptions),
Html::tag('li', Html::a(Html::tag('span', $this->toggleText), '#'), $this->toggleOptions)
];
}
}