YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Alert
  • Breadcrumbs
  • Clearing
  • Dropdown
  • FlexVideo
  • Interchange
  • JoyRide
  • Magellan
  • Orbit
  • Pager
  • Reveal
  • Section
  • SwitchButton
  • Tooltip
  • TopBar
 1 <?php
 2 /**
 3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
 4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 5  * @package foundation.components
 6  * @version 1.0.0
 7  */
 8 namespace foundation\widgets;
 9 
10 use foundation\helpers\ArrayHelper;
11 use foundation\helpers\Html;
12 use foundation\enum\Enum;
13 
14 /**
15  * Tooltip renders Foundation tooltips
16  *
17  * @see http://foundation.zurb.com/docs/components/reveal.html
18  *
19  * @author Antonio Ramirez <amigo.cobos@gmail.com>
20  * @package foundation\widgets
21  */
22 class Tooltip extends base\Widget
23 {
24     /**
25      * @var string the tooltip text
26      */
27     public $tip;
28     /**
29      * @var string the text that will trigger the tooltip on hover
30      */
31     public $text;
32     /**
33      * @var string the position of the tooltip
34      */
35     public $position = Enum::TOOLTIP_TOP;
36     /**
37      * @var array the options of the plugin. For more information, see
38      * http://foundation.zurb.com/docs/components/tooltips.html
39      */
40     public $pluginOptions = array();
41 
42 
43     /**
44      * Initializes the widget
45      */
46     public function init()
47     {
48         $this->assets = array(
49             'js' => YII_DEBUG ? 'foundation/foundation.tooltips.js' : 'foundation.min.js'
50         );
51 
52         Html::addCssClass($this->htmlOptions, Enum::TOOLTIP);
53         Html::addCssClass($this->htmlOptions, $this->position);
54         ArrayHelper::addValue('title', $this->tip, $this->htmlOptions);
55         ArrayHelper::addValue('data-tooltip', 'data-tooltip', $this->htmlOptions);
56         if ($this->tip === null || $this->text === null) {
57             throw new InvalidConfigException('"tip" and "text" cannot be null.');
58         }
59         $this->registerClientScript();
60 
61         parent::init();
62     }
63 
64     /**
65      * Renders the widget
66      */
67     public function run()
68     {
69         echo $this->renderTooltip();
70     }
71 
72     /**
73      * Returns the tooltip tag
74      * @return string the rendering result
75      */
76     public function renderTooltip()
77     {
78         return \CHtml::tag('span', $this->htmlOptions, $this->text);
79     }
80 
81     /**
82      * Registers plugin options and events (if any)
83      */
84     public function registerClientScript()
85     {
86         if (!empty($this->pluginOptions)) {
87             $options = \CJavaScript::encode($this->pluginOptions);
88             \Yii::app()->clientScript
89                 ->registerScript('Tooltip#' . $this->getId(), "$(document).foundation('tooltip', {$options});");
90         }
91     }
92 }
YiiFoundation API documentation generated by ApiGen 2.8.0