-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTelex.php
More file actions
56 lines (43 loc) · 1.19 KB
/
Telex.php
File metadata and controls
56 lines (43 loc) · 1.19 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
<?php
/**
* MIT licence
* Version 1.0.1
* Sjaak Priester, Amsterdam 22-09-2015 ... .
*
* News scroller widget for Yii 2.0 framework
*/
namespace sjaakp\telex;
use yii\base\Widget;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\Json;
class Telex extends Widget {
/**
* @var array
* Client options for the Telex jQuery widget.
* @link https://github.com/sjaakp/telex
*/
public $options = [];
/**
* @var array
* HTML options of the dateline container.
* Use this if you want to explicitly set the ID.
*/
public $htmlOptions = [];
public function init() {
if (isset($this->htmlOptions['id'])) {
$this->setId($this->htmlOptions['id']);
}
else $this->htmlOptions['id'] = $this->getId();
}
public function run() {
$view = $this->getView();
$asset = new TelexAsset();
$asset->register($view);
$jOpts = count($this->options) ? Json::encode($this->options) : '{}';
$id = $this->getId();
$js = "var {$id}=$('#{$id}').telex($jOpts);";
$view->registerJs($js);
echo Html::tag('div', '', $this->htmlOptions);
}
}