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
|
1 |
|
public function asConfig() |
19
|
|
|
{ |
20
|
1 |
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
2 |
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
2 |
|
if (!isset($this->configurator->tags['LI'])) |
26
|
|
|
{ |
27
|
2 |
|
$this->configurator->Litedown; |
28
|
|
|
} |
29
|
|
|
|
30
|
2 |
|
$this->createTaskTag(); |
31
|
2 |
|
$this->configureListItemTag($this->configurator->tags['LI']); |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
protected function configureListItemTag(Tag $tag): void |
35
|
|
|
{ |
36
|
2 |
|
$tag->filterChain->append(Helper::class . '::filterListItem') |
37
|
2 |
|
->resetParameters() |
38
|
2 |
|
->addParameterByName('parser') |
39
|
2 |
|
->addParameterByName('tag') |
40
|
2 |
|
->addParameterByName('text') |
41
|
2 |
|
->setJS(file_get_contents(__DIR__ . '/filterListItem.js')); |
42
|
|
|
|
43
|
2 |
|
$tag->template = preg_replace( |
44
|
2 |
|
'(<li[^>]*+>(?!<xsl:if test="TASK">)\\K)', |
45
|
2 |
|
'<xsl:if test="TASK"> |
46
|
|
|
<xsl:attribute name="data-task-id"> |
47
|
|
|
<xsl:value-of select="TASK/@id"/> |
48
|
|
|
</xsl:attribute> |
49
|
|
|
<xsl:attribute name="data-task-state"> |
50
|
|
|
<xsl:value-of select="TASK/@state"/> |
51
|
|
|
</xsl:attribute> |
52
|
|
|
</xsl:if>', |
53
|
2 |
|
$tag->template |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
protected function createTaskTag(): void |
58
|
|
|
{ |
59
|
2 |
|
$tag = $this->configurator->tags->add('TASK'); |
60
|
2 |
|
$tag->attributes->add('id')->filterChain->append('#identifier'); |
61
|
2 |
|
$tag->attributes->add('state')->filterChain->append('#identifier'); |
62
|
2 |
|
$tag->template = '<input data-task-id="{@id}" type="checkbox"> |
63
|
|
|
<xsl:if test="@state = \'checked\'"><xsl:attribute name="checked"/></xsl:if> |
64
|
|
|
<xsl:if test="not($TASKLISTS_EDITABLE)"><xsl:attribute name="disabled"/></xsl:if> |
65
|
|
|
</input>'; |
66
|
|
|
} |
67
|
|
|
} |