|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package s9e\TextFormatter |
|
5
|
|
|
* @copyright Copyright (c) 2010-2020 The s9e authors |
|
6
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace s9e\TextFormatter\Plugins\TaskLists; |
|
9
|
|
|
|
|
10
|
|
|
use s9e\TextFormatter\Configurator\Items\Tag; |
|
11
|
|
|
use s9e\TextFormatter\Plugins\ConfiguratorBase; |
|
12
|
|
|
|
|
13
|
|
|
class Configurator extends ConfiguratorBase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
public function asConfig() |
|
19
|
|
|
{ |
|
20
|
|
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
1 |
|
if (!isset($this->configurator->tags['LI'])) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$this->configurator->Litedown; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
$this->createTaskTag(); |
|
31
|
1 |
|
$this->configureListItemTag($this->configurator->tags['LI']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
protected function configureListItemTag(Tag $tag): void |
|
35
|
|
|
{ |
|
36
|
1 |
|
$tag->filterChain->append(Helper::class . '::filterListItem') |
|
37
|
1 |
|
->resetParameters() |
|
38
|
1 |
|
->addParameterByName('parser') |
|
39
|
1 |
|
->addParameterByName('tag') |
|
40
|
1 |
|
->addParameterByName('text') |
|
41
|
1 |
|
->setJS(file_get_contents(__DIR__ . '/filterListItem.js')); |
|
42
|
|
|
|
|
43
|
1 |
|
$attribute = $tag->attributes->add('task_id'); |
|
44
|
1 |
|
$attribute->required = false; |
|
45
|
1 |
|
$attribute->filterChain->append('#identifier'); |
|
46
|
|
|
|
|
47
|
1 |
|
$tag->template = preg_replace( |
|
48
|
1 |
|
'(<li[^>]*+>(?!<xsl:if test="@task_id">)\\K)', |
|
49
|
1 |
|
'<xsl:if test="@task_id"> |
|
50
|
|
|
<xsl:attribute name="data-task-id"> |
|
51
|
|
|
<xsl:value-of select="@task_id"/> |
|
52
|
|
|
</xsl:attribute> |
|
53
|
|
|
</xsl:if>', |
|
54
|
1 |
|
$tag->template |
|
|
|
|
|
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
protected function createTaskTag(): void |
|
59
|
|
|
{ |
|
60
|
1 |
|
$tag = $this->configurator->tags->add('TASK'); |
|
61
|
1 |
|
$tag->attributes->add('id')->filterChain->append('#identifier'); |
|
62
|
1 |
|
$tag->attributes->add('state')->required = false; |
|
63
|
1 |
|
$tag->template = '<input data-task-id="{@id}" type="checkbox"> |
|
64
|
|
|
<xsl:if test="@state"><xsl:attribute name="checked"/></xsl:if> |
|
65
|
|
|
<xsl:if test="not($TASKLISTS_EDITABLE)"><xsl:attribute name="disabled"/></xsl:if> |
|
66
|
|
|
</input>'; |
|
67
|
|
|
} |
|
68
|
|
|
} |