-
Notifications
You must be signed in to change notification settings - Fork 1
/
Isotope.php
75 lines (67 loc) · 1.83 KB
/
Isotope.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
<?php
namespace devleaks\metafizzy;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\base\Widget;
/**
* Asset Widget based to load Isotope JavaScript library {@link http://isotope.metafizzy.co)
* @package devleaks\metafizzy
*
* @author Pierre M <[email protected]>
*/
class Isotope extends Widget {
/**
* @var array the HTML attributes for the div tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* @var array Plugin options
*/
public $pluginOptions = [
'itemSelector' => '.item',
'layoutMode' => 'fitRows'
];
/**
* Initializes the object.
* This method is invoked at the end of the constructor after the object is initialized with the
* given configuration.
*/
public function init()
{
//checks for the element id
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
parent::init();
}
/**
* Render chosen select
* @return string|void
*/
public function run()
{
echo Html::beginTag('div', $this->options); //opens the container
echo Html::endTag('div'); //closes the container, opened on init
$this->registerAssets();
}
/**
* Register client assets
*/
protected function registerAssets()
{
$view = $this->getView();
IsotopeAsset::register($view);
$js = '$("#' . $this->options['id'] . '").isotope(' . $this->getPluginOptions() . ');';
$view->registerJs($js, $view::POS_END);
}
/**
* Return plugin options in json format
* @return string
*/
public function getPluginOptions()
{
return Json::encode($this->pluginOptions);
}
}