ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilJavaScriptBinding.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
11{
12 const PREFIX = "il_ui_fw_";
13
17 private $global_tpl;
18
24 protected $code = array();
25
27 {
28 $this->global_tpl = $global_tpl;
29 }
30
34 public function createId()
35 {
36 return str_replace(".", "_", uniqid(self::PREFIX, true));
37 }
38
42 public function addOnLoadCode($code)
43 {
44 $this->global_tpl->addOnLoadCode($code);
45 $this->code[] = $code;
46 }
47
51 public function getOnLoadCodeAsync()
52 {
53 if (!count($this->code)) {
54 return '';
55 }
56 $js_out = '<script data-replace-marker="script">' . implode("\n", $this->code) . '</script>';
57 $this->code = [];
58 return $js_out;
59 }
60}
An exception for terminatinating execution or to throw for unit testing.
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...
addOnLoadCode($code)
Add some JavaScript-statements to the on-load handler of the page.null
createId()
Create a fresh unique id.This MUST return a new id on every call.string
special template class to simplify handling of ITX/PEAR
Provides methods to interface with javascript.