]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/directives.js
Removes some unused code.
[bookstack] / resources / assets / js / directives.js
index 2a0547c97ab52cdda0f4f97d8363c2dcb08437b6..eb7d2776be831dc7179b8dadc1ae7564794247ca 100644 (file)
 "use strict";
-const DropZone = require("dropzone");
 const MarkdownIt = require("markdown-it");
 const mdTasksLists = require('markdown-it-task-lists');
 const code = require('./code');
 
 module.exports = function (ngApp, events) {
 
-    /**
-     * Common tab controls using simple jQuery functions.
-     */
-    ngApp.directive('tabContainer', function() {
-        return {
-            restrict: 'A',
-            link: function (scope, element, attrs) {
-                const $content = element.find('[tab-content]');
-                const $buttons = element.find('[tab-button]');
-
-                if (attrs.tabContainer) {
-                    let initial = attrs.tabContainer;
-                    $buttons.filter(`[tab-button="${initial}"]`).addClass('selected');
-                    $content.hide().filter(`[tab-content="${initial}"]`).show();
-                } else {
-                    $content.hide().first().show();
-                    $buttons.first().addClass('selected');
-                }
-
-                $buttons.click(function() {
-                    let clickedTab = $(this);
-                    $buttons.removeClass('selected');
-                    $content.hide();
-                    let name = clickedTab.addClass('selected').attr('tab-button');
-                    $content.filter(`[tab-content="${name}"]`).show();
-                });
-            }
-        };
-    });
-
-    /**
-     * Sub form component to allow inner-form sections to act like their own forms.
-     */
-    ngApp.directive('subForm', function() {
-        return {
-            restrict: 'A',
-            link: function (scope, element, attrs) {
-                element.on('keypress', e => {
-                    if (e.keyCode === 13) {
-                        submitEvent(e);
-                    }
-                });
-
-                element.find('button[type="submit"]').click(submitEvent);
-
-                function submitEvent(e) {
-                    e.preventDefault();
-                    if (attrs.subForm) scope.$eval(attrs.subForm);
-                }
-            }
-        };
-    });
-
-    /**
-     * DropZone
-     * Used for uploading images
-     */
-    ngApp.directive('dropZone', [function () {
-        return {
-            restrict: 'E',
-            template: `
-            <div class="dropzone-container">
-                <div class="dz-message">{{message}}</div>
-            </div>
-            `,
-            scope: {
-                uploadUrl: '@',
-                eventSuccess: '=',
-                eventError: '=',
-                uploadedTo: '@',
-            },
-            link: function (scope, element, attrs) {
-                scope.message = attrs.message;
-                if (attrs.placeholder) element[0].querySelector('.dz-message').textContent = attrs.placeholder;
-                let dropZone = new DropZone(element[0].querySelector('.dropzone-container'), {
-                    url: scope.uploadUrl,
-                    init: function () {
-                        let dz = this;
-                        dz.on('sending', function (file, xhr, data) {
-                            let token = window.document.querySelector('meta[name=token]').getAttribute('content');
-                            data.append('_token', token);
-                            let uploadedTo = typeof scope.uploadedTo === 'undefined' ? 0 : scope.uploadedTo;
-                            data.append('uploaded_to', uploadedTo);
-                        });
-                        if (typeof scope.eventSuccess !== 'undefined') dz.on('success', scope.eventSuccess);
-                        dz.on('success', function (file, data) {
-                            $(file.previewElement).fadeOut(400, function () {
-                                dz.removeFile(file);
-                            });
-                        });
-                        if (typeof scope.eventError !== 'undefined') dz.on('error', scope.eventError);
-                        dz.on('error', function (file, errorMessage, xhr) {
-                            console.log(errorMessage);
-                            console.log(xhr);
-                            function setMessage(message) {
-                                $(file.previewElement).find('[data-dz-errormessage]').text(message);
-                            }
-
-                            if (xhr.status === 413) setMessage(trans('errors.server_upload_limit'));
-                            if (errorMessage.file) setMessage(errorMessage.file[0]);
-
-                        });
-                    }
-                });
-            }
-        };
-    }]);
-
     /**
      * TinyMCE
      * An angular wrapper around the tinyMCE editor.
@@ -643,128 +534,4 @@ module.exports = function (ngApp, events) {
             }
         };
     }]);
-
-    ngApp.directive('commentReply', [function () {
-        return {
-            restrict: 'E',
-            templateUrl: 'comment-reply.html',
-            scope: {
-              pageId: '=',
-              parentId: '=',
-              parent: '='
-            },
-            link: function (scope, element) {
-                scope.isReply = true;
-                element.find('textarea').focus();
-                scope.$on('evt.comment-success', function (event) {
-                    // no need for the event to do anything more.
-                    event.stopPropagation();
-                    event.preventDefault();
-                    scope.closeBox();
-                });
-
-                scope.closeBox = function () {
-                    element.remove();
-                    scope.$destroy();
-                };
-            }
-        };
-    }]);
-
-    ngApp.directive('commentEdit', [function () {
-         return {
-            restrict: 'E',
-            templateUrl: 'comment-reply.html',
-            scope: {
-              comment: '='
-            },
-            link: function (scope, element) {
-                scope.isEdit = true;
-                element.find('textarea').focus();
-                scope.$on('evt.comment-success', function (event, commentId) {
-                   // no need for the event to do anything more.
-                   event.stopPropagation();
-                   event.preventDefault();
-                   if (commentId === scope.comment.id && !scope.isNew) {
-                       scope.closeBox();
-                   }
-                });
-
-                scope.closeBox = function () {
-                    element.remove();
-                    scope.$destroy();
-                };
-            }
-        };
-    }]);
-
-
-    ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) {
-        return {
-            scope: {
-                comment: '='
-            },
-            link: function (scope, element, attr) {
-                element.on('$destroy', function () {
-                    element.off('click');
-                    scope.$destroy();
-                });
-
-                element.on('click', function (e) {
-                    e.preventDefault();
-                    var $container = element.parents('.comment-actions').first();
-                    if (!$container.length) {
-                        console.error('commentReplyLink directive should be placed inside a container with class comment-box!');
-                        return;
-                    }
-                    if (attr.noCommentReplyDupe) {
-                        removeDupe();
-                    }
-
-                    compileHtml($container, scope, attr.isReply === 'true');
-                });
-            }
-        };
-
-        function compileHtml($container, scope, isReply) {
-            let lnkFunc = null;
-            if (isReply) {
-                lnkFunc = $compile('<comment-reply page-id="comment.pageId" parent-id="comment.id" parent="comment"></comment-reply>');
-            } else {
-                lnkFunc = $compile('<comment-edit comment="comment"></comment-add>');
-            }
-            var compiledHTML = lnkFunc(scope);
-            $container.append(compiledHTML);
-        }
-
-        function removeDupe() {
-            let $existingElement = $document.find('.comments-list comment-reply, .comments-list comment-edit');
-            if (!$existingElement.length) {
-                return;
-            }
-
-            $existingElement.remove();
-        }
-    }]);
-
-    ngApp.directive('commentDeleteLink', ['$window', function ($window) {
-        return {
-            controller: 'CommentDeleteController',
-            scope: {
-                comment: '='
-            },
-            link: function (scope, element, attr, ctrl) {
-
-                element.on('click', function(e) {
-                    e.preventDefault();
-                    var resp = $window.confirm(trans('entities.comment_delete_confirm'));
-                    if (!resp) {
-                        return;
-                    }
-
-                    ctrl.delete(scope.comment);
-                });
-            }
-        };
-    }]);
 };