Skip to content

Commit

Permalink
on entry edit form, use plain textarea when markup is Markdown or Tex…
Browse files Browse the repository at this point in the history
…tile
  • Loading branch information
yayugu committed Nov 1, 2011
1 parent d491c76 commit 00eaf3c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
3 changes: 2 additions & 1 deletion public/admin/entries/form.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
47 changes: 41 additions & 6 deletions public/admin/js/editor.js
Original file line number Diff line number Diff line change
@@ -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.