-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathInfiniteScrollPager.php
60 lines (50 loc) · 1.62 KB
/
InfiniteScrollPager.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
<?php
namespace darkcs\infinitescroll;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\widgets\LinkPager;
class InfiniteScrollPager extends LinkPager
{
public $containerSelector = '.list-view';
public $itemSelector = '.item';
public $paginationSelector = '.pagination';
public $nextSelector = '.pagination .next a:first';
public $wrapperSelector = '.list-view';
public $bufferPx = 40;
public $pjaxContainer = null;
public $autoStart = true;
public $alwaysHidePagination = true;
// опции jquery плагина напрямую
public $pluginOptions = [];
public function init()
{
$default = [
'pagination' => $this->paginationSelector,
'next' => $this->nextSelector,
'item' => $this->itemSelector,
'state' => [
'isPaused' => !$this->autoStart,
],
'pjax' => [
'container' => $this->pjaxContainer,
],
'bufferPx' => $this->bufferPx,
'wrapper' => $this->wrapperSelector,
'alwaysHidePagination' => $this->alwaysHidePagination,
];
$this->pluginOptions = ArrayHelper::merge($default, $this->pluginOptions);
InfiniteScrollAsset::register($this->view);
$this->initInfiniteScroll();
parent::init();
}
public function run()
{
parent::run();
}
public function initInfiniteScroll()
{
$options = Json::encode($this->pluginOptions);
$js = "$('{$this->containerSelector}').infinitescroll({$options});";
$this->view->registerJs($js);
}
}