ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Button.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\UI\Component as C;
12 
16 abstract class Button implements C\Button\Button
17 {
18  use ComponentHelper;
20  use Triggerer;
21 
25  protected $label;
26 
30  protected $action;
31 
35  protected $active = true;
36 
40  protected $aria_label;
41 
45  protected $aria_checked = false;
46 
47 
48  public function __construct($label, $action)
49  {
50  $this->checkStringArg("label", $label);
51  $this->checkStringArg("action", $action);
52  $this->label = $label;
53  $this->action = $action;
54  }
55 
59  public function getLabel()
60  {
61  return $this->label;
62  }
63 
67  public function withLabel($label)
68  {
69  $this->checkStringArg("label", $label);
70  $clone = clone $this;
71  $clone->label = $label;
72  return $clone;
73  }
74 
78  public function getAction()
79  {
80  return $this->action;
81  }
82 
86  public function isActive()
87  {
88  return $this->active;
89  }
90 
94  public function withUnavailableAction()
95  {
96  $clone = clone $this;
97  $clone->active = false;
98  return $clone;
99  }
100 
104  public function withOnClick(Signal $signal)
105  {
106  return $this->addTriggeredSignal($signal, 'click');
107  }
108 
112  public function appendOnClick(Signal $signal)
113  {
114  return $this->appendTriggeredSignal($signal, 'click');
115  }
116 
120  public function withOnHover(Signal $signal)
121  {
122  // Note: The event 'hover' maps to 'mouseenter' in javascript. Although 'hover' is available in JQuery,
123  // it encodes the 'mouseenter' and 'mouseleave' events and thus expects two event handlers.
124  // In the context of this framework, the signal MUST only be triggered on the 'mouseenter' event.
125  // See also: https://api.jquery.com/hover/
126  return $this->addTriggeredSignal($signal, 'mouseenter');
127  }
128 
132  public function appendOnHover(Signal $signal)
133  {
134  return $this->appendTriggeredSignal($signal, 'mouseenter');
135  }
136 
140  public function withAriaLabel($aria_label)
141  {
142  $this->checkStringArg("label", $aria_label);
143  $clone = clone $this;
144  $clone->aria_label = $aria_label;
145  return $clone;
146  }
147 
151  public function getAriaLabel()
152  {
153  return $this->aria_label;
154  }
155 
159  public function withAriaChecked()
160  {
161  $clone = clone $this;
162  $clone->aria_checked = true;
163  return $clone;
164  }
165 
169  public function isAriaChecked()
170  {
171  return $this->aria_checked;
172  }
173 }
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
addTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:46
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:29
This implements commonalities between standard and primary buttons.
Definition: Button.php:16