зеркало из
https://github.com/rs-pro/activeadmin-quill_editor.git
synced 2026-08-28 15:36:17 +03:00
Making sure quill editor updates with has_many
What:
* adding an event listerner so when people add a 'has_many' relationship
the quill editor is initialized correctly on any fields;
Why:
* If you have a nested has_many attributes in active admin, the form
is not created until you click the 'Add New ObjectName' button. This
triggers a jQuery event called 'has_many_add:after' which you can use to
trigger the re init of the quill editor.
* 9a33a081c9/app/assets/javascripts/active_admin/lib/has_many.es6 (L52)
Этот коммит содержится в:
@@ -1,4 +1,12 @@
|
||||
window.onload = function() {
|
||||
window.onload = function () {
|
||||
initQuillEditors();
|
||||
}
|
||||
|
||||
$(document).on('has_many_add:after', function() {
|
||||
initQuillEditors();
|
||||
});
|
||||
|
||||
var initQuillEditors = function() {
|
||||
var editors = document.querySelectorAll( '.quill-editor' );
|
||||
var default_options = {
|
||||
modules: {
|
||||
@@ -19,9 +27,11 @@ window.onload = function() {
|
||||
|
||||
for( var i = 0; i < editors.length; i++ ) {
|
||||
var content = editors[i].querySelector( '.quill-editor-content' );
|
||||
if( content ) {
|
||||
var isActive = editors[i].classList.contains('quill-editor--active');
|
||||
if( content && !isActive) {
|
||||
var options = editors[i].getAttribute( 'data-options' ) ? JSON.parse( editors[i].getAttribute( 'data-options' ) ) : default_options;
|
||||
editors[i]['_quill-editor'] = new Quill( content, options );
|
||||
editors[i].classList += ' quill-editor--active';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user