/
Persisthide.php
48 lines (38 loc) · 1.18 KB
/
Persisthide.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
<?php
namespace stivehu\persisthide;
/**
* This is just an example.
*/
class Persisthide extends \yii\base\Widget
{
public $id = 'hiddendiv';
private $_tag;
public function init($tag = 'div')
{
Asserts::register($this->getView());
$this->_tag = $tag;
\Yii::$app->view->registerJs('var persisthide = "' . $this->id . '"', \yii\web\View::POS_HEAD);
parent::init();
}
public function showButton($content, $options = null)
{
$options['id'] = isset($options['id']) ? $options['id'] : $this->id . "button";
$options['onclick'] = 'setVisible();';
return \yii\bootstrap\Html::button($content, $options);
}
public function beginTag($options = [])
{
$options['id'] = isset($options['id']) ? $options['id'] : $this->id;
$persisthide = \stivehu\enhancedcookie\EnhancedCookie::getBigCookie($this->id);
$options['style'] = ($persisthide === '1') ? '' : 'display:none';
return \yii\helpers\Html::beginTag($this->_tag, $options);
}
public function endTag()
{
return \yii\helpers\Html::endTag($this->_tag);
}
public function run()
{
return;
}
}