ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
with_js.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
40function with_js()
41{
42 global $DIC;
43 $f = $DIC->ui()->factory();
44 $renderer = $DIC->ui()->renderer();
45
46 //Note that both counters have to be present to perform JS actions on them
47 $like = $f->symbol()->glyph()->love("#")
48 ->withCounter($f->counter()->novelty(3))
49 ->withCounter($f->counter()->status(0));
50
51 $set_status_button = $f->button()->bulky($like, "Set Status Counter to 10 on click.", "#")
52 ->withAdditionalOnLoadCode(
53 function ($id) {
54 return "
55 $(\"#$id\").click(function() {
56 il.UI.counter.getCounterObject($(this)).setStatusTo(10);
57 });";
58 }
59 );
60
61 $increment_novelty_button = $f->button()->bulky($like, "Increment Novelty Counter by on click", "#")
62 ->withAdditionalOnLoadCode(
63 function ($id) {
64 return "
65 $(\"#$id\").click(function() {
66 il.UI.counter.getCounterObject($(this)).incrementNoveltyCount(1);
67 });";
68 }
69 );
70
71 $set_novelty_count_to_status_button = $f->button()->bulky($like, "Set Novelty Count to status on click", "#")
72 ->withAdditionalOnLoadCode(
73 function ($id) {
74 return "
75 $(\"#$id\").click(function() {
76 il.UI.counter.getCounterObject($(this)).setTotalNoveltyToStatusCount(1);
77 });";
78 }
79 );
80
81 //What will the value of Status be after click?
82 $combined_button = $f->button()->bulky($like, "Some chained actions", "#")
83 ->withAdditionalOnLoadCode(
84 function ($id) {
85 return "
86 $(\"#$id\").click(function() {
87 var counter = il.UI.counter.getCounterObject($(this));
88 counter.setNoveltyTo(3);
89 counter.setStatusTo(3);
90 counter.incrementStatusCount(1);
91 counter.setTotalNoveltyToStatusCount();
92 console.log(
93 counter.getStatusCount()
94 );
95 });";
96 }
97 );
98
99 return $renderer->render([$set_status_button,$increment_novelty_button,$set_novelty_count_to_status_button,$combined_button]);
100}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$renderer
global $DIC
Definition: shib_login.php:26