ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
ilJavaScriptBinding.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  public const PREFIX = "il_ui_fw_";
29 
33  protected array $code = array();
34 
35  public function __construct(
36  private \ILIAS\UICore\GlobalTemplate $global_tpl,
37  ) {
38  }
39 
43  public function createId(): string
44  {
45  return str_replace(".", "_", uniqid(self::PREFIX, true));
46  }
47 
51  public function addOnLoadCode(string $code): void
52  {
53  $this->global_tpl->addOnLoadCode($code, 1);
54  $this->code[] = $code;
55  }
56 
60  public function getOnLoadCodeAsync(): string
61  {
62  if (!count($this->code)) {
63  return '';
64  }
65  $js_out = '<script data-replace-marker="script">' . implode("\n", $this->code) . '</script>';
66  $this->code = [];
67  return $js_out;
68  }
69 }
addOnLoadCode(string $code)
Add some JavaScript-statements to the on-load handler of the page.
createId()
Create a fresh unique id.This MUST return a new id on every call.
array $code
Cache for all registered JS code.
Interface Observer Contains several chained tasks and infos about them.
Wraps global ilTemplate to provide JavaScriptBinding.
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.return all code inside <scr...
Provides methods to interface with javascript.
__construct(private \ILIAS\UICore\GlobalTemplate $global_tpl,)