Hi Walter,

> I am not following your code all that clearly this morning.
I don't blame you, its a bunch of crap...

> Are you assigning the IDs in JavaScript or in Ruby?
Actually I did it in JavaScript.

But I made a turn and now use inline rendering...
I guess this makes me quite an MVC-violator
but at least it solves my first problem
(no more whitespaces at the beginning, no tags inside textarea etc.).

The action for grabbing file paths and getting file output ready
now does not use a partial anymore but uses this line (simplified):

(1) using "onclick=" + JavaScript function:

render :inline => "<%= '<div id=\"'+timestamp+'\" class=\"ruby\"
                       onclick=\"createEditor()\">
                       '+file_contents+'</div>'%>",
                       :locals => {:timestamp => ts,
                                   :file_contents =>
                            _get_file_contents(file_path,convert)}

So now I get dynamic IDs for each file/<div>.
However, problem no. 2 from last time still exists:

- Clicking once on the html-stuff created by above code
only adds 'title' + 'background-color' to the div.
- Clicking once again makes the textarea appear.
- Closing it and clicking one more time creates two textareas and so
on.

When I omit JavaScript and use a plain old Rails in_place_editor,
this phenomenon does not appear:

(2) using JavaScriptMacrosHelper::in_place_editor:

render :inline => "<%= '<div id=\"'+timestamp+'\" class=\"ruby\">
                       '+fcontents+'</div>'
                        + in_place_editor(timestamp,
                        :url => url_for({:action => \"save_file\"}),
                        :load_text_url => url_for({:action => ...

However I then miss the ability to assign user specific values
for ":rows" and :"cols" (using screen resolution etc.)
and of course the possibilty to prevent this "all text selected" thing
inside the textarea.
This is quite important so I would hate to miss it...

The JavaScript function for creating the IPE looks like this:

function createEditor(preId,file_path) {
  var size = paneSplitter.getSizeOfPaneInPixels('center');
  var width = Math.round(size.width * 0.12);
  var height = Math.round(size.height * 0.053);
  var editor = new Ajax.InPlaceEditor(preId, file_path);
  var bak = editor.createEditField;
  editor.createEditField = function() {
    bak.apply(this, arguments);
    Event.observe(this.editField, 'focus', function(ev) {
      if (this.setSelectionRange) {
        setTimeout(function () {
          this.setSelectionRange(0, 0);
        }.bind(this), 10);
      } else {
        if (this.createTextRange) {
          var range = this.createTextRange();
          range.collapse(true);
          range.moveEnd('character', 0);
          range.moveStart('character', 0);
          range.select();
        }
      }
    }.bindAsEventListener(this.editField)
    );
  };
}

I deeply hope I explained my struggling well enough
so you might have a clue...

Thanks in advance,
Tom.

>
> Advice, in no particular order:
>
> Have a read through the example related to getting a Textile/Markdown
> formatted DIV to work correctly with the IPE -- that's where I went to
> look for clarity. And once I had that part working, the rest just
> worked.
>
> Dynamically creating an editor as needed is just an implementation
> detail, it should not be central toyourdesign. See if you can get it
> toallwork long-hand, with a separate JS block after each thing you
> want to be able to edit creating an editor you may or may not need. If
> you are doing this with a lot of items on a page, it may make the whole
> thing unstable or suck memory like a pig, but for testing purposes it
> should get you started.
>
> Once you have everything editing the way you want it to, then add the
> layer of "unobtrusive" IPE using a page listener to start a loop that
> adds a per-item listener. Then deleteyourseparate JS blocks and see
> if itallstill works.
>
> There are some Prototype functions that clean out extraneous white
> space, you might want to have a look at those inyourtravels. But you
> might also want to fill the edited div andyourdatabase back in using
> a trim()med version of the IPE output to the same effect.
>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to