ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\UI\Implementation\Render\ilJavaScriptBinding Class Reference

Wraps global ilTemplate to provide JavaScriptBinding. More...

+ Inheritance diagram for ILIAS\UI\Implementation\Render\ilJavaScriptBinding:
+ Collaboration diagram for ILIAS\UI\Implementation\Render\ilJavaScriptBinding:

Public Member Functions

 __construct (private \ILIAS\UICore\GlobalTemplate $global_tpl,)
 
 createId ()
 Create a fresh unique id.This MUST return a new id on every call. More...
 
 addOnLoadCode (string $code)
 Add some JavaScript-statements to the on-load handler of the page. More...
 
 getOnLoadCodeAsync ()
 Get all the registered on-load javascript code for the async context, e.g.return all code inside <script> tags More...
 
 clearOnLoadCodeAsync ()
 Clears all JavaScript code currently registered for the async context. More...
 
 createId ()
 Create a fresh unique id. More...
 
 addOnLoadCode (string $code)
 Add some JavaScript-statements to the on-load handler of the page. More...
 
 getOnLoadCodeAsync ()
 Get all the registered on-load javascript code for the async context, e.g. More...
 
 clearOnLoadCodeAsync ()
 Clears all JavaScript code currently registered for the async context. More...
 

Data Fields

const PREFIX = "il_ui_fw_"
 

Protected Attributes

array $code = array()
 Cache for all registered JS code. More...
 

Detailed Description

Wraps global ilTemplate to provide JavaScriptBinding.

Definition at line 26 of file ilJavaScriptBinding.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\UI\Implementation\Render\ilJavaScriptBinding::__construct ( private \ILIAS\UICore\GlobalTemplate  $global_tpl)

Definition at line 35 of file ilJavaScriptBinding.php.

37 {
38 }

Member Function Documentation

◆ addOnLoadCode()

ILIAS\UI\Implementation\Render\ilJavaScriptBinding::addOnLoadCode ( string  $code)

Add some JavaScript-statements to the on-load handler of the page.

Implements ILIAS\UI\Implementation\Render\JavaScriptBinding.

Definition at line 51 of file ilJavaScriptBinding.php.

51 : void
52 {
53 $this->global_tpl->addOnLoadCode($code, 1);
54 $this->code[] = $code;
55 }
array $code
Cache for all registered JS code.

References ILIAS\UI\Implementation\Render\ilJavaScriptBinding\$code.

◆ clearOnLoadCodeAsync()

ILIAS\UI\Implementation\Render\ilJavaScriptBinding::clearOnLoadCodeAsync ( )

Clears all JavaScript code currently registered for the async context.

This is necessary because rendering can register JavaScript as a side effect, even when the rendered output is not required by the current async endpoint.

This is caused by ILIAS treating controllers as independent layers, meaning a controller cannot reliably determine what has been executed before it, while each layer may contribute parts of the page. This causes unnecessary rendering and JavaScript registration. This method prevents said JavaScript from leaking into the async response.

This is a reminder that we want proper routing inside ILIAS: https://docu.ilias.de/go/wiki/wpage_8780_1357

Implements ILIAS\UI\Implementation\Render\JavaScriptBinding.

Definition at line 69 of file ilJavaScriptBinding.php.

69 : void
70 {
71 $this->code = [];
72 }

◆ createId()

ILIAS\UI\Implementation\Render\ilJavaScriptBinding::createId ( )

Create a fresh unique id.This MUST return a new id on every call.

Implements ILIAS\UI\Implementation\Render\JavaScriptBinding.

Definition at line 43 of file ilJavaScriptBinding.php.

43 : string
44 {
45 return str_replace(".", "_", uniqid(self::PREFIX, true));
46 }

◆ getOnLoadCodeAsync()

ILIAS\UI\Implementation\Render\ilJavaScriptBinding::getOnLoadCodeAsync ( )

Get all the registered on-load javascript code for the async context, e.g.return all code inside <script> tags

Implements ILIAS\UI\Implementation\Render\JavaScriptBinding.

Definition at line 60 of file ilJavaScriptBinding.php.

60 : string
61 {
62 if (!count($this->code)) {
63 return '';
64 }
65 $js_out = '<script data-replace-marker="script">' . implode("\n", $this->code) . '</script>';
66 return $js_out;
67 }

Field Documentation

◆ $code

array ILIAS\UI\Implementation\Render\ilJavaScriptBinding::$code = array()
protected

Cache for all registered JS code.

Definition at line 33 of file ilJavaScriptBinding.php.

Referenced by ILIAS\UI\Implementation\Render\ilJavaScriptBinding\addOnLoadCode().

◆ PREFIX

const ILIAS\UI\Implementation\Render\ilJavaScriptBinding::PREFIX = "il_ui_fw_"

Definition at line 28 of file ilJavaScriptBinding.php.


The documentation for this class was generated from the following file: