mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-24 11:52:34 +01:00
#47 - Gets rid of simplemde
This commit is contained in:
parent
3368fe42d8
commit
8b82753218
@ -17,7 +17,7 @@ class CommentController extends Controller
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function save(Request $request, $pageId, $commentId)
|
||||
public function save(Request $request, $pageId, $commentId = null)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'text' => 'required|string',
|
||||
|
15
public/libs/simplemde/simplemde.min.js
vendored
15
public/libs/simplemde/simplemde.min.js
vendored
File diff suppressed because one or more lines are too long
@ -684,19 +684,20 @@ module.exports = function (ngApp, events) {
|
||||
|
||||
// CommentCrudController
|
||||
ngApp.controller('CommentAddController', ['$scope', '$http', function ($scope, $http) {
|
||||
const MarkdownIt = require("markdown-it");
|
||||
const md = new MarkdownIt({html: true});
|
||||
let vm = this;
|
||||
let comment = {};
|
||||
$scope.errors = {};
|
||||
vm.saveComment = function () {
|
||||
let pageId = $scope.comment.pageId;
|
||||
let comment = $scope.comment.newComment;
|
||||
let commentHTML = $scope.getCommentHTML();
|
||||
let commentHTML = md.render($scope.comment.newComment);
|
||||
|
||||
$http.post(window.baseUrl(`/ajax/page/${pageId}/comment/`), {
|
||||
text: comment,
|
||||
html: commentHTML
|
||||
}).then(resp => {
|
||||
$scope.clearInput();
|
||||
$scope.comment.newComment = '';
|
||||
if (!resp.data || resp.data.status !== 'success') {
|
||||
return events.emit('error', trans('error'));
|
||||
}
|
||||
|
@ -818,53 +818,6 @@ 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 {
|
||||
|
@ -57,4 +57,11 @@
|
||||
|
||||
.comment-editor {
|
||||
margin-top: 2em;
|
||||
|
||||
textarea {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
min-height: 120px;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -12,7 +12,6 @@
|
||||
@import "animations";
|
||||
@import "tinymce";
|
||||
@import "highlightjs";
|
||||
@import "simplemde";
|
||||
@import "components";
|
||||
@import "header";
|
||||
@import "lists";
|
||||
|
@ -239,5 +239,6 @@ return [
|
||||
* Comments
|
||||
*/
|
||||
'comment' => 'Comment',
|
||||
'comments' => 'Comments'
|
||||
'comments' => 'Comments',
|
||||
'comment_placeholder' => 'Enter your comments here, markdown supported...'
|
||||
];
|
@ -1,13 +1,11 @@
|
||||
<div class="comment-editor" ng-controller="CommentAddController as vm" ng-cloak>
|
||||
<form novalidate>
|
||||
<div simple-markdown-input smd-model="comment.newComment" smd-get-content="getCommentHTML" smd-clear="clearInput">
|
||||
<textarea name="markdown" rows="3"
|
||||
@if($errors->has('markdown')) class="neg" @endif>@if(isset($model) ||
|
||||
old('markdown')){{htmlspecialchars( old('markdown') ? old('markdown') : ($model->markdown === '' ? $model->html : $model->markdown))}}@endif</textarea>
|
||||
</div>
|
||||
<form novalidate>
|
||||
<textarea name="markdown" rows="3" ng-model="comment.newComment" placeholder="{{ trans('entities.comment_placeholder') }}"
|
||||
@if($errors->has('markdown')) class="neg" @endif>@if(isset($model) ||
|
||||
old('markdown')){{htmlspecialchars( old('markdown') ? old('markdown') : ($model->markdown === '' ? $model->html : $model->markdown))}}@endif</textarea>
|
||||
<input type="hidden" ng-model="pageId" name="comment.pageId" value="{{$pageId}}" ng-init="comment.pageId = {{$pageId }}">
|
||||
<button type="submit" class="button pos" ng-click="vm.saveComment()">Save</button>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@if($errors->has('markdown'))
|
||||
|
@ -1,6 +1,3 @@
|
||||
@section('head')
|
||||
<script src="{{ baseUrl("/libs/simplemde/simplemde.min.js") }}"></script>
|
||||
@stop
|
||||
<script type="text/ng-template" id="comment-list-item.html">
|
||||
@include('comments/list-item')
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user