]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/directives.js
Merge pull request #10 from BookStackApp/master
[bookstack] / resources / assets / js / directives.js
index 537a016f5e13a637236301ae7c9f5491c0130353..cae07a1663cde3aa70024be61287ab1454f20e95 100644 (file)
@@ -1,8 +1,9 @@
 "use strict";
-import DropZone from "dropzone";
-import markdown from "marked";
+const DropZone = require("dropzone");
+const MarkdownIt = require("markdown-it");
+const mdTasksLists = require('markdown-it-task-lists');
 
-export default function (ngApp, events) {
+module.exports = function (ngApp, events) {
 
     /**
      * Common tab controls using simple jQuery functions.
@@ -214,18 +215,8 @@ export default function (ngApp, events) {
         }
     }]);
 
-    let renderer = new markdown.Renderer();
-    // Custom markdown checkbox list item
-    // Attribution: https://github.com/chjj/marked/issues/107#issuecomment-44542001
-    renderer.listitem = function(text) {
-        if (/^\s*\[[x ]\]\s*/.test(text)) {
-            text = text
-                .replace(/^\s*\[ \]\s*/, '<input type="checkbox"/>')
-                .replace(/^\s*\[x\]\s*/, '<input type="checkbox" checked/>');
-            return `<li class="checkbox-item">${text}</li>`;
-        }
-        return `<li>${text}</li>`;
-    };
+    const md = new MarkdownIt({html: true});
+    md.use(mdTasksLists, {label: true});
 
     /**
      * Markdown input
@@ -244,20 +235,20 @@ export default function (ngApp, events) {
                 element = element.find('textarea').first();
                 let content = element.val();
                 scope.mdModel = content;
-                scope.mdChange(markdown(content, {renderer: renderer}));
+                scope.mdChange(md.render(content));
 
                 element.on('change input', (event) => {
                     content = element.val();
                     $timeout(() => {
                         scope.mdModel = content;
-                        scope.mdChange(markdown(content, {renderer: renderer}));
+                        scope.mdChange(md.render(content));
                     });
                 });
 
                 scope.$on('markdown-update', (event, value) => {
                     element.val(value);
                     scope.mdModel = value;
-                    scope.mdChange(markdown(value));
+                    scope.mdChange(md.render(value));
                 });
 
             }
@@ -874,5 +865,52 @@ export default function (ngApp, events) {
             }
         }
     }]);
+    
+    ngApp.directive('commentReply', ['$timeout', function ($timeout) {        
+        return {
+            restrict: 'E',
+            templateUrl: 'comment-reply.html',
+            scope: {
+                
+            },
+            link: function (scope, element, attr) {
+               
+            }
+        }
+                
+    }]);
 
+    ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) {
+        return { 
+            link: function (scope, element, attr) {
+                element.on('$destroy', function () {
+                    element.off('click');
+                    scope.$destroy(); 
+                });
+                
+                element.on('click', function () {
+                    var $container = element.parents('.comment-box').first();
+                    if (!$container.length) {
+                        console.error('commentReplyLink directive should be placed inside a container with class comment-box!');
+                        return;
+                    }
+                    if (attr.noCommentReplyDupe) {
+                        removeDupe();                    
+                    }
+                    var compiledHTML = $compile('<comment-reply></comment-reply>')(scope);
+                    $container.append(compiledHTML);
+                });
+            }
+        };
+        
+        
+        function removeDupe() {
+            let $existingElement = $document.find('comment-reply');
+            if (!$existingElement.length) {
+                return;
+            }
+            
+            $existingElement.remove();
+        }
+    }]);
 };