|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package s9e\TextFormatter |
|
5
|
|
|
* @copyright Copyright (c) 2010-2021 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
|
2 |
|
public function asConfig() |
|
19
|
|
|
{ |
|
20
|
2 |
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function finalize() |
|
27
|
|
|
{ |
|
28
|
1 |
|
$this->configureListItemTag(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
5 |
|
protected function setUp(): void |
|
32
|
|
|
{ |
|
33
|
5 |
|
if (!isset($this->configurator->tags['LI'])) |
|
34
|
|
|
{ |
|
35
|
5 |
|
$this->configurator->Litedown; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
5 |
|
$this->createTaskTag(); |
|
39
|
5 |
|
$this->configureListItemTag(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
5 |
|
protected function configureListItemTag(): void |
|
43
|
|
|
{ |
|
44
|
5 |
|
if (!isset($this->configurator->tags['LI'])) |
|
45
|
|
|
{ |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
5 |
|
$tag = $this->configurator->tags['LI']; |
|
50
|
5 |
|
$callback = Helper::class . '::filterListItem'; |
|
51
|
5 |
|
if (!$tag->filterChain->containsCallback($callback)) |
|
52
|
|
|
{ |
|
53
|
5 |
|
$tag->filterChain->append($callback) |
|
54
|
5 |
|
->resetParameters() |
|
55
|
5 |
|
->addParameterByName('parser') |
|
56
|
5 |
|
->addParameterByName('tag') |
|
57
|
5 |
|
->addParameterByName('text') |
|
58
|
5 |
|
->setJS(file_get_contents(__DIR__ . '/filterListItem.js')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
5 |
|
$dom = $tag->template->asDOM(); |
|
62
|
5 |
|
foreach ($dom->query('//li[not(xsl:if[@test="TASK"])]') as $li) |
|
63
|
|
|
{ |
|
64
|
5 |
|
$if = $li->prependXslIf('TASK'); |
|
65
|
5 |
|
$if->appendXslAttribute('data-s9e-livepreview-ignore-attrs', 'data-task-id'); |
|
66
|
5 |
|
$if->appendXslAttribute('data-task-id')->appendXslValueOf('TASK/@id'); |
|
67
|
5 |
|
$if->appendXslAttribute('data-task-state')->appendXslValueOf('TASK/@state'); |
|
68
|
|
|
} |
|
69
|
5 |
|
$dom->saveChanges(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
5 |
|
protected function createTaskTag(): void |
|
73
|
|
|
{ |
|
74
|
5 |
|
$tag = $this->configurator->tags->add('TASK'); |
|
75
|
5 |
|
$tag->attributes->add('id')->filterChain->append('#identifier'); |
|
76
|
5 |
|
$tag->attributes->add('state')->filterChain->append('#identifier'); |
|
77
|
5 |
|
$tag->template = '<input data-task-id="{@id}" data-s9e-livepreview-ignore-attrs="data-task-id" type="checkbox"> |
|
78
|
|
|
<xsl:if test="@state = \'checked\'"><xsl:attribute name="checked"/></xsl:if> |
|
79
|
|
|
<xsl:if test="not($TASKLISTS_EDITABLE)"><xsl:attribute name="disabled"/></xsl:if> |
|
80
|
|
|
</input>'; |
|
81
|
|
|
} |
|
82
|
|
|
} |