ILIAS  release_8 Revision v8.24
ilJavaScriptBinding.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24
29{
30 public const PREFIX = "il_ui_fw_";
31
33
37 protected array $code = array();
38
40 {
41 $this->global_tpl = $global_tpl;
42 }
43
47 public function createId(): string
48 {
49 return str_replace(".", "_", uniqid(self::PREFIX, true));
50 }
51
55 public function addOnLoadCode(string $code): void
56 {
57 $this->global_tpl->addOnLoadCode($code, 1);
58 $this->code[] = $code;
59 }
60
64 public function getOnLoadCodeAsync(): string
65 {
66 if (!count($this->code)) {
67 return '';
68 }
69 $js_out = '<script data-replace-marker="script">' . implode("\n", $this->code) . '</script>';
70 $this->code = [];
71 return $js_out;
72 }
73}
Wraps global ilTemplate to provide JavaScriptBinding.
__construct(ilGlobalTemplateInterface $global_tpl)
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.return all code inside <scr...
createId()
Create a fresh unique id.This MUST return a new id on every call.
array $code
Cache for all registered JS code.
addOnLoadCode(string $code)
Add some JavaScript-statements to the on-load handler of the page.
Provides methods to interface with javascript.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...