ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_js.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
40 function 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 }
$renderer
global $DIC
Definition: shib_login.php:22
with_js()
description: > Base example for rendering a JS status counter
Definition: with_js.php:40
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23