I have a pretty good structure for multiple CKEditor textareas, and when clicking a submit button I'm letting the user copy/paste the HTML from a JavaScript prompt
.
However, I want RTF instead of HTML. Do I need another JavaScript plugin, or can this be done with CKEditor?
Here's my code:
<!DOCTYPE html>
<html>
<head>
<title>CKEditor Test</title>
<style type="text/css">
.container {
margin-left: 30%;
}
</style>
</head>
<body>
<div class="container">
<form>
<textarea class="ckeditor" name="ckeditor1">
</textarea>
<input type="submit" value="submit" />
</form>
<form>
<textarea class="ckeditor" name="ckeditor2">
</textarea>
<input type="submit" value="submit" />
</form>
<form>
<textarea class="ckeditor" name="ckeditor3">
</textarea>
<input type="submit" value="submit" />
</form>
</div>
<script src="ckeditor_4.4.4_basic\ckeditor\ckeditor.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(".ckeditor").each(function() {
CKEDITOR.replace($(this).attr("name"));
CKEDITOR.config.width = 500;
});
$("form").submit(function(e) {
e.preventDefault();
var textarea = $(this).find("textarea:first");
var name = $(textarea).attr("name");
// forcing the textarea to update:
CKEDITOR.instances[name].updateElement();
var text = textarea.html();
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
});
</script>
</body>
</html>
...what it looks like:
...and some sample HTML output (from the text in the above screenshot):
<p>some top-level text</p><ul><li>a sub-item</li><li>another sub-item</li></ul>
Note: I'm using the basic version of CKEditor, and have disabled some buttons with this line in
config.js
:
config.removeButtons = 'Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript,Link,Unlink,About';