2 const DropZone = require("dropzone");
3 const MarkdownIt = require("markdown-it");
4 const mdTasksLists = require('markdown-it-task-lists');
5 const code = require('./code');
7 module.exports = function (ngApp, events) {
10 * Common tab controls using simple jQuery functions.
12 ngApp.directive('tabContainer', function() {
15 link: function (scope, element, attrs) {
16 const $content = element.find('[tab-content]');
17 const $buttons = element.find('[tab-button]');
19 if (attrs.tabContainer) {
20 let initial = attrs.tabContainer;
21 $buttons.filter(`[tab-button="${initial}"]`).addClass('selected');
22 $content.hide().filter(`[tab-content="${initial}"]`).show();
24 $content.hide().first().show();
25 $buttons.first().addClass('selected');
28 $buttons.click(function() {
29 let clickedTab = $(this);
30 $buttons.removeClass('selected');
32 let name = clickedTab.addClass('selected').attr('tab-button');
33 $content.filter(`[tab-content="${name}"]`).show();
40 * Sub form component to allow inner-form sections to act like their own forms.
42 ngApp.directive('subForm', function() {
45 link: function (scope, element, attrs) {
46 element.on('keypress', e => {
47 if (e.keyCode === 13) {
52 element.find('button[type="submit"]').click(submitEvent);
54 function submitEvent(e) {
56 if (attrs.subForm) scope.$eval(attrs.subForm);
64 * Used for uploading images
66 ngApp.directive('dropZone', [function () {
70 <div class="dropzone-container">
71 <div class="dz-message">{{message}}</div>
80 link: function (scope, element, attrs) {
81 scope.message = attrs.message;
82 if (attrs.placeholder) element[0].querySelector('.dz-message').textContent = attrs.placeholder;
83 let dropZone = new DropZone(element[0].querySelector('.dropzone-container'), {
87 dz.on('sending', function (file, xhr, data) {
88 let token = window.document.querySelector('meta[name=token]').getAttribute('content');
89 data.append('_token', token);
90 let uploadedTo = typeof scope.uploadedTo === 'undefined' ? 0 : scope.uploadedTo;
91 data.append('uploaded_to', uploadedTo);
93 if (typeof scope.eventSuccess !== 'undefined') dz.on('success', scope.eventSuccess);
94 dz.on('success', function (file, data) {
95 $(file.previewElement).fadeOut(400, function () {
99 if (typeof scope.eventError !== 'undefined') dz.on('error', scope.eventError);
100 dz.on('error', function (file, errorMessage, xhr) {
101 console.log(errorMessage);
103 function setMessage(message) {
104 $(file.previewElement).find('[data-dz-errormessage]').text(message);
107 if (xhr.status === 413) setMessage(trans('errors.server_upload_limit'));
108 if (errorMessage.file) setMessage(errorMessage.file[0]);
119 * Provides some simple logic to create small dropdown menus
121 ngApp.directive('dropdown', [function () {
124 link: function (scope, element, attrs) {
125 const menu = element.find('ul');
129 menu.removeClass('anim menuIn');
133 menu.show().addClass('anim menuIn');
134 element.mouseleave(hide);
136 // Focus on input if exist in dropdown and hide on enter press
137 let inputs = menu.find('input');
138 if (inputs.length > 0) inputs.first().focus();
141 // Hide menu on option click
142 element.on('click', '> ul a', hide);
143 // Show dropdown on toggle click.
144 element.find('[dropdown-toggle]').on('click', show);
145 // Hide menu on enter press in inputs
146 element.on('keypress', 'input', event => {
147 if (event.keyCode !== 13) return true;
148 event.preventDefault();
158 * An angular wrapper around the tinyMCE editor.
160 ngApp.directive('tinymce', ['$timeout', function ($timeout) {
168 link: function (scope, element, attrs) {
170 function tinyMceSetup(editor) {
171 editor.on('ExecCommand change NodeChange ObjectResized', (e) => {
172 let content = editor.getContent();
174 scope.mceModel = content;
176 scope.mceChange(content);
179 editor.on('keydown', (event) => {
180 scope.$emit('editor-keydown', event);
183 editor.on('init', (e) => {
184 scope.mceModel = editor.getContent();
187 scope.$on('html-update', (event, value) => {
188 editor.setContent(value);
189 editor.selection.select(editor.getBody(), true);
190 editor.selection.collapse(false);
191 scope.mceModel = editor.getContent();
195 scope.tinymce.extraSetups.push(tinyMceSetup);
196 tinymce.init(scope.tinymce);
201 const md = new MarkdownIt({html: true});
202 md.use(mdTasksLists, {label: true});
206 * Handles the logic for just the editor input field.
208 ngApp.directive('markdownInput', ['$timeout', function ($timeout) {
215 link: function (scope, element, attrs) {
218 element = element.find('textarea').first();
219 let cm = code.markdownEditor(element[0]);
221 // Custom key commands
222 let metaKey = code.getMetaKey();
223 const extraKeys = {};
224 // Insert Image shortcut
225 extraKeys[`${metaKey}-Alt-I`] = function(cm) {
226 let selectedText = cm.getSelection();
227 let newText = ``;
228 let cursorPos = cm.getCursor('from');
229 cm.replaceSelection(newText);
230 cm.setCursor(cursorPos.line, cursorPos.ch + newText.length -1);
233 extraKeys[`${metaKey}-S`] = function(cm) {scope.$emit('save-draft');};
234 // Show link selector
235 extraKeys[`Shift-${metaKey}-K`] = function(cm) {showLinkSelector()};
237 extraKeys[`${metaKey}-K`] = function(cm) {insertLink()};
239 extraKeys[`${metaKey}-1`] = function(cm) {replaceLineStart('##');};
240 extraKeys[`${metaKey}-2`] = function(cm) {replaceLineStart('###');};
241 extraKeys[`${metaKey}-3`] = function(cm) {replaceLineStart('####');};
242 extraKeys[`${metaKey}-4`] = function(cm) {replaceLineStart('#####');};
243 extraKeys[`${metaKey}-5`] = function(cm) {replaceLineStart('');};
244 extraKeys[`${metaKey}-d`] = function(cm) {replaceLineStart('');};
245 extraKeys[`${metaKey}-6`] = function(cm) {replaceLineStart('>');};
246 extraKeys[`${metaKey}-q`] = function(cm) {replaceLineStart('>');};
247 extraKeys[`${metaKey}-7`] = function(cm) {wrapSelection('\n```\n', '\n```');};
248 extraKeys[`${metaKey}-8`] = function(cm) {wrapSelection('`', '`');};
249 extraKeys[`Shift-${metaKey}-E`] = function(cm) {wrapSelection('`', '`');};
250 extraKeys[`${metaKey}-9`] = function(cm) {wrapSelection('<p class="callout info">', '</div>');};
251 cm.setOption('extraKeys', extraKeys);
253 // Update data on content change
254 cm.on('change', (instance, changeObj) => {
258 // Handle scroll to sync display view
259 cm.on('scroll', instance => {
260 // Thanks to http://liuhao.im/english/2015/11/10/the-sync-scroll-of-markdown-editor-in-javascript.html
261 let scroll = instance.getScrollInfo();
262 let atEnd = scroll.top + scroll.clientHeight === scroll.height;
264 scope.$emit('markdown-scroll', -1);
267 let lineNum = instance.lineAtHeight(scroll.top, 'local');
268 let range = instance.getRange({line: 0, ch: null}, {line: lineNum, ch: null});
269 let parser = new DOMParser();
270 let doc = parser.parseFromString(md.render(range), 'text/html');
271 let totalLines = doc.documentElement.querySelectorAll('body > *');
272 scope.$emit('markdown-scroll', totalLines.length);
275 // Handle image paste
276 cm.on('paste', (cm, event) => {
277 if (!event.clipboardData || !event.clipboardData.items) return;
278 for (let i = 0; i < event.clipboardData.items.length; i++) {
279 uploadImage(event.clipboardData.items[i].getAsFile());
283 // Handle images on drag-drop
284 cm.on('drop', (cm, event) => {
285 event.stopPropagation();
286 event.preventDefault();
287 let cursorPos = cm.coordsChar({left: event.pageX, top: event.pageY});
288 cm.setCursor(cursorPos);
289 if (!event.dataTransfer || !event.dataTransfer.files) return;
290 for (let i = 0; i < event.dataTransfer.files.length; i++) {
291 uploadImage(event.dataTransfer.files[i]);
295 // Helper to replace editor content
296 function replaceContent(search, replace) {
297 let text = cm.getValue();
298 let cursor = cm.listSelections();
299 cm.setValue(text.replace(search, replace));
300 cm.setSelections(cursor);
303 // Helper to replace the start of the line
304 function replaceLineStart(newStart) {
305 let cursor = cm.getCursor();
306 let lineContent = cm.getLine(cursor.line);
307 let lineLen = lineContent.length;
308 let lineStart = lineContent.split(' ')[0];
310 // Remove symbol if already set
311 if (lineStart === newStart) {
312 lineContent = lineContent.replace(`${newStart} `, '');
313 cm.replaceRange(lineContent, {line: cursor.line, ch: 0}, {line: cursor.line, ch: lineLen});
314 cm.setCursor({line: cursor.line, ch: cursor.ch - (newStart.length + 1)});
318 let alreadySymbol = /^[#>`]/.test(lineStart);
321 posDif = newStart.length - lineStart.length;
322 lineContent = lineContent.replace(lineStart, newStart).trim();
323 } else if (newStart !== '') {
324 posDif = newStart.length + 1;
325 lineContent = newStart + ' ' + lineContent;
327 cm.replaceRange(lineContent, {line: cursor.line, ch: 0}, {line: cursor.line, ch: lineLen});
328 cm.setCursor({line: cursor.line, ch: cursor.ch + posDif});
331 function wrapLine(start, end) {
332 let cursor = cm.getCursor();
333 let lineContent = cm.getLine(cursor.line);
334 let lineLen = lineContent.length;
335 let newLineContent = lineContent;
337 if (lineContent.indexOf(start) === 0 && lineContent.slice(-end.length) === end) {
338 newLineContent = lineContent.slice(start.length, lineContent.length - end.length);
340 newLineContent = `${start}${lineContent}${end}`;
343 cm.replaceRange(newLineContent, {line: cursor.line, ch: 0}, {line: cursor.line, ch: lineLen});
344 cm.setCursor({line: cursor.line, ch: cursor.ch + (newLineContent.length - lineLen)});
347 function wrapSelection(start, end) {
348 let selection = cm.getSelection();
349 if (selection === '') return wrapLine(start, end);
350 let newSelection = selection;
354 if (selection.indexOf(start) === 0 && selection.slice(-end.length) === end) {
355 newSelection = selection.slice(start.length, selection.length - end.length);
356 endDiff = -(end.length + start.length);
358 newSelection = `${start}${selection}${end}`;
359 endDiff = start.length + end.length;
362 let selections = cm.listSelections()[0];
363 cm.replaceSelection(newSelection);
364 let headFirst = selections.head.ch <= selections.anchor.ch;
365 selections.head.ch += headFirst ? frontDiff : endDiff;
366 selections.anchor.ch += headFirst ? endDiff : frontDiff;
367 cm.setSelections([selections]);
370 // Handle image upload and add image into markdown content
371 function uploadImage(file) {
372 if (file === null || file.type.indexOf('image') !== 0) return;
376 let fileNameMatches = file.name.match(/\.(.+)$/);
377 if (fileNameMatches.length > 1) ext = fileNameMatches[1];
380 // Insert image into markdown
381 let id = "image-" + Math.random().toString(16).slice(2);
382 let placeholderImage = window.baseUrl(`/loading.gif#upload${id}`);
383 let selectedText = cm.getSelection();
384 let placeHolderText = ``;
385 cm.replaceSelection(placeHolderText);
387 let remoteFilename = "image-" + Date.now() + "." + ext;
388 let formData = new FormData();
389 formData.append('file', file, remoteFilename);
391 window.$http.post('/images/gallery/upload', formData).then(resp => {
392 replaceContent(placeholderImage, resp.data.thumbs.display);
394 events.emit('error', trans('errors.image_upload_error'));
395 replaceContent(placeHolderText, selectedText);
400 // Show the popup link selector and insert a link when finished
401 function showLinkSelector() {
402 let cursorPos = cm.getCursor('from');
403 window.showEntityLinkSelector(entity => {
404 let selectedText = cm.getSelection() || entity.name;
405 let newText = `[${selectedText}](${entity.link})`;
407 cm.replaceSelection(newText);
408 cm.setCursor(cursorPos.line, cursorPos.ch + newText.length);
412 function insertLink() {
413 let cursorPos = cm.getCursor('from');
414 let selectedText = cm.getSelection() || '';
415 let newText = `[${selectedText}]()`;
417 cm.replaceSelection(newText);
418 let cursorPosDiff = (selectedText === '') ? -3 : -1;
419 cm.setCursor(cursorPos.line, cursorPos.ch + newText.length+cursorPosDiff);
422 // Show the image manager and handle image insertion
423 function showImageManager() {
424 let cursorPos = cm.getCursor('from');
425 window.ImageManager.showExternal(image => {
426 let selectedText = cm.getSelection();
427 let newText = "";
429 cm.replaceSelection(newText);
430 cm.setCursor(cursorPos.line, cursorPos.ch + newText.length);
434 // Update the data models and rendered output
435 function update(instance) {
436 let content = instance.getValue();
437 element.val(content);
439 scope.mdModel = content;
440 scope.mdChange(md.render(content));
445 // Listen to commands from parent scope
446 scope.$on('md-insert-link', showLinkSelector);
447 scope.$on('md-insert-image', showImageManager);
448 scope.$on('markdown-update', (event, value) => {
451 scope.mdModel = value;
452 scope.mdChange(md.render(value));
461 * Handles all functionality of the markdown editor.
463 ngApp.directive('markdownEditor', ['$timeout', '$rootScope', function ($timeout, $rootScope) {
466 link: function (scope, element, attrs) {
469 const $display = element.find('.markdown-display').first();
470 const $insertImage = element.find('button[data-action="insertImage"]');
471 const $insertEntityLink = element.find('button[data-action="insertEntityLink"]');
473 // Prevent markdown display link click redirect
474 $display.on('click', 'a', function(event) {
475 event.preventDefault();
476 window.open(this.getAttribute('href'));
480 $insertEntityLink.click(e => {scope.$broadcast('md-insert-link');});
481 $insertImage.click(e => {scope.$broadcast('md-insert-image');});
483 // Handle scroll sync event from editor scroll
484 $rootScope.$on('markdown-scroll', (event, lineCount) => {
485 let elems = $display[0].children[0].children;
486 if (elems.length > lineCount) {
487 let topElem = (lineCount === -1) ? elems[elems.length-1] : elems[lineCount];
489 scrollTop: topElem.offsetTop
490 }, {queue: false, duration: 200, easing: 'linear'});
498 * Page Editor Toolbox
499 * Controls all functionality for the sliding toolbox
500 * on the page edit view.
502 ngApp.directive('toolbox', [function () {
505 link: function (scope, elem, attrs) {
507 // Get common elements
508 const $buttons = elem.find('[toolbox-tab-button]');
509 const $content = elem.find('[toolbox-tab-content]');
510 const $toggle = elem.find('[toolbox-toggle]');
512 // Handle toolbox toggle click
513 $toggle.click((e) => {
514 elem.toggleClass('open');
517 // Set an active tab/content by name
518 function setActive(tabName, openToolbox) {
519 $buttons.removeClass('active');
521 $buttons.filter(`[toolbox-tab-button="${tabName}"]`).addClass('active');
522 $content.filter(`[toolbox-tab-content="${tabName}"]`).show();
523 if (openToolbox) elem.addClass('open');
526 // Set the first tab content active on load
527 setActive($content.first().attr('toolbox-tab-content'), false);
529 // Handle tab button click
530 $buttons.click(function (e) {
531 let name = $(this).attr('toolbox-tab-button');
532 setActive(name, true);
539 * Tag Autosuggestions
540 * Listens to child inputs and provides autosuggestions depending on field type
541 * and input. Suggestions provided by server.
543 ngApp.directive('tagAutosuggestions', ['$http', function ($http) {
546 link: function (scope, elem, attrs) {
548 // Local storage for quick caching.
549 const localCache = {};
551 // Create suggestion element
552 const suggestionBox = document.createElement('ul');
553 suggestionBox.className = 'suggestion-box';
554 suggestionBox.style.position = 'absolute';
555 suggestionBox.style.display = 'none';
556 const $suggestionBox = $(suggestionBox);
558 // General state tracking
559 let isShowing = false;
560 let currentInput = false;
563 // Listen to input events on autosuggest fields
564 elem.on('input focus', '[autosuggest]', function (event) {
565 let $input = $(this);
566 let val = $input.val();
567 let url = $input.attr('autosuggest');
568 let type = $input.attr('autosuggest-type');
570 // Add name param to request if for a value
571 if (type.toLowerCase() === 'value') {
572 let $nameInput = $input.closest('tr').find('[autosuggest-type="name"]').first();
573 let nameVal = $nameInput.val();
574 if (nameVal !== '') {
575 url += '?name=' + encodeURIComponent(nameVal);
579 let suggestionPromise = getSuggestions(val.slice(0, 3), url);
580 suggestionPromise.then(suggestions => {
581 if (val.length === 0) {
582 displaySuggestions($input, suggestions.slice(0, 6));
584 suggestions = suggestions.filter(item => {
585 return item.toLowerCase().indexOf(val.toLowerCase()) !== -1;
587 displaySuggestions($input, suggestions);
592 // Hide autosuggestions when input loses focus.
593 // Slight delay to allow clicks.
594 let lastFocusTime = 0;
595 elem.on('blur', '[autosuggest]', function (event) {
596 let startTime = Date.now();
598 if (lastFocusTime < startTime) {
599 $suggestionBox.hide();
604 elem.on('focus', '[autosuggest]', function (event) {
605 lastFocusTime = Date.now();
608 elem.on('keydown', '[autosuggest]', function (event) {
609 if (!isShowing) return;
611 let suggestionElems = suggestionBox.childNodes;
612 let suggestCount = suggestionElems.length;
615 if (event.keyCode === 40) {
616 let newActive = (active === suggestCount - 1) ? 0 : active + 1;
617 changeActiveTo(newActive, suggestionElems);
620 else if (event.keyCode === 38) {
621 let newActive = (active === 0) ? suggestCount - 1 : active - 1;
622 changeActiveTo(newActive, suggestionElems);
625 else if ((event.keyCode === 13 || event.keyCode === 9) && !event.shiftKey) {
626 currentInput[0].value = suggestionElems[active].textContent;
627 currentInput.focus();
628 $suggestionBox.hide();
630 if (event.keyCode === 13) {
631 event.preventDefault();
637 // Change the active suggestion to the given index
638 function changeActiveTo(index, suggestionElems) {
639 suggestionElems[active].className = '';
641 suggestionElems[active].className = 'active';
644 // Display suggestions on a field
645 let prevSuggestions = [];
647 function displaySuggestions($input, suggestions) {
649 // Hide if no suggestions
650 if (suggestions.length === 0) {
651 $suggestionBox.hide();
653 prevSuggestions = suggestions;
657 // Otherwise show and attach to input
659 $suggestionBox.show();
662 if ($input !== currentInput) {
663 $suggestionBox.detach();
664 $input.after($suggestionBox);
665 currentInput = $input;
668 // Return if no change
669 if (prevSuggestions.join() === suggestions.join()) {
670 prevSuggestions = suggestions;
675 $suggestionBox[0].innerHTML = '';
676 for (let i = 0; i < suggestions.length; i++) {
677 let suggestion = document.createElement('li');
678 suggestion.textContent = suggestions[i];
679 suggestion.onclick = suggestionClick;
681 suggestion.className = 'active';
684 $suggestionBox[0].appendChild(suggestion);
687 prevSuggestions = suggestions;
690 // Suggestion click event
691 function suggestionClick(event) {
692 currentInput[0].value = this.textContent;
693 currentInput.focus();
694 $suggestionBox.hide();
698 // Get suggestions & cache
699 function getSuggestions(input, url) {
700 let hasQuery = url.indexOf('?') !== -1;
701 let searchUrl = url + (hasQuery ? '&' : '?') + 'search=' + encodeURIComponent(input);
703 // Get from local cache if exists
704 if (typeof localCache[searchUrl] !== 'undefined') {
705 return new Promise((resolve, reject) => {
706 resolve(localCache[searchUrl]);
710 return $http.get(searchUrl).then(response => {
711 localCache[searchUrl] = response.data;
712 return response.data;
720 ngApp.directive('entityLinkSelector', [function($http) {
723 link: function(scope, element, attrs) {
725 const selectButton = element.find('.entity-link-selector-confirm');
726 let callback = false;
727 let entitySelection = null;
729 // Handle entity selection change, Stores the selected entity locally
730 function entitySelectionChange(entity) {
731 entitySelection = entity;
732 if (entity === null) {
733 selectButton.attr('disabled', 'true');
735 selectButton.removeAttr('disabled');
738 events.listen('entity-select-change', entitySelectionChange);
740 // Handle selection confirm button click
741 selectButton.click(event => {
743 if (entitySelection !== null) callback(entitySelection);
746 // Show selector interface
751 // Hide selector interface
753 element.fadeOut(240);
756 // Listen to confirmation of entity selections (doubleclick)
757 events.listen('entity-select-confirm', entity => {
762 // Show entity selector, Accessible globally, and store the callback
763 window.showEntityLinkSelector = function(passedCallback) {
765 callback = passedCallback;
773 ngApp.directive('entitySelector', ['$http', '$sce', function ($http, $sce) {
777 link: function (scope, element, attrs) {
778 scope.loading = true;
779 scope.entityResults = false;
782 // Add input for forms
783 const input = element.find('[entity-selector-input]').first();
785 // Detect double click events
787 function isDoubleClick() {
788 let now = Date.now();
789 let answer = now - lastClick < 300;
794 // Listen to entity item clicks
795 element.on('click', '.entity-list a', function(event) {
796 event.preventDefault();
797 event.stopPropagation();
798 let item = $(this).closest('[data-entity-type]');
799 itemSelect(item, isDoubleClick());
801 element.on('click', '[data-entity-type]', function(event) {
802 itemSelect($(this), isDoubleClick());
805 // Select entity action
806 function itemSelect(item, doubleClick) {
807 let entityType = item.attr('data-entity-type');
808 let entityId = item.attr('data-entity-id');
809 let isSelected = !item.hasClass('selected') || doubleClick;
810 element.find('.selected').removeClass('selected').removeClass('primary-background');
811 if (isSelected) item.addClass('selected').addClass('primary-background');
812 let newVal = isSelected ? `${entityType}:${entityId}` : '';
816 events.emit('entity-select-change', null);
819 if (!doubleClick && !isSelected) return;
821 let link = item.find('.entity-list-item-link').attr('href');
822 let name = item.find('.entity-list-item-name').text();
825 events.emit('entity-select-confirm', {
826 id: Number(entityId),
833 events.emit('entity-select-change', {
834 id: Number(entityId),
841 // Get search url with correct types
842 function getSearchUrl() {
843 let types = (attrs.entityTypes) ? encodeURIComponent(attrs.entityTypes) : encodeURIComponent('page,book,chapter');
844 return window.baseUrl(`/ajax/search/entities?types=${types}`);
847 // Get initial contents
848 $http.get(getSearchUrl()).then(resp => {
849 scope.entityResults = $sce.trustAsHtml(resp.data);
850 scope.loading = false;
853 // Search when typing
854 scope.searchEntities = function() {
855 scope.loading = true;
857 let url = getSearchUrl() + '&term=' + encodeURIComponent(scope.search);
858 $http.get(url).then(resp => {
859 scope.entityResults = $sce.trustAsHtml(resp.data);
860 scope.loading = false;
867 ngApp.directive('commentReply', [function () {
870 templateUrl: 'comment-reply.html',
876 link: function (scope, element) {
877 scope.isReply = true;
878 element.find('textarea').focus();
879 scope.$on('evt.comment-success', function (event) {
880 // no need for the event to do anything more.
881 event.stopPropagation();
882 event.preventDefault();
886 scope.closeBox = function () {
894 ngApp.directive('commentEdit', [function () {
897 templateUrl: 'comment-reply.html',
901 link: function (scope, element) {
903 element.find('textarea').focus();
904 scope.$on('evt.comment-success', function (event, commentId) {
905 // no need for the event to do anything more.
906 event.stopPropagation();
907 event.preventDefault();
908 if (commentId === scope.comment.id && !scope.isNew) {
913 scope.closeBox = function () {
922 ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) {
927 link: function (scope, element, attr) {
928 element.on('$destroy', function () {
929 element.off('click');
933 element.on('click', function (e) {
935 var $container = element.parents('.comment-actions').first();
936 if (!$container.length) {
937 console.error('commentReplyLink directive should be placed inside a container with class comment-box!');
940 if (attr.noCommentReplyDupe) {
944 compileHtml($container, scope, attr.isReply === 'true');
949 function compileHtml($container, scope, isReply) {
952 lnkFunc = $compile('<comment-reply page-id="comment.pageId" parent-id="comment.id" parent="comment"></comment-reply>');
954 lnkFunc = $compile('<comment-edit comment="comment"></comment-add>');
956 var compiledHTML = lnkFunc(scope);
957 $container.append(compiledHTML);
960 function removeDupe() {
961 let $existingElement = $document.find('.comments-list comment-reply, .comments-list comment-edit');
962 if (!$existingElement.length) {
966 $existingElement.remove();
970 ngApp.directive('commentDeleteLink', ['$window', function ($window) {
972 controller: 'CommentDeleteController',
976 link: function (scope, element, attr, ctrl) {
978 element.on('click', function(e) {
980 var resp = $window.confirm(trans('entities.comment_delete_confirm'));
985 ctrl.delete(scope.comment);