101 lines
4.2 KiB
PHP
101 lines
4.2 KiB
PHP
@php
|
|
$o = $o ?? 'X';
|
|
@endphp
|
|
<div class="alert alert-warning @if(!$tmpl)dropdownGroup @else d-none dropdownTemplate @endif" role="alert">
|
|
<button type="button" class="close" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
<div class="form-group">
|
|
<label for="{{ $i.$k }}_title_{{ ($tmpl ? 'X' : $o) }}" data-count="{{ $o }}"><small>{{ __('Titre') }}*</small></label>
|
|
<input id="{{ $i.$k }}_title_{{ ($tmpl ? 'X' : $o) }}" type="text" class="form-control" name="content[{{$i}}][content][{{$k}}][value][{{ ($tmpl ? 'X' : $o) }}][title]" placeholder="Titre" value="{{ old("content.$i.content.$k.value.$o.title") ?? (!$tmpl ? ($dropdown['title'] ?? '') : '') }}">
|
|
<br>
|
|
<label for="{{ $i.$k }}_html_{{ ($tmpl ? 'X' : $o) }}"><small>{{ __('Contenu') }}*</small></label>
|
|
<custom-ckeditor
|
|
id="{{ $i.$k }}_html_{{ ($tmpl ? 'X' : $o) }}"
|
|
class="CKEDITOR"
|
|
name="content[{{$i}}][content][{{$k}}][value][{{ ($tmpl ? 'X' : $o) }}][html]"
|
|
dbtext="{{ old("content.$i.content.$k.value.$o.html") ?? (!$tmpl ? ($dropdown['html'] ?? '') : '') }}"></custom-ckeditor>
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
if(!__MINIACF) {
|
|
var __MINIACF = {};
|
|
}
|
|
if(!__MINIACF.dropdown) {
|
|
__MINIACF.dropdown = true;
|
|
if(!__MINIACF.loadedEditors) {
|
|
__MINIACF.loadedEditors = [];
|
|
}
|
|
$(document).ready(function() {
|
|
var cloneFn = function(e) {
|
|
e.preventDefault();
|
|
$(this).parent().fadeOut(300, function() { this.remove(); });
|
|
};
|
|
// dropdowns
|
|
$('.dropdownGroup').each(function(k, grp) {
|
|
$(grp).children('button').first().on('click', cloneFnDropdown);
|
|
});
|
|
var cloneFnDropdown = function(e) {
|
|
let editorDom = $(this).parents('div.alert').find('div.CKEDITOR')
|
|
if(editorDom) {
|
|
for(let editor of __MINIACF.loadedEditors) {
|
|
if(editor.$el === editorDom[0]) {
|
|
editor.$destroy();
|
|
cloneFn.apply(this, [e]);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
var setDataNumDropdown = function(c , div) {
|
|
if($(div).hasClass('d-none')) {
|
|
return;
|
|
}
|
|
$(div).find('custom-ckeditor').each(function(o, el) {
|
|
__MINIACF.loadedEditors.push(new Vue({ el: el }));
|
|
});
|
|
$(div).find('input').each(function(o, el) {
|
|
if(!$(el).hasClass('form-control')) {
|
|
return;
|
|
}
|
|
if (el.id.length) {
|
|
let xid = el.id.split('_');
|
|
xid[2] = c;
|
|
el.id = xid.join('_');
|
|
}
|
|
if ($(el).prev().attr('for')) {
|
|
let xfor = $(el).prev().attr('for').split('_');
|
|
xfor[2] = c;
|
|
$(el).prev().attr('for', xfor.join('_'));
|
|
}
|
|
$(el).attr('name', $(el).attr('name')
|
|
.replace(/(?:\[(X|[0-9]*)\])\[(title|html)\]$/, '[' + (c-1) + '][$2]'));
|
|
console.log(el)
|
|
});
|
|
};
|
|
$('.dropdownAdd').on('click', function(e) {
|
|
e.preventDefault();
|
|
var $t = $($(this).parent().parent().find('.dropdownTemplate').first()).clone().removeClass('d-none');
|
|
var $self = $(this);
|
|
$t.insertBefore($(this).parent());
|
|
$t.children('button').first().on('click', cloneFnDropdown);
|
|
$self.parent().parent().find('div.alert').each(setDataNumDropdown);
|
|
});
|
|
$('.dropdownAdd').parent().parent().on('click', 'button.close', function() {
|
|
var $self = $(this).parent().parent();
|
|
setTimeout(function() {
|
|
$self.find('div.alert').each(setDataNumDropdown);
|
|
}, 400);
|
|
});
|
|
// init CK on DROPDOWNS
|
|
$('.dropdownAdd').parent().parent().find('div.alert').each(function(i, el) {
|
|
if($(el).hasClass('d-none')) {
|
|
return;
|
|
}
|
|
__MINIACF.loadedEditors.push(new Vue({ el: $(el).find('custom-ckeditor')[0] }));
|
|
})
|
|
});
|
|
}
|
|
</script>
|
|
@endpush
|