-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPjaxIndicator.php
More file actions
61 lines (57 loc) · 1.63 KB
/
PjaxIndicator.php
File metadata and controls
61 lines (57 loc) · 1.63 KB
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
<?php
/**
* @copyright Copyright (c) 2016 Ilya Shumilov
* @version 1.1.3
* @link https://github.com/restlin/PjaxIndicator
*/
namespace restlin\pjaxindicator;
use yii\helpers\Html;
use Yii;
/**
* Simple class showing the "Loading" message when pjax loads data
* For translations add file "messages/ru/app.php" (replace "ru" for your language) with code:
*
* ```php
* return [
* 'Loading! Please, wait...' => 'Загрузка! Подождите, пожалуйста...'
* ];
* ```
*
* @author Ilya Shumilov <restlinru@yandex.ru>
*/
class PjaxIndicator extends \yii\widgets\Pjax
{
/**
* Message, that show when pjax loading data.
* @var string
*/
public $message = 'Loading! Please, wait...';
/**
* CSS style of indicator's container
* @var string
*/
public $cssStyle = 'position:fixed; left:45%; top:45%; width:200px; height:30px; z-index:100; display:none; padding: 2px; color: #fff; text-align:center';
/**
* @inheritdoc
*/
public function run()
{
echo Html::tag('div',Yii::t('app', $this->message),[
'class' => 'navbar-inverse navbar pjax-indicator',
'style' => $this->cssStyle,
]);
parent::run();
}
/**
* Registers the needed JavaScript.
*/
public function registerClientScript()
{
$view = $this->getView();
$js = '$(document)'
. '.on("pjax:send",function(){$(".pjax-indicator").show();})'
. '.on("pjax:complete",function(){$(".pjax-indicator").hide();});';
$view->registerJs($js);
parent::registerClientScript();
}
}