YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhTimeAgo
  • WhTimeAgoFormatter
 1 <?php
 2 /**
 3  * WhTimeAgo class
 4  *
 5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 6  * @copyright Copyright &copy; 2amigos.us 2013-
 7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 8  * @package YiiWheels.widgets.timeago
 9  * @uses YiiStrap.helpers.TbArray
10  */
11 Yii::import('bootstrap.helpers.TbArray');
12 
13 class WhTimeAgo extends CWidget
14 {
15     /**
16      * @var string the HTML tag type
17      */
18     public $tagName = 'abbr';
19 
20     /**
21      * @var array additional HTML attributes to the tag
22      */
23     public $htmlOptions = array();
24 
25     /**
26      * @var array plugin options
27      */
28     public $pluginOptions = array();
29 
30     /**
31      * @var string the language
32      * @see js/locales
33      */
34     public $language = 'en';
35 
36     /**
37      * @var string the selector to initialize the widget. Defaults to widget id.
38      */
39     public $selector;
40 
41     /**
42      * @var string the date to use the timeago against. If null, the widget will not render the tag, assuming that
43      * everything will be handled via the $selector.
44      */
45     public $date;
46 
47     /**
48      * Widget's initialization method
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      * Widget's run method
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, '&nbsp;');
70         }
71         $this->registerClientScript();
72     }
73 
74     /**
75      * Registers required client script for sparklines
76      */
77     public function registerClientScript()
78     {
79         /* publish assets dir */
80         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
81         $assetsUrl = $this->getAssetsUrl($path);
82 
83         /* @var $cs CClientScript */
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         /* initialize plugin */
93         $this->getApi()->registerPlugin('timeago', $this->selector, $this->pluginOptions);
94     }
95 
96 }
YiiWheels API documentation generated by ApiGen 2.8.0