-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWidget.php
71 lines (61 loc) · 1.77 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
<?php
/**
* @copyright Copyright © Digisin soc. coop, digisin.it 2014
* @package nonzod/yii2-foundation
* @version dev
*/
namespace nonzod\foundation;
/**
* Description of Widget
*
* @author Nicola Tomassoni <[email protected]>
* @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();
}
}
/**
* Registers a specific Foundation plugin and call related methods
* @param string $name the name of the Foundation plugin
* @todo far caricare solo i js dei plugin in uso
*/
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));
}
}
}