-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
on entry edit form, use plain textarea when markup is Markdown or Tex…
…tile
- Loading branch information
Showing
2 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |