Skip to content

Commit 5efc8ba

Browse files
authored
Merge pull request #18 from Chaosmeister/master
enable "URL-Rewriting" enabled instances to use checkboxes add html validation
2 parents 0d28d7a + 90e91d6 commit 5efc8ba

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

Diff for: Assets/js/checkbox.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
KB.on('dom.ready', function() {
1+
KB.on('dom.ready', function () {
22
const urlParams = new URLSearchParams(window.location.search);
3-
if ((urlParams.get('controller') == "TaskViewController" && urlParams.get('action') == 'show') || /\/task\/[0-9]+$/.test(window.location)) {
4-
var Content = document.getElementsByClassName('sidebar-content')[0];
53

6-
const elements = [...Content.getElementsByTagName('input')];
7-
var checkboxes = elements.filter(input=>input.type == 'checkbox');
8-
const matches = [...Content.innerHTML.matchAll(RegExp('(<input type="checkbox")|(\\[[xX ]\\])', 'gm'))];
9-
10-
var count = 0;
11-
var currentCheckbox = 0;
12-
for (const match of matches) {
13-
++count;
14-
if (match[1] !== undefined) {
15-
var checkbox = checkboxes[currentCheckbox];
16-
checkbox.setAttribute('class', 'activecheckbox');
17-
checkbox.setAttribute('number', count);
18-
++currentCheckbox;
19-
}
20-
}
4+
let URLRewrite = /\/task\/[0-9]+$/.test(window.location);
5+
if ((urlParams.get('controller') == "TaskViewController" && urlParams.get('action') == 'show') ||
6+
URLRewrite) { // for activated URL-Rewrite
217

228
KB.onClick('.activecheckbox', ToggleActiveCheckbox, !0);
239

2410
function ToggleActiveCheckbox(e) {
2511
const urlParams = new URLSearchParams(window.location.search);
2612

27-
const link = '?controller=CheckboxController&action=toggle&plugin=MarkdownPlus';
13+
var task_id = null;
14+
var taskIdElem = document.getElementById('form-task_id');
15+
if (taskIdElem != null) {
16+
task_id = taskIdElem.value;
17+
}
18+
19+
let link = "";
20+
if (URLRewrite) {
21+
link = '/MarkdownPlus/Checkbox';
22+
}
23+
else {
24+
link = '?controller=CheckboxController&action=toggle&plugin=MarkdownPlus';
25+
}
26+
2827
KB.http.postJson(link, {
29-
'task_id': urlParams.get('task_id'),
28+
'task_id': task_id,
3029
'number': e.target.getAttribute('number')
3130
});
3231
}

Diff for: Plugin.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Kanboard\Plugin\MarkdownPlus;
44

55
use Kanboard\Core\Plugin\Base;
6-
use Kanboard\Plugin\MarkdownPlus\Helper\MarkdownPlusHelper;
76

87
class Plugin extends Base
98

Diff for: vendor/erusev/parsedown-extra/ParsedownExtra.php

+11
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ protected function processTag($elementMarkup) # recursive
629629

630630
# http://stackoverflow.com/q/4879946/200145
631631
$DOMDocument->loadHTML($elementMarkup);
632+
633+
if (!$DOMDocument->validate()) {
634+
$errormessage = 'could not parse html<br>';
635+
$errors = libxml_get_errors();
636+
foreach ($errors as $error) {
637+
$errormessage .= $error->message;
638+
$errormessage .= '<br>';
639+
}
640+
return $errormessage;
641+
}
642+
632643
$DOMDocument->removeChild($DOMDocument->doctype);
633644
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
634645

Diff for: vendor/leblanc-simon/parsedown-checkbox/ParsedownCheckbox.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class ParsedownCheckbox extends ParsedownExtra
1212
{
1313
const VERSION = '0.0.4';
14+
private static $count = 1;
1415

1516
public function __construct()
1617
{
@@ -73,7 +74,7 @@ protected function checkboxUnchecked($text)
7374
$text = self::escape($text);
7475
}
7576

76-
return '<input type="checkbox" class="activeCheckBox"/> ' . $this->format($text);
77+
return '<input type="checkbox" class="activecheckbox" number="'. ParsedownCheckbox::$count++ .'"/> ' . $this->format($text);
7778
}
7879

7980
protected function checkboxChecked($text)
@@ -82,7 +83,7 @@ protected function checkboxChecked($text)
8283
$text = self::escape($text);
8384
}
8485

85-
return '<input type="checkbox" class="activeCheckBox" checked/> ' . $this->format($text);
86+
return '<input type="checkbox" class="activecheckbox" number="'. ParsedownCheckbox::$count++ .'" checked/> ' . $this->format($text);
8687
}
8788

8889
/**

0 commit comments

Comments
 (0)