]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/directives.js
Merge pull request #10 from BookStackApp/master
[bookstack] / resources / assets / js / directives.js
index 0bc664200f70a7459859abe1abf38061719a0498..cae07a1663cde3aa70024be61287ab1454f20e95 100644 (file)
@@ -215,7 +215,7 @@ module.exports = function (ngApp, events) {
         }
     }]);
 
-    const md = new MarkdownIt();
+    const md = new MarkdownIt({html: true});
     md.use(mdTasksLists, {label: true});
 
     /**
@@ -818,4 +818,99 @@ module.exports = function (ngApp, events) {
             }
         };
     }]);
+
+
+    ngApp.directive('simpleMarkdownInput', ['$timeout', function ($timeout) {
+        return {
+            restrict: 'A',
+            scope: {
+                smdModel: '=',
+                smdChange: '=',
+                smdGetContent: '=',
+                smdClear: '='
+            },
+            link: function (scope, element, attrs) {
+                // Set initial model content
+                element = element.find('textarea').first();
+                let simplemde = new SimpleMDE({
+                    element: element[0],
+                    status: []
+                });
+                let content = element.val();
+                simplemde.value(content)
+                scope.smdModel = content;
+
+                simplemde.codemirror.on('change', (event) => {
+                    content = simplemde.value();
+                    $timeout(() => {
+                        scope.smdModel = content;
+                        if (scope.smdChange) {
+                            scope.smdChange(element, content);
+                        }
+                    });
+                });
+                
+                if ('smdGetContent' in attrs) {
+                    scope.smdGetContent = function () {
+                        return simplemde.options.previewRender(simplemde.value());
+                    };
+                }
+                
+                if ('smdClear' in attrs) {
+                    scope.smdClear = function () {
+                        simplemde.value('');
+                        scope.smdModel = '';                        
+                    };
+                }
+            }
+        }
+    }]);
+    
+    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();
+        }
+    }]);
 };