-
Notifications
You must be signed in to change notification settings - Fork 11
/
ToastrAjaxFeed.php
46 lines (41 loc) · 1.2 KB
/
ToastrAjaxFeed.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 Copyright © Odai Alali 2014
* @package yii2-toastr
* @version 0.1-dev
*/
namespace odaialali\yii2toastr;
use odaialali\yii2toastr\ToastrAjaxFeedAsset;
use yii\helpers\Json;
/**
* Description of ToastrAjaxFeed
*
* @author Odai Alali <[email protected]>
*/
class ToastrAjaxFeed extends \yii\base\Widget {
public $customStyle = true;
public $options = [];
public $feedUrl = '';
public $interval = 6000;
public function init() {
parent::init();
if($this->customStyle){
ToastrCustomAsset::register($this->getView());
}else{
ToastrAsset::register($this->getView());
}
}
public function run() {
parent::run();
$view = $this->getView();
$options = empty($this->options) ? '[]' : Json::encode($this->options);
ToastrAjaxFeedAsset::register($view);
$view->registerJs('jQuery(document).ready( function() {'
. 'setInterval('
. 'function(){'
. 'ToastrAjaxFeed.getNotifications(\''.$this->feedUrl.'\', '.$options.')'
. '}'
. ','
. $this->interval.');} );');
}
}