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

Make sure CKEDITOR works in content box #1457

Merged
merged 2 commits into from
Oct 15, 2020
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
11 changes: 8 additions & 3 deletions core/assets/js/contentbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(function( $ ) {

var settings = {},
objects = {},
methods = {
init : function ( options ) {
// Create some defaults, extending them with any options that were provided
Expand All @@ -24,7 +25,7 @@
'</div>',
'</div>'
].join('\n'),
onAfterLoad : function ( content ) {}
onAfterLoad : function ( content, objects ) {}
}, options);

// Add close on escape
Expand Down Expand Up @@ -61,7 +62,7 @@
{
callback();
}
},
},
show : function () {
$('.content-box-header span').html(settings.title);
settings.element.find('.loading-bar').show();
Expand All @@ -81,8 +82,12 @@
}
});

// Save the reference to the iframe's content window to expose it to the code creating the content box
var iFrameWindow = iFrame[0].contentWindow? iFrame[0].contentWindow : iFrame[0].contentDocument.defaultView;
objects.iframe = iFrameWindow;

settings.element.find('.loading-bar').hide();
settings.onAfterLoad( content );
settings.onAfterLoad( content, objects );
});
});
},
Expand Down
30 changes: 24 additions & 6 deletions core/plugins/courses/outline/assets/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,24 @@ HUB.CoursesOutline = {
$.contentBox({
src : src,
title : 'Edit ' + assetName.charAt(0).toUpperCase() + assetName.substr(1),
onAfterLoad : function( content ) {
onAfterLoad : function( content, objects ) {
content.find('.cancel').click(function () {
// Close the content box
$.contentBox('close');
});

content.find('.edit-form').submit(function ( e ) {
if (typeof CKEDITOR !== 'undefined') {
$(this).find('#content').html($(this).find('.cke_wysiwyg_frame').contents().find('body').html());
// Run the CKEditor
var ckEditor = objects.iframe.CKEDITOR;
if(ckEditor) {
for(var instanceName in ckEditor.instances) {
ckEditor.instances[instanceName].updateElement();
}
}
else if (typeof CKEDITOR !== 'undefined') {
for(var instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].updateElement();
}
}

// Create ajax call to change info in the database
Expand Down Expand Up @@ -1239,7 +1248,7 @@ HUB.CoursesOutline = {
$.contentBox({
src : src,
title : 'Create a wiki page',
onAfterLoad : function( content ) {
onAfterLoad : function( content, objects ) {
var t = $(this);
content.find('.cancel').click(function(e) {
e.preventDefault();
Expand All @@ -1258,8 +1267,17 @@ HUB.CoursesOutline = {
});

content.find('.edit-form').submit(function ( e ) {
if (typeof CKEDITOR !== 'undefined') {
$(this).find('#content').html($(this).find('.cke_wysiwyg_frame').contents().find('body').html());
// Run the CKEditor
var ckEditor = objects.iframe.CKEDITOR;
if(ckEditor) {
for(var instanceName in ckEditor.instances) {
ckEditor.instances[instanceName].updateElement();
}
}
else if (typeof CKEDITOR !== 'undefined') {
for(var instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].updateElement();
}
}

// Create ajax call to change info in the database
Expand Down