Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor baseHref not working and editor not working after minification/bundeling

I am developing a Web-Application using ASP.NET MVC 4 and I am trying to use CKEditor for some content editing.
In debug everything works fine as long as no bundeling or minification is happening, but as soon as this does CKEditor generates wrong URLs even if I have set baseHref:

CKEDITOR.replace('ckeditor',
{
    autoUpdateElement: true,
    baseHref: '@Url.Content("~/Scripts/ckeditor/")',
    filebrowserImageUploadUrl: '/Uploads/Upload'
});

In debug the following is included:

<script src="/Scripts/ckeditor/ckeditor.js"></script>

And after bundeling/minifaction it is just:

<script src="/bundles/ckeditor?v=dLE-_JqB4vxXJ9idGep_8yUL8KfOwGhfYoEZAeIudoE1"></script>

and it trys to load the following JS files:

http://DOMAIN.net/CONTROLLER/ACTION/config.js?t=D26D

Which is wrong as it should be:

http://DOMAIN.net/Scripts/ckeditor/config.js?t=D26D

Does anyone know what I am doing wrong or how to fix this?
Alternatively I would also be fine with a possibility to disable bundeling/minification for that one bundle to avoid that problem.

like image 567
Christoph Fink Avatar asked Dec 08 '22 17:12

Christoph Fink


2 Answers

Try to add the following content before include the ckeditor's js file:

<script type="text/javascript">
    var CKEDITOR_BASEPATH = '@Url.Content("~/Scripts/ckeditor/")';
</script>

More information: http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Specifying_the_Editor_Path

And it will also work with ckeditor 4.x.

like image 122
crackym Avatar answered May 10 '23 20:05

crackym


I had similar problem but found this to work. Include it in the cshtml layout file.

<script>
  CKEDITOR.basePath = "@Url.Content("~/lib/ckeditor/")";
</script>

or with JQuery

$(document).ready(function() { 
  CKEDITOR.basePath = "@Url.Content("~/lib/ckeditor/")"; 
});
like image 36
bluee Avatar answered May 10 '23 20:05

bluee