CKEditor with ASP.NET MVC Bundling

Using CKEditor in ASP.NET MVC 4 still has problems. The system will load required files when using ckeditor, but because of the name ckeditor.js disappeared, the path of required files become false.

For that reason, in bundling, CKEditor must have its own bundle with name like "~/Scripts/ckeditor" if place in Scripts directory, or like "~/Scripts/wcw/ckeditor if place in Scripts/wcw directory. Then, the ckeditor.js must be changed little in the function for basePath, so it will read the ckeditor instead of ckeditor.js.

bundleConfig.js
[code language=”csharp” highlight=”1″]
bundles.Add(new ScriptBundle("~/Scripts/wcw/ckeditor").Include(
"~/Scripts/wcw/ckeditor.js"
));
[/code]

ckeditor.js
[code language=”javascript” highlight=”6″]
basePath:
function(){
var a=window.CKEDITOR_BASEPATH||"";
if(!a)
for(var b=document.getElementsByTagName("script"),d=0;d<b.length;d++){
var c=b[d].src.match(/(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?(?:\.js)?(?:\?.*)?$/i);
if(c){a=c[1];break}
}
-1==a.indexOf(":/")&&(a=0===a.indexOf("/")?location.href.match(/^.*?:\/\/[^\/]*/)[0]+a:location.href.match(/^[^\?]*\/(?:)/)[0]+a);
if(!a)
throw’The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.’;
return a
}()
[/code]

Septu Jamasoka has written 23 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>