ILIAS  release_7 Revision v7.30-3-g800a261c036
with_additional_on_load_code.php File Reference

Go to the source code of this file.

Functions

 with_additional_on_load_code ()
 Example showing how JS-Code can be attached to images. More...
 

Function Documentation

◆ with_additional_on_load_code()

with_additional_on_load_code ( )

Example showing how JS-Code can be attached to images.

In this example, an alert is poping up a soon as the image is clicked.

Definition at line 7 of file with_additional_on_load_code.php.

8{
9 //Loading factories
10 global $DIC;
11 $f = $DIC->ui()->factory();
12 $renderer = $DIC->ui()->renderer();
13
14 //Genarating and rendering the image and modal
15 $image = $f->image()->standard(
16 "src/UI/examples/Image/HeaderIconLarge.svg",
17 "Thumbnail Example"
18 )->withAction("#")
19 ->withAdditionalOnLoadCode(function ($id) {
20 return "$('#$id').click(function(e) { e.preventDefault(); alert('Image Onload Code')});";
21 });
22
23 $html = $renderer->render($image);
24
25 return $html;
26}
global $DIC
Definition: goto.php:24

References $DIC, and Vendor\Package\$f.