Hi Walter,
thanks for your code, it works great!
However, yet another problem has occurred.
Maybe you could solve this,too...
In order to format file contents properly I added a pre-Tag to my
partial:
<pre class="sourcecode" id="editme" onclick="activateEditor();"><%= h
file_contents %></pre>
<script>
//...
var editor = new Ajax.InPlaceEditor('editme', '<%=
escape_javascript(url_for({ :action => "save_file", :path => path}))
%>')
//...
</script>
Before I click the rendered file contents, the respective HTML (in
Firebug) looks sort of like this:
<div id="file.rb" class="DHTMLSuite_paneContentInner" style="display:
block;">
<pre id="editme" class="sourcecode" onclick="activateEditor();">
file contents with lots of special chars...
</pre>
<script type="text/javascript">
// code for the InPlaceEditor
</script>
</div>
After clicking, a form-tag is added: <form id="editme-inplaceeditor"
class="inplaceeditor-form">
When I click "save/ok", the pre-tag gets doubled:
<div id="two_controller.rb" class="DHTMLSuite_paneContentInner"
style="display: block;">
<pre id="editme" class="sourcecode" onclick="activateEditor();"
title="Click to edit" style="...">
<pre id="editme" class="sourcecode"
onclick="activateEditor();">
file contents with lots of special chars...
</pre>
</pre>
<script type="text/javascript">
// code for the InPlaceEditor
</script>
</div>
When I click on the file contents again, the whole text disappears and
Firebug yells at me:
string has no properties
convertHTMLLineBreaks(null)controls.js (line 591)
createEditField()controls.js (line 622)
createForm()controls.js (line 562)
enterEditMode(click clientX=0, clientY=0)controls.js (line 547)
bindAsEventListener(click clientX=0, clientY=0)
control.js:
convertHTMLLineBreaks: function(string) {
return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi,
"\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
},
I don't know whether these two errors are related to eachother.
I also have no idea why the "string" disappeared...
Using InPlaceEditor without your extension, this error does not
appear.
But then I am missing your great work ;-)
The action for saving InPlaceEditor-contents looks like this:
def save_file
file_path = params[:path]
file_content = params[:value]
begin
# ...
edited_file = File.open(file, "w")
edited_file << file_content
edited_file.close
render :partial => 'ide/partials/file_contents', :locals =>
{ :path => file_path, :file_contents =>
_get_file_contents(file_path) }, :layout => false
rescue
# ...
end
end
The file is saved to the file system without any errors.
I tried to solve this over the weekend but failed again.
And those two dents I got are now medicated the hellboy-way ;-)
Cheers,
Tom.
On Apr 22, 2:29 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> Object.extend(Ajax.InPlaceEditor.prototype, {
> onLoadedExternalText: function(transport) {
> Element.removeClasName(this.form, this.options.loadingClasName);
> this.editField.disabled = false;
> this.editField.value = transport.responseText;
> Field.scrolFreActivate(this.editField);
> }});
>
> Object.extend(Ajax.InPlaceEditor.prototype, {
> getText: function() {
> return this.element.childNodes[0] ?
> this.element.childNodes[0].nodeValue : '';
> }
>
> });
>
> Add these two extensions afterprotaculous8-) loads. The first one
> removes the stripTags feature from the editor. The second one replaces
> the innerHTML with nodeValue. Those two together are what I did to get
> < and > and so forth to show up properly.
>
> It is very important if you do this not to put htmlspecialchars() into
> the mix. Something in prototype already does this, and it made quite a
> dent in my forehead until I realized that. Double-escaped entities --
> very nasty.
>
> Walter
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---