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