ILIAS  release_8 Revision v8.24
class.ilTooltipGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected static bool $initialized = false;
26 protected static bool $library_initialized = false;
27
28 public static function addTooltip(
29 string $a_el_id,
30 string $a_text,
31 string $a_container = "",
32 string $a_my = "bottom center",
33 string $a_at = "top center",
34 bool $a_use_htmlspecialchars = true
35 ): void {
36 // to get rid of globals here, we need to change the
37 // process in learning modules, e.g. which does not work with $DIC (since it does not
38 // use the standard template)
39 $tpl = $GLOBALS["tpl"];
40
41 self::init();
42
43 $code = self::getToolTip(
44 $a_el_id,
45 $a_text,
46 $a_container,
47 $a_my,
48 $a_at,
49 $a_use_htmlspecialchars
50 );
51 $tpl->addOnLoadCode($code);
52 }
53
57 public static function getToolTip(
58 string $a_el_id,
59 string $a_text,
60 string $a_container = "",
61 string $a_my = "bottom center",
62 string $a_at = "top center",
63 bool $a_use_htmlspecialchars = true
64 ): string {
65 $addstr = "";
66
67 // not needed, just make sure the position plugin is included
68 // $addstr.= ", position: {viewport: $('#fixed_content')}";
69
70 if ($a_container !== "") {
71 $addstr .= ", container: '" . $a_container . "'";
72 }
73
74 if ($a_use_htmlspecialchars) {
75 $a_text = htmlspecialchars(str_replace(array("\n", "\r"), "", $a_text));
76 } else {
77 $a_text = str_replace(array("\n", "\r", "'", '"'), array("", "", "\'", '\"'), $a_text);
78 }
79 return 'il.Tooltip.add("' . $a_el_id . '", {' .
80 ' context:"' . $a_el_id . '",' .
81 ' my:"' . $a_my . '",' .
82 ' at:"' . $a_at . '",' .
83 ' text:"' . $a_text . '" ' . $addstr . '} );';
84 }
85
89 public static function init(): void
90 {
91 // for globals use, see comment above
92 $tpl = $GLOBALS["tpl"];
93
94 if (!self::$initialized) {
95 $tpl->addCss("./node_modules/qtip2/dist/jquery.qtip.min.css");
96 $tpl->addJavascript("./node_modules/qtip2/dist/jquery.qtip.min.js");
97 $tpl->addJavascript("./Services/UIComponent/Tooltip/js/ilTooltip.js");
98
99 // use setTimeout as a workaround, since the last parameter is ignored
100 $tpl->addOnLoadCode('setTimeout(function() {il.Tooltip.init();}, 500);', 3);
101 self::$initialized = true;
102 }
103 }
104}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static bool $initialized
static bool $library_initialized
static addTooltip(string $a_el_id, string $a_text, string $a_container="", string $a_my="bottom center", string $a_at="top center", bool $a_use_htmlspecialchars=true)
static getToolTip(string $a_el_id, string $a_text, string $a_container="", string $a_my="bottom center", string $a_at="top center", bool $a_use_htmlspecialchars=true)
Get tooltip js code.
static init()
Initializes the needed tooltip libraries.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41