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