Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Jan 12, 2024
1 parent 8bc0e16 commit 57d0fc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions lam/lib/html.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1492,12 +1492,12 @@ class htmlSelect extends htmlElement {
$onChange .= 'if (document.getElementById(\'' . $this->name . '\').value == \'' . $val . '\') {';
if (isset($this->tableRowsToShow[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\').closest(\'' . $selector . '\').classList.remove(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
}
if (isset($this->tableRowsToHide[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\').closest(\'' . $selector . '\').classList.add(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
}
$onChange .= '};';
Expand All @@ -1507,13 +1507,13 @@ class htmlSelect extends htmlElement {
if (isset($this->tableRowsToShow[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$this->selectedElements[0]]); $i++) {
$classType = 'remove';
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElements[0]][$i] . '\').closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
}
}
if (isset($this->tableRowsToHide[$this->selectedElements[0]])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$this->selectedElements[0]]); $i++) {
$classType = 'add';
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElements[0]][$i] . '\').closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElements[0]][$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');' . "\n";
}
}
$script .= '});</script>';
Expand Down Expand Up @@ -1708,12 +1708,12 @@ class htmlRadio extends htmlElement {
$onChange .= 'if (document.getElementById(\'' . $this->name . $counter . '\').value == \'' . $val . '\') {';
if (isset($this->tableRowsToShow[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\').closest(\'' . $selector . '\').classList.remove(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
}
if (isset($this->tableRowsToHide[$val])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$val]); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\').closest(\'' . $selector . '\').classList.add(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$val][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
}
$onChange .= '};';
Expand All @@ -1727,12 +1727,12 @@ class htmlRadio extends htmlElement {
$script = '<script type="text/javascript">window.lam.utility.documentReady(function() {' . "\n";
if (isset($this->tableRowsToShow[$this->selectedElement])) {
for ($i = 0; $i < sizeof($this->tableRowsToShow[$this->selectedElement]); $i++) {
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElement][$i] . '\').closest(\'' . $selector . '\').classList.remove(\'hidden\');' . "\n";
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');' . "\n";
}
}
if (isset($this->tableRowsToHide[$this->selectedElement])) {
for ($i = 0; $i < sizeof($this->tableRowsToHide[$this->selectedElement]); $i++) {
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElement][$i] . '\').closest(\'' . $selector . '\').classList.add(\'hidden\');' . "\n";
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$this->selectedElement][$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');' . "\n";
}
}
$script .= '});</script>';
Expand Down Expand Up @@ -1990,18 +1990,18 @@ class htmlInputCheckbox extends htmlElement {
// build onChange listener
$onChange .= 'if (document.querySelector(\'#' . $this->name . ':checked\') !== null) {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\').closest(\'' . $selector . '\').classList.remove(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\').closest(\'' . $selector . '\').classList.add(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
$onChange .= '}';
$onChange .= 'else {';
for ($i = 0; $i < sizeof($this->tableRowsToShow); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\').closest(\'' . $selector . '\').classList.add(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.add(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\').closest(\'' . $selector . '\').classList.remove(\'hidden\');';
$onChange .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.remove(\'hidden\');';
}
$onChange .= '};';
// build script to set initial state
Expand All @@ -2011,14 +2011,14 @@ class htmlInputCheckbox extends htmlElement {
if ($this->checked) {
$classType = 'remove';
}
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\').closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
$script .= 'document.getElementById(\'' . $this->tableRowsToShow[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
}
for ($i = 0; $i < sizeof($this->tableRowsToHide); $i++) {
$classType = 'remove';
if ($this->checked) {
$classType = 'add';
}
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\').closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
$script .= 'document.getElementById(\'' . $this->tableRowsToHide[$i] . '\')?.closest(\'' . $selector . '\').classList.' . $classType . '(\'hidden\');';
}
$script .= '});</script>';
}
Expand Down
10 changes: 5 additions & 5 deletions lam/tests/design/designExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@
$showHideSelect = new htmlResponsiveSelect('showHideSelect', $showHideOptions, ['input1'], 'Show/hide select');
$showHideSelect->setHasDescriptiveElements(true);
$showHideSelect->setTableRowsToShow([
'input1' => ['showHideSelect_i1'],
'input1' => ['showHideSelect_i1', 'invalid'],
'input2' => ['showHideSelect_i2'],
'both' => ['showHideSelect_i1', 'showHideSelect_i2'],
]);
$showHideSelect->setTableRowsToHide([
'input1' => ['showHideSelect_i2'],
'input1' => ['showHideSelect_i2', 'invalid'],
'input2' => ['showHideSelect_i1'],
'both' => [],
]);
Expand All @@ -381,12 +381,12 @@
$showHideRadio = new htmlResponsiveRadio('Show/hide radio', 'showHideRadio', $showHideOptions, 'input2');
$showHideRadio->setTableRowsToShow([
'input1' => ['showHideRadio_i1'],
'input2' => ['showHideRadio_i2'],
'input2' => ['showHideRadio_i2', 'invalid'],
'both' => ['showHideRadio_i1', 'showHideRadio_i2'],
]);
$showHideRadio->setTableRowsToHide([
'input1' => ['showHideRadio_i2'],
'input2' => ['showHideRadio_i1'],
'input2' => ['showHideRadio_i1', 'invalid'],
'both' => [],
]);
$row->add($showHideRadio);
Expand All @@ -397,7 +397,7 @@

$showHideCheckbox = new htmlResponsiveInputCheckbox('showHideCheckbox', false, 'Show/hide checkbox');
$showHideCheckbox->setTableRowsToShow(['showHideCheckbox_i1']);
$showHideCheckbox->setTableRowsToHide(['showHideCheckbox_i2']);
$showHideCheckbox->setTableRowsToHide(['showHideCheckbox_i2', 'invalid']);
$showHideCheckbox->setElementsToEnable(['showHideCheckbox_ie']);
$showHideCheckbox->setElementsToDisable(['showHideCheckbox_id']);
$row->add($showHideCheckbox);
Expand Down

0 comments on commit 57d0fc6

Please sign in to comment.