Tom V.
2007-Apr-11 08:44 UTC
InPlaceEditor: How to turn off selection of text when form is created?
I use in_place_editor with the :load_text_url option to load a file. When the form is created all text inside the textarea is selected by default. How do I turn this off? Rails'' in_place_editor method doesn''t seem to have an option to do this so I took a closer look at control.js and the "enterEditMode" method but I can''t figure out which call makes the selection. Also: special characters like < > & " get escaped when the textarea is created. As far as I know this is not a bug but a feature of html-textarea to prevent the use of HTML markup. Is there a way to show those special characters properly - meaning unescaped - inside the textarea? Thanks for your help! Tom. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Apr-11 11:27 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
On Apr 11, 2007, at 4:44 AM, Tom V. wrote:> Also: > special characters like < > & " get escaped when the textarea is > created. > As far as I know this is not a bug but a feature of html-textarea > to prevent the use of HTML markup. > > Is there a way to show those special characters properly - meaning > unescaped - > inside the textarea?You need to escape the code you send to the browser to display in any form field. It is the browser''s responsibility to display it to you on screen as the characters represented by the escape sequence. And when it is submitted back to your server by the form, it will also be in the form of the actual characters, not the escape sequence. 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Apr-11 11:28 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
On Apr 11, 2007, at 4:44 AM, Tom V. wrote:> How do I turn this off? > > Rails'' in_place_editor method doesn''t seem to have an option to do > this > so I took a closer look at control.js and the "enterEditMode" method > but I can''t figure out which call makes the selection.This has been a lively topic over the past few months, you might try the archives of the list. There were a number of impassioned pleas to the developers to add a high-level flag to switch this behavior off, but I haven''t heard of any outcome. 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Apr-11 17:34 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
I tasked myself with developing a patch for this a while back, but have been so busy, I haven''t got around to it yet. You will find our (heated) discussion on the topic in the archives and the proposed solution may be in there, if not, let me know and I can see what I have here to send you for now. Andrew On 4/11/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > > On Apr 11, 2007, at 4:44 AM, Tom V. wrote: > > > How do I turn this off? > > > > Rails'' in_place_editor method doesn''t seem to have an option to do > > this > > so I took a closer look at control.js and the "enterEditMode" method > > but I can''t figure out which call makes the selection. > > This has been a lively topic over the past few months, you might try > the archives of the list. There were a number of impassioned pleas to > the developers to add a high-level flag to switch this behavior off, > but I haven''t heard of any outcome. > > 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom V.
2007-Apr-19 16:06 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Hi Walter, sorry for the late reply. One way to do this is shown here: http://rubyonrails-spinoffs.googlegroups.com/web/in-place-editor-test.html On Apr 11, 1:28 pm, Walter Lee Davis <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Apr 11, 2007, at 4:44 AM, Tom V. wrote: > > > How do I turn this off? > > > Rails'' in_place_editor method doesn''t seem to have an option to do > > this > > so I took a closer look at control.js and the "enterEditMode" method > > but I can''t figure out which call makes the selection. > > This has been a lively topic over the past few months, you might try > the archives of the list. There were a number of impassioned pleas to > the developers to add a high-level flag to switch this behavior off, > but I haven''t heard of any outcome. > > 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom V.
2007-Apr-19 16:20 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Hi Walter, again sorry for the late reply! Could you please specify how to escape/unescape the contents of a form. This here doesn''t work: View (_file_contents): <div id="editme"><%= CG::unescapeHTML(file_contents) %></div> <%= in_place_editor ''editme'', :url => url_for({ :action => ''save_file'', :path => path }), :save_text => ''save'', :rows => 20, :cols => 5 %> Controller: def file_contents file_path = CGI::unescape(params[:path]) begin # ... render :partial => ''ide/partials/file_contents'', :locals => { :path => file_path, :file_contents => _get_file_contents(file_path) } end end def save_file file_path = URI::unescape(params[:path]) file_content = CGI::unescapeHTML(params[:value]) begin # ... render :partial => ''ide/partials/myPartial'', :locals => { :path => file_path, :file_contents => _get_file_contents(file_path) }, :layout => false end end Thanks, Tom.> You need to escape the code you send to the browser to display in any > form field. It is the browser''s responsibility to display it to you on > screen as the characters represented by the escape sequence. And when > it is submitted back to your server by the form, it will also be in the > form of the actual characters, not the escape sequence. > > 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Apr-19 17:07 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Hey there, IPE is undergoing massive overhaul. I''ll put an option for the final behavior: activate/focus/nothing. The current method uses activate, so you get focus+select. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Apr-19 17:32 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Where in the chain are you trying to escape/unescape the form contents? Are you describing a server-side or client-side process? Walter On Apr 19, 2007, at 12:20 PM, Tom V. wrote:> again sorry for the late reply! > Could you please specify how to escape/unescape the contents of a > form. > This here doesn''t work:--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom V.
2007-Apr-20 12:13 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Hi Walter, I use the live_tree plugin (http://www.epiphyte.ca/code/ live_tree.html) to generate a file system browser. When a user clicks a file it is displayed using this partial: <div id="editme"><%= file_contents %></div> <%= in_place_editor ''editme'', :url => url_for({ :action => ''save_file'', :path => path }), :save_text => ''save'', :rows => 20, :cols => 5 %> File contents are displayed properly meaning all special characters (especially "bigger than", "less than", "ampersand" and "double quotes") are displayed as unescaped characters. However, when the user clicks the "editme"-div the in_place_editor is activated and those special characters get escaped. I don''t want this to happen... I tried to make this work using a pure scriptaculous-inplaceeditor, something like: <script> //... var text = this.getText().unescapeHTML(); var textField = document.createElement("input"); textField.value = text; this.editField = textField; //... </script> however I have not succeeded so far... Thanks for your help, Tom. On Apr 19, 7:32 pm, Walter Lee Davis <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Where in the chain are you trying to escape/unescape the form contents? > Are you describing a server-side or client-side process? > > Walter > > On Apr 19, 2007, at 12:20 PM, Tom V. wrote: > > > again sorry for the late reply! > > Could you please specify how to escape/unescape the contents of a > > form. > > This here doesn''t work:--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Apr-22 00:29 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
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 after protaculous 8-) 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 On Apr 20, 2007, at 8:13 AM, Tom V. wrote:> > Hi Walter, > > I use the live_tree plugin (http://www.epiphyte.ca/code/ > live_tree.html) > to generate a file system browser. > When a user clicks a file it is displayed using this partial: > > <div id="editme"><%= file_contents %></div> > <%= in_place_editor ''editme'', > :url => url_for({ :action => ''save_file'', :path => path }), > :save_text => ''save'', > :rows => 20, > :cols => 5 > %> > > File contents are displayed properly meaning all special characters > (especially "bigger than", "less than", "ampersand" and "double > quotes") > are displayed as unescaped characters. > However, when the user clicks the "editme"-div > the in_place_editor is activated and those special characters get > escaped. > I don''t want this to happen... > > I tried to make this work using a pure scriptaculous-inplaceeditor, > something like: > > <script> > //... > var text = this.getText().unescapeHTML(); > var textField = document.createElement("input"); > textField.value = text; > this.editField = textField; > //... > </script> > > however I have not succeeded so far... > Thanks for your help, > Tom. > > > On Apr 19, 7:32 pm, Walter Lee Davis <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> Where in the chain are you trying to escape/unescape the form >> contents? >> Are you describing a server-side or client-side process? >> >> Walter >> >> On Apr 19, 2007, at 12:20 PM, Tom V. wrote: >> >>> again sorry for the late reply! >>> Could you please specify how to escape/unescape the contents of a >>> form. >>> This here doesn''t work: > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom V.
2007-Apr-23 12:46 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
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 <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Apr-23 13:14 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
You may have to change where exactly your partial goes, and where the editor goes. The issue, as I see it, is that your partial is emitting the same id it is supposed to be replacing the *contents* of. Try doing it this way, and see if that helps. <pre id="xyz" onclick="activateEditor()"> (partial creates this bit) some gnarly text here (/partial) </pre> Walter On Apr 23, 2007, at 8:46 AM, Tom V. wrote:> > 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 <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom V.
2007-Apr-23 17:03 UTC
Re: InPlaceEditor: How to turn off selection of text when form is created?
Hi Walter, again, you were right! I just put the pre-tag into my layout: <pre id="file_contents" onclick="activateEditor()"> <%= yield :main %> </pre> And the JS-stuff for the InPlaceEditor, too. Thanks so much for your help! Tom. (now using a grinding machine to get those two dents of my hellish head...) On Apr 23, 3:14 pm, Walter Lee Davis <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> You may have to change where exactly your partial goes, and where the > editor goes. The issue, as I see it, is that your partial is emitting > the same id it is supposed to be replacing the *contents* of. > > Try doing it this way, and see if that helps. > > <pre id="xyz" onclick="activateEditor()"> > (partial creates this bit) some gnarly text here (/partial) > </pre> > > Walter > > On Apr 23, 2007, at 8:46 AM, Tom V. wrote: > > > > > 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 <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---