Yay! Finally did it!
At last I used the CKEditor and it worked! Check it out:
- download the editor at http://ckeditor.com/download
- put it into the
assets
folder of your project - add
config.filebrowserUploadUrl = '/uploader';
to yourckeditor/config.js
file - add an action for uploads in your controller :
upload_file : function(req, res) {
var fs = require('fs'); console.log(req.files); fs.readFile(req.files.upload.path, function (err, data) { var newPath = 'assets/files/' + req.files.upload.name; fs.writeFile(newPath, data, function (err) { if (err) res.view({err: err}); html = ""; html += "<script type='text/javascript'>"; html += " var funcNum = " + req.query.CKEditorFuncNum + ";"; html += " var url = \"/files/" + req.files.upload.name + "\";"; html += " var message = \"Uploaded file successfully\";"; html += ""; html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);"; html += "</script>"; res.send(html); }); });
}
- add a route for this action:
'/uploader' : { controller : 'post', action : 'upload_file' }
- make a folder (
assets/files
for me) for uploads - finally, change the form putting ckeditor in:
block body script(type="text/javascript", src="/ckeditor/ckeditor.js") form(action='/posts/create', method="post", enctype="multipart/form-data") p Title input(type='text', name='title') p Body textarea(name='body', id='ck') script. CKEDITOR.replace( 'ck' ); hr input(type='submit', value='Сохранить')
(in jade here)
That's all! Enjoy WYSIWYG :)