-
Notifications
You must be signed in to change notification settings - Fork 0
/
EJuiTooltip.php
executable file
·65 lines (60 loc) · 2.03 KB
/
EJuiTooltip.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
Yii::import('zii.widgets.jui.CJuiWidget');
/**
* EJuiTooltip encapsulates jQuery UI Tooltip plugin.
*
* Example usage:
* $this->widget('EJuiTooltip', array(
* // elements selector, by default their title attribute will be used as content
* 'selector' => '.tooltip',
* // additional javascript options for the tooltip plugin
* 'options' => array(
* 'scope' => 'myScope',
* ),
* ));
*
* By configuring the options property, you may specify the options
* that need to be passed to the JUI Tooltip plugin. Please refer to
* the official {@link http://jqueryui.com/demos/tooltip/} documentation
* for possible options (name-value pairs).
*/
class EJuiTooltip extends CJuiWidget
{
/**
* @var string Tooltip selector, defaults to document (all elements with title attribute
* will have tooltip with the title attribute content used as tooltip content)
*/
public $selector = 'document';
/**
* Renders the close tag of the draggable element.
*/
public function run()
{
Yii::app()->clientScript->registerScript(__CLASS__ . $this->selector,
self::getJavascriptString($this->selector, $this->options)
);
}
/**
* @param $selector
* @param array $options
* @return string
*/
public static function getJavascriptString($selector, array $options = [])
{
if (!isset($options['content'])) {
$options['content'] = 'js: function() { return $(this).prop("title"); }';
}
$options = CJavaScript::encode($options);
return "$('{$selector}').tooltip($options)";
}
/**
* Helper method for afterAjaxUpdate calls
* @param $selector
* @param array $options
* @return CJavaScriptExpression
*/
public static function getJavascriptFunction($selector, array $options = [])
{
return new CJavaScriptExpression(sprintf('function () { %s }', self::getJavascriptString($selector, $options)));
}
}