1 <?php
2 3 4 5 6 7 8 9 10
11 Yii::import('bootstrap.helpers.TbArray');
12
13 class WhTimeAgo extends CWidget
14 {
15 16 17
18 public $tagName = 'abbr';
19
20 21 22
23 public $htmlOptions = array();
24
25 26 27
28 public $pluginOptions = array();
29
30 31 32 33
34 public $language = 'en';
35
36 37 38
39 public $selector;
40
41 42 43 44
45 public $date;
46
47 48 49
50 public function init()
51 {
52 $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
53
54 $this->htmlOptions['id'] = TbArray::getValue('id', $this->htmlOptions, $this->getId());
55
56 if (!$this->selector) {
57 $this->selector = '#' . TbArray::getValue('id', $this->htmlOptions);
58 }
59
60 }
61
62 63 64
65 public function run()
66 {
67 if (null !== $this->date) {
68 $this->htmlOptions['title'] = $this->date;
69 echo CHtml::tag($this->tagName, $this->htmlOptions, ' ');
70 }
71 $this->registerClientScript();
72 }
73
74 75 76
77 public function registerClientScript()
78 {
79
80 $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
81 $assetsUrl = $this->getAssetsUrl($path);
82
83
84 $cs = Yii::app()->getClientScript();
85
86 $cs->registerScriptFile($assetsUrl . '/js/jquery.timeago.js');
87
88 if (null !== $this->language) {
89 $cs->registerScriptFile($assetsUrl . '/js/locales/jquery.timeago.' . $this->language . '.js');
90 }
91
92
93 $this->getApi()->registerPlugin('timeago', $this->selector, $this->pluginOptions);
94 }
95
96 }