Skip to content

Commit 2b40c65

Browse files
multiple page list with tagcheck are allowed in page render
- If two LIST have exact same options, it still create a conflict. - added classes to span and form to help select them. Ex: to hide a specific checkbox
1 parent 27b5ce6 commit 2b40c65

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

app/class/Optlist.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Optlist extends Optcode
1919
protected bool $timemodif = false;
2020
protected bool $author = false;
2121
protected bool $hidecurrent = false;
22-
protected bool $checkbox = false;
22+
protected bool $tagcheck = false;
2323
protected string $style = self::LIST;
2424

2525
public const LIST = 'list';
@@ -29,6 +29,7 @@ class Optlist extends Optcode
2929
self::CARD => self::CARD,
3030
];
3131

32+
/** @var array<string, int> $usefulltags */
3233
protected array $usefulltags = [];
3334

3435
/**
@@ -159,7 +160,7 @@ public function listhtml(array $pagelist, Page $currentpage): string
159160
$thumbnail->setAttribute('alt', htmlspecialchars($page->title()));
160161
$parent->appendChild($thumbnail);
161162
}
162-
if ($this->checkbox) {
163+
if ($this->tagcheck) {
163164
$tags = $page->tag();
164165
$this->addusefulltags($tags);
165166
foreach ($tags as $tag) {
@@ -169,15 +170,19 @@ public function listhtml(array $pagelist, Page $currentpage): string
169170
}
170171
$dom->appendChild($ul);
171172

172-
if ($this->checkbox) {
173+
if ($this->tagcheck) {
174+
$hash = crc32(serialize($this));
173175
$domform = new DOMDocument('1.0', 'UTF-8');
174176
$form = $domform->createElement('form');
177+
$form->setAttribute('class', 'tagcheck');
178+
$form->setAttribute('id', "tagcheck-$hash");
175179
foreach ($this->usefulltags as $tag => $count) {
176180
if ($count === $pagecount) {
177181
continue; // skip this tag as it's used by all pages
178182
}
179183
$span = $domform->createElement('span');
180-
$id = "checkbox-tag_$tag";
184+
$span->setAttribute('class', "tag_$tag");
185+
$id = "tagcheck-$hash-tag_$tag";
181186
$input = $domform->createElement('input');
182187
$input->setAttribute('id', $id);
183188
$input->setAttribute('value', $tag);
@@ -203,7 +208,9 @@ public function listhtml(array $pagelist, Page $currentpage): string
203208

204209
/**
205210
* merge list of tags within the list of usefull tags.
206-
* Tag names are stored as key and value count the time it's used.
211+
* Tag name is key and value count the time it's used.
212+
*
213+
* @param string[] $tags
207214
*/
208215
private function addusefulltags(array $tags): void
209216
{
@@ -267,9 +274,9 @@ public function hidecurrent(): bool
267274
return $this->hidecurrent;
268275
}
269276

270-
public function checkbox(): bool
277+
public function tagcheck(): bool
271278
{
272-
return $this->checkbox;
279+
return $this->tagcheck;
273280
}
274281

275282
public function style(): string
@@ -325,12 +332,12 @@ public function sethidecurrent(bool $hidecurrent): void
325332
$this->hidecurrent = $hidecurrent;
326333
}
327334

328-
public function setcheckbox($checkbox)
335+
public function settagcheck(bool $tagcheck): void
329336
{
330-
$this->checkbox = boolval($checkbox);
337+
$this->tagcheck = $tagcheck;
331338
}
332339

333-
public function setstyle(string $style)
340+
public function setstyle(string $style): void
334341
{
335342
if (key_exists($style, self::STYLES)) {
336343
$this->style = $style;

app/class/Servicerender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ protected function pageoptlist(string $text): string
737737

738738
$optlist->hydrate($options);
739739

740-
if ($optlist->checkbox()) {
740+
if ($optlist->tagcheck()) {
741741
$this->checkboxjs = true;
742742
}
743743

src/pagecheckbox.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
console.log('yoo');
1+
const formFilters = document.querySelectorAll('form');
22

3-
const formFilter = document.querySelector('form');
4-
5-
function w_filterpagelist() {
3+
function filterpagelist(id) {
4+
let idSelector = '#' + id;
65
let tagCheckboxesChecked = document.querySelectorAll(
7-
'input[type="checkbox"]:checked'
6+
'form' + idSelector + ' input[type="checkbox"]:checked'
87
);
98

10-
let pages = document.querySelectorAll('.pagelist li');
9+
let pages = document.querySelectorAll(
10+
'form' + idSelector + ' + .pagelist li'
11+
);
1112
let tagCount = tagCheckboxesChecked.length;
1213

1314
for (var li of pages) {
@@ -31,4 +32,8 @@ function w_filterpagelist() {
3132
}
3233
}
3334

34-
formFilter.addEventListener('click', w_filterpagelist);
35+
for (let formFilter of formFilters) {
36+
formFilter.addEventListener('click', () => {
37+
filterpagelist(formFilter.id);
38+
});
39+
}

0 commit comments

Comments
 (0)