ILIAS  release_8 Revision v8.24
class.ilOverlayGUI.php
Go to the documentation of this file.
1<?php
2
24{
26 protected string $width = "";
27 protected string $height = "";
28 protected bool $fixed_center = false;
29 protected bool $visible = false;
30 protected string $anchor_el_id = "";
31 protected string $anchor_ov_corner = "";
32 protected string $anchor_anch_corner = "";
33 protected bool $auto_hide = false;
34 protected ?string $close_el = null;
35 protected string $trigger_el_id = '';
36 protected string $trigger_event = '';
37 protected ?string $trigger_anchor_el_id = null;
38 protected string $overlay_el_id = '';
39
40 public function __construct(string $a_overlay_el_id)
41 {
42 global $DIC;
43
44 // please check learning modules (e.g. rating) before removing this globals
45 // use (they do not use standard template)
46 $this->tpl = $GLOBALS["tpl"];
47 $this->overlay_el_id = $a_overlay_el_id;
48 }
49
55 public function setAnchor(
56 string $a_anchor_el_id,
57 string $a_ov_corner = "tl",
58 string $a_anch_corner = "bl"
59 ): void {
60 $this->anchor_el_id = $a_anchor_el_id;
61 $this->anchor_ov_corner = $a_ov_corner;
62 $this->anchor_anch_corner = $a_anch_corner;
63 }
64
65 public function setSize(
66 string $a_width = "",
67 string $a_height = ""
68 ): void {
69 $this->width = $a_width;
70 $this->height = $a_height;
71 }
72
73 public function setFixedCenter(bool $a_fixed_center = true): void
74 {
75 $this->fixed_center = $a_fixed_center;
76 }
77
78 public function setVisible(bool $a_visible = true): void
79 {
80 $this->visible = $a_visible;
81 }
82
83 public function setTrigger(
84 string $a_el_id,
85 string $a_event = "click",
86 ?string $a_trigger_anchor_el_id = null
87 ): void {
88 $this->trigger_el_id = $a_el_id;
89 $this->trigger_event = $a_event;
90 $this->trigger_anchor_el_id = $a_trigger_anchor_el_id;
91 }
92
93 public function setAutoHide(bool $a_val): void
94 {
95 $this->auto_hide = $a_val;
96 }
97
98 public function getAutoHide(): bool
99 {
100 return $this->auto_hide;
101 }
102
103 public function setCloseElementId(string $a_val): void
104 {
105 $this->close_el = $a_val;
106 }
107
108 public function getCloseElementId(): string
109 {
110 return $this->close_el;
111 }
112
113 public function getOnLoadCode(): string
114 {
115 // yui cfg string
116 $yuicfg["visible"] = $this->visible;
117
118 if ($this->width !== "") {
119 $yuicfg["width"] = $this->width;
120 }
121
122 if ($this->height !== "") {
123 $yuicfg["height"] = $this->height;
124 }
125 $yuicfg["fixedcenter"] = $this->fixed_center;
126 if ($this->anchor_el_id !== "") {
127 $yuicfg["context"] = array($this->anchor_el_id, $this->anchor_ov_corner,
128 $this->anchor_anch_corner, array("beforeShow", "windowResize"));
129 }
130 // general cfg string
131 $cfg["yuicfg"] = $yuicfg;
132 $cfg["trigger"] = $this->trigger_el_id;
133 $cfg["trigger_event"] = $this->trigger_event;
134 $cfg["anchor_id"] = $this->trigger_anchor_el_id;
135 $cfg["auto_hide"] = $this->auto_hide;
136 $cfg["close_el"] = $this->close_el;
137
138 //var_dump(json_encode($cfg, JSON_THROW_ON_ERROR));
139 return 'il.Overlay.add("' . $this->overlay_el_id . '", ' .
140 json_encode($cfg, JSON_THROW_ON_ERROR) . '); ';
141 }
142
143 public function add(): void
144 {
146 self::initJavascript();
147 $tpl->addOnLoadCode($this->getOnLoadCode());
148 }
149
150 public static function initJavascript(): void
151 {
153 global $DIC;
154
155 $tpl = $DIC->ui()->mainTemplate();
156
158 $tpl->addJavaScript("./Services/UIComponent/Overlay/js/ilOverlay.js");
159 }
160
161 public function getTriggerOnLoadCode(
162 string $a_tr_id,
163 string $a_tr_event,
164 string $a_anchor_el_id,
165 bool $a_center = false,
166 string $a_ov_corner = "tl",
167 string $a_anch_corner = "bl"
168 ): string {
169 $center = ($a_center) ? "true" : "false";
170 return 'il.Overlay.addTrigger("' . $a_tr_id . '","' . $a_tr_event . '","' . $this->overlay_el_id . '","' .
171 $a_anchor_el_id . '", ' . $center . ',"' . $a_ov_corner . '","' . $a_anch_corner . '"); ';
172 }
173
174 public function addTrigger(
175 string $a_tr_id,
176 string $a_tr_event,
177 string $a_anchor_el_id,
178 bool $a_center = false,
179 string $a_ov_corner = "tl",
180 string $a_anch_corner = "bl"
181 ): void {
182 $tpl = $this->tpl;
183
184 self::initJavascript();
185 $tpl->addOnLoadCode($this->getTriggerOnLoadCode(
186 $a_tr_id,
187 $a_tr_event,
188 $a_anchor_el_id,
189 $a_center,
190 $a_ov_corner,
191 $a_anch_corner
192 ));
193 }
194}
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...
setFixedCenter(bool $a_fixed_center=true)
setSize(string $a_width="", string $a_height="")
getTriggerOnLoadCode(string $a_tr_id, string $a_tr_event, string $a_anchor_el_id, bool $a_center=false, string $a_ov_corner="tl", string $a_anch_corner="bl")
setCloseElementId(string $a_val)
__construct(string $a_overlay_el_id)
setTrigger(string $a_el_id, string $a_event="click", ?string $a_trigger_anchor_el_id=null)
string $anchor_anch_corner
string $trigger_anchor_el_id
setVisible(bool $a_visible=true)
setAnchor(string $a_anchor_el_id, string $a_ov_corner="tl", string $a_anch_corner="bl")
ilGlobalTemplateInterface $tpl
addTrigger(string $a_tr_id, string $a_tr_event, string $a_anchor_el_id, bool $a_center=false, string $a_ov_corner="tl", string $a_anch_corner="bl")
setAutoHide(bool $a_val)
static initOverlay(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Overlay module used in Modules/Test, Services/TermsOfService, Services/Tracking,...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41