Skip to content

Commit

Permalink
Merge pull request #6 from PengYilong/hasmany
Browse files Browse the repository at this point in the history
fix 重复多次初始化问题
  • Loading branch information
jxlwqq authored Dec 15, 2021
2 parents 1320aed + 3b10fbf commit be5ab91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion resources/views/editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@include('admin::form.error')

<div id="{{$id}}" class="quill-{{$id}}" style="height: {{$height}}">
<div id="{{$id}}" class="quill-{{$id}}" style="height: {{$height}}" data-initialed="false">
<p>{!! old($column, $value) !!}</p>
</div>

Expand Down
29 changes: 8 additions & 21 deletions src/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,22 @@ public function render()
$options = json_encode($options);

$this->script = <<<EOT
// solved the conflict
Quill.register("modules/htmlEditButton", htmlEditButton);
// init last editor for adding
var options = {$options},
editorClass = 'quill-{$this->id}',
editors = $('.' + editorClass),
lastEditor = editors.last(),
editorLength = editors.length,
editorMark = editorClass+editorLength;
var options = {$options};
// add a mark to the last editor
lastEditor.addClass(editorMark);
new Quill('.' + editorMark, options);
// init editors that don't include the last one
$('.' + editorClass).each(function(index, item) {
if(index !== editorLength - 1) {
index++;
$(this).addClass(editorClass+index);
new Quill('.' + editorClass + index, options);
$('.quill-{$this->id}').each(function(index, item) {
if( false === $(this).data('initialed') ) { // prevent initialed twice
new Quill(item, options);
$(this).data('initialed', true); // mark the editor as initialed
}
});
$('button[type="submit"]').click(function() {
$('.' + editorClass).each(function(index, item) {
var editorConent = item.children[0].innerHTML;
$('.quill-{$this->id}').each(function(index, item) {
editorConent = item.children[0].innerHTML;
$(this).siblings('input[type="hidden"]').val(editorConent);
});
Expand Down

0 comments on commit be5ab91

Please sign in to comment.