From bc067e9ad41804de26ec37fab90ec413b48b2270 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 22 Jul 2017 14:02:47 +0100 Subject: [PATCH 1/6] Updated dropdowns to hide after option click Fixes #429 --- resources/assets/js/controllers.js | 2 +- resources/assets/js/directives.js | 40 +++++++++++++++++------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/resources/assets/js/controllers.js b/resources/assets/js/controllers.js index ac1c3487c..9337ea889 100644 --- a/resources/assets/js/controllers.js +++ b/resources/assets/js/controllers.js @@ -379,7 +379,7 @@ module.exports = function (ngApp, events) { */ $scope.discardDraft = function () { let url = window.baseUrl('/ajax/page/' + pageId); - $http.get(url).then((responseData) => { + $http.get(url).then(responseData => { if (autoSave) $interval.cancel(autoSave); $scope.draftText = trans('entities.pages_editing_page'); $scope.isUpdateDraft = false; diff --git a/resources/assets/js/directives.js b/resources/assets/js/directives.js index 51f1b7579..d783fd682 100644 --- a/resources/assets/js/directives.js +++ b/resources/assets/js/directives.js @@ -123,25 +123,31 @@ module.exports = function (ngApp, events) { restrict: 'A', link: function (scope, element, attrs) { const menu = element.find('ul'); - element.find('[dropdown-toggle]').on('click', function () { + + function hide() { + menu.hide(); + menu.removeClass('anim menuIn'); + } + + function show() { menu.show().addClass('anim menuIn'); + element.mouseleave(hide); + + // Focus on input if exist in dropdown and hide on enter press let inputs = menu.find('input'); - let hasInput = inputs.length > 0; - if (hasInput) { - inputs.first().focus(); - element.on('keypress', 'input', event => { - if (event.keyCode === 13) { - event.preventDefault(); - menu.hide(); - menu.removeClass('anim menuIn'); - return false; - } - }); - } - element.mouseleave(function () { - menu.hide(); - menu.removeClass('anim menuIn'); - }); + if (inputs.length > 0) inputs.first().focus(); + } + + // Hide menu on option click + element.on('click', '> ul a', hide); + // Show dropdown on toggle click. + element.find('[dropdown-toggle]').on('click', show); + // Hide menu on enter press in inputs + element.on('keypress', 'input', event => { + if (event.keyCode !== 13) return true; + event.preventDefault(); + hide(); + return false; }); } }; From b12e2ceada9b1b8a382b76c896fc392adcdf5b84 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 22 Jul 2017 14:21:56 +0100 Subject: [PATCH 2/6] Added included content into page's text view Allows rendered content to be shown in listings and used in searches. Also prevented angular tags in content being parsed in listings. Fixes #442 --- app/Repos/EntityRepo.php | 19 +++++++++++++++---- resources/views/books/show.blade.php | 4 ++-- resources/views/chapters/show.blade.php | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index 7bc5fc4fc..7865de772 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -571,7 +571,7 @@ class EntityRepo $draftPage->slug = $this->findSuitableSlug('page', $draftPage->name, false, $draftPage->book->id); $draftPage->html = $this->formatHtml($input['html']); - $draftPage->text = strip_tags($draftPage->html); + $draftPage->text = $this->pageToPlainText($draftPage->html); $draftPage->draft = false; $draftPage->revision_count = 1; @@ -713,6 +713,17 @@ class EntityRepo return $content; } + /** + * Get the plain text version of a page's content. + * @param Page $page + * @return string + */ + public function pageToPlainText(Page $page) + { + $html = $this->renderPage($page); + return strip_tags($html); + } + /** * Get a new draft page instance. * @param Book $book @@ -816,7 +827,7 @@ class EntityRepo $userId = user()->id; $page->fill($input); $page->html = $this->formatHtml($input['html']); - $page->text = strip_tags($page->html); + $page->text = $this->pageToPlainText($page); if (setting('app-editor') !== 'markdown') $page->markdown = ''; $page->updated_by = $userId; $page->revision_count++; @@ -933,7 +944,7 @@ class EntityRepo $revision = $page->revisions()->where('id', '=', $revisionId)->first(); $page->fill($revision->toArray()); $page->slug = $this->findSuitableSlug('page', $page->name, $page->id, $book->id); - $page->text = strip_tags($page->html); + $page->text = $this->pageToPlainText($page->html); $page->updated_by = user()->id; $page->save(); $this->searchService->indexEntity($page); @@ -953,7 +964,7 @@ class EntityRepo if ($page->draft) { $page->fill($data); if (isset($data['html'])) { - $page->text = strip_tags($data['html']); + $page->text = $this->pageToPlainText($data['html']); } $page->save(); return $page; diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index ddbe7a0a4..353018dbc 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -50,7 +50,7 @@ -
+
@@ -112,7 +112,7 @@ @endif -
+

{{ $chapter->name }}

@@ -116,7 +116,7 @@ @endif