-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widget.php
73 lines (64 loc) · 1.85 KB
/
Widget.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
<?php
/**
* @link http://foundationize.com
* @package shqear/yii2-foundation6
* @version dev
*/
namespace shqear\foundation6;
use yii\helpers\Json;
/**
* Description of Widget
*
* @since 0.0.1
* @see
*/
class Widget extends \yii\base\Widget
{
/**
* @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* @var array Specific options of the Foundation plugin in use.
* @see http://foundation.zurb.com/docs/javascript.html
*/
public $clientOptions = [];
/**
* @var array Specific methods to call
* @see http://foundation.zurb.com/docs/javascript.html
*/
public $clientFireMethods = [];
/**
* Initialize the widget
*/
public function init()
{
parent::init();
if (empty($this->options['id'])) {
$this->options['id'] = $this->getId();
}
}
/**
* @deprecated (not mentioned in foundation6 docs)<br>
* Registers a specific Foundation plugin and call related methods
* @param string $name the name of the Foundation plugin
*/
protected function registerPlugin($name = '')
{
$view = $this->getView();
//$id = $this->options['id'];
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "$(document).foundation({ '$name' : { $options } });";
$view->registerJs($js);
}
if (!empty($this->clientFireMethods)) {
$js = [];
foreach ($this->clientFireMethods as $method) {
$js[] = "$(document).foundation('$name', '$method');";
}
$view->registerJs(implode("\n", $js));
}
}
}