Thanx to Pekka, I reached a solution through:
$('#stylesheeetSelector').change(function() { $.post('/getStylesheet', {id: $(this).val()}, function(data) { for(i in CKEDITOR.instances) { var linkElement = $(CKEDITOR.instances[i].document.$).find('link'); if (data.editorStylesheet > 0) { if (linkElement.length == 0) { $(CKEDITOR.instances[i].document.$).find('head').append('<link rel="stylesheet" type="text/css" href="'+ data.editorStylesheet +'">'); } else { linkElement.attr('href', data.editorStylesheet) } } else if (linkElement.length > 0) { linkElement.remove(); } } }); });
It works by selecting a JSON object filled with the URL of the stylesheet (among others), and sets (or deletes, if not present) the selected stylesheet ...
Clean and simple!
source share