ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_js.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
24 function with_js()
25 {
26  global $DIC;
27  $f = $DIC->ui()->factory();
28  $renderer = $DIC->ui()->renderer();
29 
30  //Note that both counters have to be present to perform JS actions on them
31  $like = $f->symbol()->glyph()->love("#")
32  ->withCounter($f->counter()->novelty(3))
33  ->withCounter($f->counter()->status(0));
34 
35  $set_status_button = $f->button()->bulky($like, "Set Status Counter to 10 on click.", "#")
36  ->withAdditionalOnLoadCode(
37  function ($id) {
38  return "
39  $(\"#$id\").click(function() {
40  il.UI.counter.getCounterObject($(this)).setStatusTo(10);
41  });";
42  }
43  );
44 
45  $increment_novelty_button = $f->button()->bulky($like, "Increment Novelty Counter by on click", "#")
46  ->withAdditionalOnLoadCode(
47  function ($id) {
48  return "
49  $(\"#$id\").click(function() {
50  il.UI.counter.getCounterObject($(this)).incrementNoveltyCount(1);
51  });";
52  }
53  );
54 
55  $set_novelty_count_to_status_button = $f->button()->bulky($like, "Set Novelty Count to status on click", "#")
56  ->withAdditionalOnLoadCode(
57  function ($id) {
58  return "
59  $(\"#$id\").click(function() {
60  il.UI.counter.getCounterObject($(this)).setTotalNoveltyToStatusCount(1);
61  });";
62  }
63  );
64 
65  //What will the value of Status be after click?
66  $combined_button = $f->button()->bulky($like, "Some chained actions", "#")
67  ->withAdditionalOnLoadCode(
68  function ($id) {
69  return "
70  $(\"#$id\").click(function() {
71  var counter = il.UI.counter.getCounterObject($(this));
72  counter.setNoveltyTo(3);
73  counter.setStatusTo(3);
74  counter.incrementStatusCount(1);
75  counter.setTotalNoveltyToStatusCount();
76  console.log(
77  counter.getStatusCount()
78  );
79  });";
80  }
81  );
82 
83  return $renderer->render([$set_status_button,$increment_novelty_button,$set_novelty_count_to_status_button,$combined_button]);
84 }
$renderer
global $DIC
Definition: shib_login.php:25
with_js()
description: > Base example for rendering a JS status counter
Definition: with_js.php:24
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24