19declare(strict_types=1);
46 $tpl = $this->
getTemplate(
"tpl.image.html",
true,
true);
48 if (($sources = $component->getAdditionalHighResSources()) !== []) {
49 $component = $component->withAdditionalOnLoadCode(
50 fn(
string $id):
string =>
"
51 const imageElement = il.UI.image.getImageElement('$id');
52 if (imageElement === null) {
53 throw new Error(`Image '$id' not found.`);
55 il.UI.image.loadHighResolutionSource(
57 {$this->getHighResSourceMapForJs($sources)}
64 if (!empty($component->getAction())) {
65 $tpl->touchBlock(
"action_begin");
67 if (is_string($component->getAction())) {
68 $tpl->setCurrentBlock(
"with_href");
69 $tpl->setVariable(
"HREF", $component->getAction());
70 $tpl->parseCurrentBlock();
73 if (is_array($component->getAction())) {
74 $tpl->setCurrentBlock(
"with_href");
75 $tpl->setVariable(
"HREF",
"#");
76 $tpl->parseCurrentBlock();
77 $tpl->setCurrentBlock(
"with_id");
78 $tpl->setVariable(
"ID",
$id);
79 $tpl->parseCurrentBlock();
83 if (!is_array($component->getAction()) &&
$id !==
null) {
84 $tpl->setVariable(
"IMG_ID",
" id='" .
$id .
"' ");
87 $tpl->setCurrentBlock($component->getType());
88 $tpl->setVariable(
"SOURCE", $component->getSource());
89 $tpl->setVariable(
"ALT", htmlspecialchars($component->getAlt()));
90 $tpl->parseCurrentBlock();
92 if (!empty($component->getAction())) {
93 $tpl->touchBlock(
"action_end");
104 parent::registerResources($registry);
105 $registry->
register(
'assets/js/image.min.js');
114 foreach (
$resources as $min_width => $source) {
115 $map_entries .=
"[$min_width, '$source'],\n";
118 return "new Map([\n$map_entries])";
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getHighResSourceMapForJs(array $resources)
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Base class for all component renderers.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
addTriggererOnLoadCode(Triggerer $triggerer)
Add onload-code for triggerer.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
An entity that renders components to a string output.