]> BookStack Code Mirror - bookstack/commitdiff
Added WYSIWYG tasklist clicking ability
authorDan Brown <redacted>
Sun, 20 Mar 2022 11:59:46 +0000 (11:59 +0000)
committerDan Brown <redacted>
Sun, 20 Mar 2022 11:59:46 +0000 (11:59 +0000)
resources/js/wysiwyg/plugins-tasklist.js
resources/sass/_tinymce.scss

index 4070575d92aea8fb1729bdd037916d7402de1859..3fbc2c1e80fe81cefd30dd244b2d7ed17add4975 100644 (file)
@@ -25,6 +25,37 @@ function register(editor, url) {
 
     });
 
+    editor.on('click', function(event) {
+        const clickedEl = event.originalTarget;
+        if (clickedEl.nodeName === 'LI' && clickedEl.classList.contains('task-list-item')) {
+            handleTaskListItemClick(event, clickedEl, editor);
+        }
+    });
+
+}
+
+/**
+ * @param {MouseEvent} event
+ * @param {Element} clickedEl
+ * @param {Editor} editor
+ */
+function handleTaskListItemClick(event, clickedEl, editor) {
+    const bounds = clickedEl.getBoundingClientRect();
+    const withinBounds = event.clientX <= bounds.right
+                        && event.clientX >= bounds.left
+                        && event.clientY >= bounds.top
+                        && event.clientY <= bounds.bottom;
+
+    // Outside of the task list item bounds mean we're probably clicking the pseudo-element.
+    if (!withinBounds) {
+        editor.undoManager.transact(() => {
+            if (clickedEl.hasAttribute('checked')) {
+                clickedEl.removeAttribute('checked');
+            }  else {
+                clickedEl.setAttribute('checked', 'checked');
+            }
+        });
+    }
 }
 
 /**
index c4848561a9ba800f8a4a4c759cbbc05dc049dab9..0ee3fa40b235298e3ceaf0bf64ab4bb6456b050d 100644 (file)
@@ -117,6 +117,10 @@ body.page-content.mce-content-body  {
 /**
  * Fake task list checkboxes
  */
+.page-content.mce-content-body .task-list-item {
+  margin-left: 0;
+  position: relative;
+}
 .page-content.mce-content-body .task-list-item > input[type="checkbox"] {
   display: none;
 }
@@ -130,6 +134,9 @@ body.page-content.mce-content-body  {
   margin-right: 8px;
   vertical-align: text-top;
   cursor: pointer;
+  position: absolute;
+  left: -24px;
+  top: 4px;
 }
 
 .page-content.mce-content-body .task-list-item[checked]:before {