I'm working on subverting FCKeditor to serve as a text editor, a sort of enhanced textarea with nice features such as Print, Find and Undo/Redo.
#593 Start the editor in Source mode includes a patch which I applied. This appears to do what I want.
However, I do have a problem with this which I hope is a simple newbie issue. Following html/sample02.html, I set up a page to ReplaceTextarea in a view in my Rails app (no, I'm not using a Rails plugin for this -- it would be overkill in my case). The code is as follows:
window.onload = function() { if (fileExists) { var oFCKeditor = new FCKeditor('file') ; oFCKeditor.BasePath = '/javascripts/fckeditor/' ; oFCKeditor.Config["CustomConfigurationsPath"] = oFCKeditor.BasePath+"dyconfig.js"; oFCKeditor.ToolbarSet = 'Text' ; oFCKeditor.ReplaceTextarea() ; } }
<form action="/file/save/<%= params[:id] %>" method="post"> <div> <textarea name="file" rows="30" cols="80" style="width: 100%; height: 400px"><%= @file %></textarea> </div> <br /> </form>
When I press Save, what is submitted is the original contents of the textarea, not the new contents. This resembles viewtopic.php?f=6&t=10299 but I don't understand his solution -- it involves Ajax which I don't use here. My assumption is that pressing Save does an ordinary form submit, and that it ought to submit the changed value. Is this assumption incorrect?
I must have done something foolish here and someone should be able to set me straight fairly quickly. Please assist.
To make FCKeditor behave as a text editor, I also remove any HTML-related buttons from the buttonbar so that it is always in Source mode and can't be switched out. Is this a reasonable approach? Are there any other "gotchas" I haven't considered? I do see that there is an issue with Replace not working in Source mode (someone else filed a ticket on this already, but I don't have the URL at my fingertips) but we could live without that for now.
Thanks,
Ben
Re: Using FCKeditor as a text editor
FCKeditor in source mode is just a textarea, and I don't see any of the buttons that you mention enabled in source mode. Only select All, Save, New, Preview and fullscreen
Re: Using FCKeditor as a text editor
Ah. I use a custom toolbar. However, I see that many buttons are greyed out in this mode: Print, cut, paste, undo, redo to mention a few. While Find and Replace are not greyed out, they don't seem to work. See:
http://dev.fckeditor.net/ticket/158
Although finding many features we want are missing in Source mode is a discouraging discovery, I'm not ready to give up on it yet, provided the developers agree future releases might support them. The fact that #158 remains open after all of this time indicates to me they're open to the idea. If just this bug were resolved, it would be worth it for us to stick with FCKeditor, assuming my problem with not being able to save the edited content can be solved, too.
My initial attempt at implementing text mode was to just use normal mode but disable HTML buttons in the toolbar and then wrap the original text with <pre>..</pre>. But this is too easy to break if the user inserts material above or below these tags or deletes the tags all together (e.g. select-all and then replace the entire contents with new text).
See also: http://dev.fckeditor.net/ticket/849 which is sort of what we had in mind.
In particular, although Fred initially thought that people should just use a textarea instead, he later reversed that position, re-opening the bug and leaving it on the books. My own issue is similar to pgoiffon's. While in this particular case I am using the editor to edit text (some control files belonging to our application) there are other cases where we will be using it to edit HTML. We would like the consistency of using FCKeditor for all cases, in addition to the desirable extra features mentioned in my original post.
Ben