Skip to content
Browse files

on entry edit form, use plain textarea when markup is Markdown or Tex…

…tile
  • Loading branch information...
1 parent d491c76 commit 00eaf3c6305f59a7614b70e255f5034272fec58a @yayugu yayugu committed Nov 2, 2011
Showing with 43 additions and 7 deletions.
  1. +2 −1 public/admin/entries/form.haml
  2. +41 −6 public/admin/js/editor.js
View
3 public/admin/entries/form.haml
@@ -15,7 +15,8 @@
.field
%label(for="#{@name}_body")= t("#{@name}.body")
%br/
- %textarea(id="#{@name}_body" class="editor" name="#{@name}[body]" rows="10" cols="50")= h @entry.raw_body
+ %div#editor
+ %textarea(id="#{@name}_body" class="editor" name="#{@name}[body]" rows="10" cols="50")= h @entry.raw_body
.field
%label(for="#{@name}_slug")= t("#{@name}.slug")
%br/
View
47 public/admin/js/editor.js
@@ -1,7 +1,42 @@
$(function() {
- $('textarea.editor').cleditor({
- width: 550,
- height: 550,
- controls: 'bold italic underline strikethrough subscript superscript font size style | color highlight removeformat bullets numbering | outdent indent | alignleft center alignright justify | rule image link unlink | pastetext source'
- })
-})
+ var cleditor;
+ var textarea = $('textarea.editor').clone();
+ var plainTextareaMode;
+
+ var switchTextareaAndCleditor = (function() {
+ var name = $('select[name$="[markup]"] option:selected').val();
+ var html;
+ if (name == '') {
+ // enable cleditor
+ if (plainTextareaMode) {
+ textarea = $('textarea.editor').clone();
+ translateToCleditor($('textarea.editor'));
+ plainTextareaMode = false;
+ }
+ } else {
+ // enable textarea
+ if (!plainTextareaMode) {
+ html = cleditor[0].doc.body.innerHTML;
+ textarea[0].innerHTML = html;
+ $('.cleditorMain').remove();
+ $('#editor').prepend(textarea);
+ plainTextareaMode = true;
+ }
+ }
+ });
+
+ var translateToCleditor = (function(jQueryObj) {
+ cleditor = jQueryObj.cleditor({
+ width: 550,
+ height: 550,
+ controls: 'bold italic underline strikethrough subscript superscript font size style | color highlight removeformat bullets numbering | outdent indent | alignleft center alignright justify | rule image link unlink | pastetext source'
+ });
+ });
+
+ $('select[name$="[markup]"]').change(switchTextareaAndCleditor);
+
+ translateToCleditor($('textarea.editor'));
+ plainTextareaMode = false;
+
+ switchTextareaAndCleditor();
+});

0 comments on commit 00eaf3c

Please sign in to comment.
Something went wrong with that request. Please try again.