Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to integrate TinyMCE and CKEditor in Meteor JS?

I am trying to use CKEditor or TinyMCE editor in my project. So I put TinyMCE folder in meteor public folder, also put

<head>
<script type="text/javascript" src="<your installation path>/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
    tinymce.init({
        selector: "textarea"
    });
</script>

in template head tag. However receiving following error. Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/%3Cyour%20installation%20path%3E/tinymce/tinymce.min.js". (index):97 Uncaught SyntaxError: Unexpected token < tinymce.min.js:1 Uncaught ReferenceError: tinymce is not defined

How do I fix this problem? It is same to CKEditor. Is there any other rich editor ,which I can use in Meteor JS?

like image 681
zevsuld Avatar asked Sep 24 '14 07:09

zevsuld


2 Answers

First, you need to put everything from the CKEDITOR build download in the public folder. CKEDITOR comes with all sorts of stuff and references everything based on relative directories.

Your public folder should have a directory named ckeditor it should contain contain the following files and folders:

 adapters
 lang
 plugins
 skins
 ckeditor.js
 config.js
 contents.css
 styles.js

In your primary layout file reference CKEDITOR like so:

 <head>
   <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
   <script type="text/javascript" src="/ckeditor/adapters/jquery.js"></script>
 </head>

In your template:

 <template name="yourTemplate">
   <textarea id="content" name="content"></textarea>
 </template>

Finally, in the rendered function of your template:

 Template.yourTemplate.rendered = function() {
   $('#content').ckeditor();
 };

Normally, you would say this.$('#content').ckeditor() but that doesn't work because CKEDITOR is in your public folder. As a result, you need to the global reference to the #content element.

like image 156
Brandon Avatar answered Sep 18 '22 00:09

Brandon


Instead of /public folder, put your files in /client/compatibility. Then initialize it in the template you want to use it.

Template.editor.rendered = function() {
  tinymce.init({
    selector: 'textarea'
  });
};
like image 38
Hubert OG Avatar answered Sep 22 '22 00:09

Hubert OG