Hey there, I have a trick that I use in jQuery quite a lot, and I just can''t quite figure out how to do it with prototype/scriptaculous.. Basically for elements i am going to dynamically insert I have a hidden div with all the fields and such inside it and I just did something like $(''.newthingy).clone(), can''t remember the exact jQuery syntax any more. I assume there''s something similar here, can someone fill me in? Cheers, Jason --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It''s not there by default, but a bit of googling turned up this, which works pretty much how you would expect: http://www.mail-archive.com/prototype-core-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org/ msg01671.html Add the script after Prototype loads, but before you need to use the trick. Then just do the following: $(''targetDiv'').insert({after: $(''templateDiv'').clone()}); or $(''container'').appendChild($(''templateDiv'').clone()); Walter On Feb 20, 2008, at 6:57 PM, Backov wrote:> > Hey there, > > I have a trick that I use in jQuery quite a lot, and I just can''t > quite figure out how to do it with prototype/scriptaculous.. > > Basically for elements i am going to dynamically insert I have a > hidden div with all the fields and such inside it and I just did > something like $(''.newthingy).clone(), can''t remember the exact jQuery > syntax any more. > > I assume there''s something similar here, can someone fill me in? > > Cheers, > Jason > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I found one bug in trying this out. It sets all copies to the same ID, which then doesn''t play well later. I modified the clone function as follows to fix that: clone: function(element) { var clone = new Element(element.tagName); $A(element.attributes).each(function(attribute) { if ( attribute.name != ''style'' && attribute.name != ''id'' ) clone [attribute.name] attribute.value; }); clone.setStyle( element.getStyles() ); clone.identify(); clone.update(element.innerHTML); return clone; } } ); Walter On Feb 20, 2008, at 8:33 PM, Walter Lee Davis wrote:> > It''s not there by default, but a bit of googling turned up this, > which works pretty much how you would expect: > > http://www.mail-archive.com/prototype-core-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org/ > msg01671.html > > Add the script after Prototype loads, but before you need to use the > trick. Then just do the following: > > $(''targetDiv'').insert({after: $(''templateDiv'').clone()}); > > or > > $(''container'').appendChild($(''templateDiv'').clone()); > > Walter > > > On Feb 20, 2008, at 6:57 PM, Backov wrote: > >> >> Hey there, >> >> I have a trick that I use in jQuery quite a lot, and I just can''t >> quite figure out how to do it with prototype/scriptaculous.. >> >> Basically for elements i am going to dynamically insert I have a >> hidden div with all the fields and such inside it and I just did >> something like $(''.newthingy).clone(), can''t remember the exact >> jQuery >> syntax any more. >> >> I assume there''s something similar here, can someone fill me in? >> >> Cheers, >> Jason >>> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very nice script but looks like it''s doing a little too much : ) Native element.cloneNode from DOM2 [1] already "copies all attributes and their values" so it looks like we can safely skip #getStyles and #clone methods. Something like this perhaps: Element.addMethods({ toHTML: function(element) { element = $(element); try { var xmlSerializer = new XMLSerializer(); return element.nodeType == 4 ? element.nodeValue : xmlSerializer.serializeToString(element); } catch(e) { return element.xml || element.outerHTML || element.cloneNode(true).wrap().innerHTML; } } }); [1] http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-3A0ED0A4 - kangax On Feb 20, 8:44 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> I found one bug in trying this out. It sets all copies to the same > ID, which then doesn''t play well later. I modified the clone function > as follows to fix that: > > clone: function(element) { > var clone = new Element(element.tagName); > $A(element.attributes).each(function(attribute) { if > ( attribute.name != ''style'' && attribute.name != ''id'' ) clone > [attribute.name] > attribute.value; }); > > clone.setStyle( element.getStyles() ); > clone.identify(); > clone.update(element.innerHTML); > > return clone; > } } ); > > Walter > > On Feb 20, 2008, at 8:33 PM, Walter Lee Davis wrote: > > > > > It''s not there by default, but a bit of googling turned up this, > > which works pretty much how you would expect: > > >http://www.mail-archive.com/prototype-core-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org/ > > msg01671.html > > > Add the script after Prototype loads, but before you need to use the > > trick. Then just do the following: > > > $(''targetDiv'').insert({after: $(''templateDiv'').clone()}); > > > or > > > $(''container'').appendChild($(''templateDiv'').clone()); > > > Walter > > > On Feb 20, 2008, at 6:57 PM, Backov wrote: > > >> Hey there, > > >> I have a trick that I use in jQuery quite a lot, and I just can''t > >> quite figure out how to do it with prototype/scriptaculous.. > > >> Basically for elements i am going to dynamically insert I have a > >> hidden div with all the fields and such inside it and I just did > >> something like $(''.newthingy).clone(), can''t remember the exact > >> jQuery > >> syntax any more. > > >> I assume there''s something similar here, can someone fill me in? > > >> Cheers, > >> Jason--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What''s interesting is that the script should even work on iFrame elements in IE (which we can not use cloneNode on directly) since it tries outerHTML first. On Feb 20, 9:19 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Very nice script but looks like it''s doing a little too much : ) > > Native element.cloneNode from DOM2 [1] already "copies all attributes > and their values" so it looks like we can safely skip #getStyles and > #clone methods. > > Something like this perhaps: > > Element.addMethods({ > toHTML: function(element) { > element = $(element); > try { > var xmlSerializer = new XMLSerializer(); > return element.nodeType == 4 > ? element.nodeValue > : xmlSerializer.serializeToString(element); > } catch(e) { > return element.xml > || element.outerHTML > || element.cloneNode(true).wrap().innerHTML; > } > } > > }); > > [1]http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-3A0ED0A4 > > - kangax > > On Feb 20, 8:44 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > I found one bug in trying this out. It sets all copies to the same > > ID, which then doesn''t play well later. I modified the clone function > > as follows to fix that: > > > clone: function(element) { > > var clone = new Element(element.tagName); > > $A(element.attributes).each(function(attribute) { if > > ( attribute.name != ''style'' && attribute.name != ''id'' ) clone > > [attribute.name] > > attribute.value; }); > > > clone.setStyle( element.getStyles() ); > > clone.identify(); > > clone.update(element.innerHTML); > > > return clone; > > } } ); > > > Walter > > > On Feb 20, 2008, at 8:33 PM, Walter Lee Davis wrote: > > > > It''s not there by default, but a bit of googling turned up this, > > > which works pretty much how you would expect: > > > >http://www.mail-archive.com/prototype-core-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org/ > > > msg01671.html > > > > Add the script after Prototype loads, but before you need to use the > > > trick. Then just do the following: > > > > $(''targetDiv'').insert({after: $(''templateDiv'').clone()}); > > > > or > > > > $(''container'').appendChild($(''templateDiv'').clone()); > > > > Walter > > > > On Feb 20, 2008, at 6:57 PM, Backov wrote: > > > >> Hey there, > > > >> I have a trick that I use in jQuery quite a lot, and I just can''t > > >> quite figure out how to do it with prototype/scriptaculous.. > > > >> Basically for elements i am going to dynamically insert I have a > > >> hidden div with all the fields and such inside it and I just did > > >> something like $(''.newthingy).clone(), can''t remember the exact > > >> jQuery > > >> syntax any more. > > > >> I assume there''s something similar here, can someone fill me in? > > > >> Cheers, > > >> Jason--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A few interesting functions there. To be honest I''m quite surprised it isn''t built in, but I guess that''s because of the DOM2 coverage. Walter - the clone script from jQuery did the same thing too, you had to set the id to something else after you cloned it. Kangax - I''m not quite sure what you''re doing there with the xml serializer? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m not doing anything with it : ) I just adopted the above mentioned script to use native cloneNode method (which should be substantially faster and eliminates quite few lines of code) I haven''t tested it, so take it with a grain of salt. - kangax On Feb 20, 10:11 pm, Backov <bac...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> A few interesting functions there. To be honest I''m quite surprised it > isn''t built in, but I guess that''s because of the DOM2 coverage. > > Walter - the clone script from jQuery did the same thing too, you had > to set the id to something else after you cloned it. > > Kangax - I''m not quite sure what you''re doing there with the xml > serializer?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Feb 20, 2008, at 9:19 PM, kangax wrote:> Something like this perhaps: > > Element.addMethods({ > toHTML: function(element) { > element = $(element); > try { > var xmlSerializer = new XMLSerializer(); > return element.nodeType == 4 > ? element.nodeValue > : xmlSerializer.serializeToString(element); > } catch(e) { > return element.xml > || element.outerHTML > || element.cloneNode(true).wrap().innerHTML; > } > } > }); > > - kangax >Thanks for the optimized code. There''s something odd going on when I use it in conjunction with insert and identify: $(''copy'').observe(''click'',function(){ var clone = $(''target'').insert({ after: $(''target'').toHTML() }); clone.id = null; clone.identify() }); To my eye, that should create a copy of the target below itself. But in fact, the opposite happens. The copies appear above the target. If I switch to insert :before, then I get what I want. Can anyone explain why this might be? Thanks again, 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 -~----------~----~----~----~------~----~------~--~---
Well, #insert returns the element that is inserted into (not the one being inserted) - so "clone" refers to an original element in this case. On Feb 21, 12:46 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Feb 20, 2008, at 9:19 PM, kangax wrote: > > > > > Something like this perhaps: > > > Element.addMethods({ > > toHTML: function(element) { > > element = $(element); > > try { > > var xmlSerializer = new XMLSerializer(); > > return element.nodeType == 4 > > ? element.nodeValue > > : xmlSerializer.serializeToString(element); > > } catch(e) { > > return element.xml > > || element.outerHTML > > || element.cloneNode(true).wrap().innerHTML; > > } > > } > > }); > > > - kangax > > Thanks for the optimized code. There''s something odd going on when I > use it in conjunction with insert and identify: > > $(''copy'').observe(''click'',function(){ > var clone = $(''target'').insert({ > after: $(''target'').toHTML() > }); > clone.id = null; > clone.identify() > > }); > > To my eye, that should create a copy of the target below itself. But > in fact, the opposite happens. The copies appear above the target. If > I switch to insert :before, then I get what I want. > > Can anyone explain why this might be? > > Thanks again, > > 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 -~----------~----~----~----~------~----~------~--~---
On Feb 21, 2008, at 8:26 AM, kangax wrote:> > Well, #insert returns the element that is inserted into (not the one > being inserted) - so "clone" refers to an original element in this > case. >SInce this toHTML extension you helped cook up doesn''t return an Element, but rather a text representation of the HTML to create one, what would be a good way to make that happen? The goal, as before, is to create a copy of an element, assign it a new ID, and insert it into the page at a specified place. So Element.insert({position: html}) returns the element that was inserted into, rather than the new element that was inserted? How would you go about extracting the inserted (generated) element in this case? Thanks again, 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 -~----------~----~----~----~------~----~------~--~---
Well, #toHTML could accept an optional id parameter (and use #identify by default) Getting a reference to an element is even easier: $(''copy'').observe(''click'', function() { var target = $(''target''), clone = target.cloneNode(true); clone.id = ''''; clone.identify(); target.insert({ after: clone }); }); - kangax On Feb 21, 8:40 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On Feb 21, 2008, at 8:26 AM, kangax wrote: > > > > > Well, #insert returns the element that is inserted into (not the one > > being inserted) - so "clone" refers to an original element in this > > case. > > SInce this toHTML extension you helped cook up doesn''t return an > Element, but rather a text representation of the HTML to create one, > what would be a good way to make that happen? The goal, as before, is > to create a copy of an element, assign it a new ID, and insert it > into the page at a specified place. > > So Element.insert({position: html}) returns the element that was > inserted into, rather than the new element that was inserted? How > would you go about extracting the inserted (generated) element in > this case? > > Thanks again, > > 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 -~----------~----~----~----~------~----~------~--~---
You might want to look at something like this: http://pastie.org/155363 Best, Tobie On Feb 21, 2:56 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, #toHTML could accept an optional id parameter (and use #identify > by default) > Getting a reference to an element is even easier: > > $(''copy'').observe(''click'', function() { > var target = $(''target''), clone = target.cloneNode(true); > clone.id = ''''; > clone.identify(); > target.insert({ after: clone }); > > }); > > - kangax > > On Feb 21, 8:40 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > On Feb 21, 2008, at 8:26 AM, kangax wrote: > > > > Well, #insert returns the element that is inserted into (not the one > > > being inserted) - so "clone" refers to an original element in this > > > case. > > > SInce this toHTML extension you helped cook up doesn''t return an > > Element, but rather a text representation of the HTML to create one, > > what would be a good way to make that happen? The goal, as before, is > > to create a copy of an element, assign it a new ID, and insert it > > into the page at a specified place. > > > So Element.insert({position: html}) returns the element that was > > inserted into, rather than the new element that was inserted? How > > would you go about extracting the inserted (generated) element in > > this case? > > > Thanks again, > > > 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 -~----------~----~----~----~------~----~------~--~---
Aha. I always forget about those DOM methods; furiously hunting through the API, as if it was meant to wrap the entire kingdom of JavaScript. Thanks, Walter On Feb 21, 2008, at 8:56 AM, kangax wrote:> > Well, #toHTML could accept an optional id parameter (and use #identify > by default) > Getting a reference to an element is even easier: > > $(''copy'').observe(''click'', function() { > var target = $(''target''), clone = target.cloneNode(true); > clone.id = ''''; > clone.identify(); > target.insert({ after: clone }); > }); > > - kangax > > On Feb 21, 8:40 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> On Feb 21, 2008, at 8:26 AM, kangax wrote: >> >> >> >>> Well, #insert returns the element that is inserted into (not the one >>> being inserted) - so "clone" refers to an original element in this >>> case. >> >> SInce this toHTML extension you helped cook up doesn''t return an >> Element, but rather a text representation of the HTML to create one, >> what would be a good way to make that happen? The goal, as before, is >> to create a copy of an element, assign it a new ID, and insert it >> into the page at a specified place. >> >> So Element.insert({position: html}) returns the element that was >> inserted into, rather than the new element that was inserted? How >> would you go about extracting the inserted (generated) element in >> this case? >> >> Thanks again, >> >> 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 -~----------~----~----~----~------~----~------~--~---
Elegant! Walter On Feb 21, 2008, at 9:06 AM, Tobie Langel wrote:> > You might want to look at something like this: > > http://pastie.org/155363 > > Best, > > Tobie > > On Feb 21, 2:56 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Well, #toHTML could accept an optional id parameter (and use >> #identify >> by default) >> Getting a reference to an element is even easier: >> >> $(''copy'').observe(''click'', function() { >> var target = $(''target''), clone = target.cloneNode(true); >> clone.id = ''''; >> clone.identify(); >> target.insert({ after: clone }); >> >> }); >> >> - kangax >> >> On Feb 21, 8:40 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> >>> On Feb 21, 2008, at 8:26 AM, kangax wrote: >> >>>> Well, #insert returns the element that is inserted into (not the >>>> one >>>> being inserted) - so "clone" refers to an original element in this >>>> case. >> >>> SInce this toHTML extension you helped cook up doesn''t return an >>> Element, but rather a text representation of the HTML to create one, >>> what would be a good way to make that happen? The goal, as >>> before, is >>> to create a copy of an element, assign it a new ID, and insert it >>> into the page at a specified place. >> >>> So Element.insert({position: html}) returns the element that was >>> inserted into, rather than the new element that was inserted? How >>> would you go about extracting the inserted (generated) element in >>> this case? >> >>> Thanks again, >> >>> 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 -~----------~----~----~----~------~----~------~--~---
Indeed, that''s a nice piece of code and did the trick, thanks Tobie. :) On Feb 21, 6:14 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Elegant! > > Walter > > On Feb 21, 2008, at 9:06 AM, Tobie Langel wrote: > > > > > You might want to look at something like this: > > >http://pastie.org/155363 > > > Best, > > > Tobie > > > On Feb 21, 2:56 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Well, #toHTML could accept an optional id parameter (and use > >> #identify > >> by default) > >> Getting a reference to an element is even easier: > > >> $(''copy'').observe(''click'', function() { > >> var target = $(''target''), clone = target.cloneNode(true); > >> clone.id = ''''; > >> clone.identify(); > >> target.insert({ after: clone }); > > >> }); > > >> - kangax > > >> On Feb 21, 8:40 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > >>> On Feb 21, 2008, at 8:26 AM, kangax wrote: > > >>>> Well, #insert returns the element that is inserted into (not the > >>>> one > >>>> being inserted) - so "clone" refers to an original element in this > >>>> case. > > >>> SInce this toHTML extension you helped cook up doesn''t return an > >>> Element, but rather a text representation of the HTML to create one, > >>> what would be a good way to make that happen? The goal, as > >>> before, is > >>> to create a copy of an element, assign it a new ID, and insert it > >>> into the page at a specified place. > > >>> So Element.insert({position: html}) returns the element that was > >>> inserted into, rather than the new element that was inserted? How > >>> would you go about extracting the inserted (generated) element in > >>> this case? > > >>> Thanks again, > > >>> 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 -~----------~----~----~----~------~----~------~--~---