Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AdminBundle] Fix rich-editor issues for pageparts with subentities #364

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Kunstmaan/AdminBundle/Resources/ui/js/_nested-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ kunstmaanbundles.nestedForm = (function(window, undefined) {
setupForm($form);
$form.data('initialized', true);
}

});
};

Expand Down Expand Up @@ -154,8 +153,7 @@ kunstmaanbundles.nestedForm = (function(window, undefined) {
// Add "Delete" button
addDelBtn($newItem, $form);

// Reinit rich Editors
kunstmaanbundles.richEditor.destroyRichEditors();
// Init new rich editors
kunstmaanbundles.richEditor.init();

// Init Ajax Modals
Expand Down
12 changes: 11 additions & 1 deletion src/Kunstmaan/AdminBundle/Resources/ui/js/_page-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ kunstmaanbundles.pageEditor = (function(window, undefined) {
var $el = $(evt.item),
elScope = $el.data('scope');

// Destroy rich editors inside dragged element
$el.find('.js-rich-editor').each(function() {
kunstmaanbundles.richEditor.destroySpecificRichEditor($(this));
});

// Add active class
$body.addClass('sortable-active');

Expand All @@ -150,7 +155,7 @@ kunstmaanbundles.pageEditor = (function(window, undefined) {
onEnd: function(evt) {
var $el = $(evt.item),
$PPcontainer = $el.parents('.js-pp-container'),
$contextUpdateField = $el.find('.pagepartadmin_field_updatecontextname')
$contextUpdateField = $el.find('.pagepartadmin_field_updatecontextname'),
currentContext = $PPcontainer.data('context');

// Remove active class
Expand All @@ -166,6 +171,11 @@ kunstmaanbundles.pageEditor = (function(window, undefined) {
$contextUpdateField.each(function() {
$(this).attr('name', currentContext + $(this).data('suffix'));
});

// Enable rich editors inside dragged element
$el.find('.js-rich-editor').each(function() {
kunstmaanbundles.richEditor.enableRichEditor($(this));
});
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ kunstmaanbundles.pagepartEditor = (function(window, undefined) {
// Enable leave-page modal
kunstmaanbundles.checkIfEdited.edited();

// Reinit rich Editors
kunstmaanbundles.richEditor.destroyRichEditors();
// Enable new Rich Editors
kunstmaanbundles.richEditor.init();

// reinit colorpicker
Expand Down
37 changes: 29 additions & 8 deletions src/Kunstmaan/AdminBundle/Resources/ui/js/_rich-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ var kunstmaanbundles = kunstmaanbundles || {};
kunstmaanbundles.richEditor = (function(window, undefined) {

var init,
enableRichEditors;
enableRichEditor, destroyAllRichEditors, destroySpecificRichEditor;


// First Init
init = function() {
$('.js-rich-editor').each(function() {
enableRichEditors($(this));
if(!$(this).hasClass('js-rich-editor--enabled')) {
enableRichEditor($(this));
}
});
};


// Enable
enableRichEditors = function($el) {
enableRichEditor = function($el) {
var $body = $('body'),
fileBrowseUrl = $body.data('file-browse-url'),
imageBrowseUrl = $body.data('image-browse-url'),
Expand Down Expand Up @@ -158,6 +160,8 @@ kunstmaanbundles.richEditor = (function(window, undefined) {
toolbar: elToolbar
});

$el.addClass('js-rich-editor--enabled');

// Behat tests
// Add id on iframe so that behat tests can interact
var checkExist = setInterval(function() {
Expand All @@ -174,20 +178,37 @@ kunstmaanbundles.richEditor = (function(window, undefined) {
};


// Destroy
destroyRichEditors = function() {
// Destroy All
destroyAllRichEditors = function() {
for(instance in CKEDITOR.instances) {
var $el = $('#' + CKEDITOR.instances[instance].name);

if($('#' + CKEDITOR.instances[instance].name).hasClass('js-rich-editor')) {
CKEDITOR.instances[instance].destroy();
if($el.hasClass('js-rich-editor')) {
$el.removeClass('js-rich-editor--enabled');

CKEDITOR.instances[instance].destroy(true);
};
}
};


// Destroy Specific
destroySpecificRichEditor = function($el) {
var elId = $el.attr('id'),
editor = CKEDITOR.instances[elId];

if(editor) {
editor.destroy(true);
}
};


// Returns
return {
init: init,
destroyRichEditors: destroyRichEditors
enableRichEditor: enableRichEditor,
destroyAllRichEditors: destroyAllRichEditors,
destroySpecificRichEditor: destroySpecificRichEditor
};

}(window));