forked from plesk/yii2-pjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.php
46 lines (40 loc) · 1.18 KB
/
Component.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
<?php
// Copyright 2017. Plesk International GmbH.
namespace plesk\yii2pjax;
use Yii;
use yii\base\Component as YiiComponent;
/**
* Convert PJAX config from Yii2 widget format to JS format.
* <code>
* $this->registerJs(
* '$("#plesk-pjax-search-form").on("pjax:success", function() {
* $.pjax.reload(' . Json::encode(Yii::$app->pjax->pjaxConvertConfigWidgetToJs($gridPjaxOptions)) . ');
* });'
* );
* </code>
*/
class Component extends YiiComponent
{
/**
* @var array
*/
public $pjaxConfigMapWidgetJs = [
'enablePushState' => 'push',
'enableReplaceState' => 'replace',
'timeout' => 'timeout',
'scrollTo' => 'scrollTo',
];
public function pjaxConvertConfigWidgetToJs($widgetConfig)
{
$jsConfig = [];
foreach ($this->pjaxConfigMapWidgetJs as $widgetOption => $jsOption) {
if (isset($widgetConfig[$widgetOption])) {
$jsConfig[$jsOption] = $widgetConfig[$widgetOption];
}
}
$jsConfig['container'] = isset($widgetConfig['container']) ?
$widgetConfig['container'] :
"#{$widgetConfig['id']}";
return $jsConfig;
}
}