info-Rt+jRHwf3olhrNIvIkuUv7NldLUNz+W/@public.gmane.org
2007-Nov-30 10:24 UTC
make sortable divs and innerHTML
My problem is that elements that were included in my site with innerHTML can´t be sortable because the DOM doesn´t know that these elements are there. Has anybody a solution or an idea to this problem? 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 -~----------~----~----~----~------~----~------~--~---
On Nov 30, 2007, at 5:24 AM, info-Rt+jRHwf3olhrNIvIkuUv7NldLUNz+W/@public.gmane.org wrote:> > My problem is that elements that were included in my site with > innerHTML can´t be sortable because the DOM doesn´t know that these > elements are there. > Has anybody a solution or an idea to this problem? > > ToM >Remove the sortable before you add the elements, and add it again after. The following code does something slightly different (adds sortable after showing the handles and hiding everything that''s not essential for the sort), but shows the basic syntax to programmatically add and remove the sortable handlers. removeHandles = function(evt){ $$(''div.handle'').invoke(''hide''); $$(''.sort_hide'').invoke(''show''); $(''sort'').stopObserving(''click'',removeHandles); $(''sort'').update(''Updating...''); $(''sort_order'').value = thelist = Sortable.serialize(''thelist''); new Ajax.Request(''/ajax_save_sort_order.php'',{parameters: {sort_order: thelist},onComplete: function(transport){ Sortable.destroy(''thelist''); $(''sort'').update(''Change Order''); $(''sort'').observe(''click'',addHandles); refreshList(); }}) }; addHandles = function(evt){ $$(''div.handle'').invoke(''show''); $$(''.sort_hide'').invoke(''hide''); $(''sort'').update(''Done Sorting''); $(''sort'').stopObserving(''click'',addHandles); Sortable.create(''thelist'', {dropOnEmpty:false,handle:''handle'',constraint:''vertical''}); $(''sort'').observe(''click'',removeHandles); }; $(''sort'').observe(''click'',addHandles); 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 Nov 30, 12:24 pm, "i...-Rt+jRHwf3olhrNIvIkuUv7NldLUNz+W/@public.gmane.org" <i...-Rt+jRHwf3olhrNIvIkuUv7NldLUNz+W/@public.gmane.org> wrote:> My problem is that elements that were included in my site with > innerHTML can´t be sortable because the DOM doesn´t know that these > elements are there. > Has anybody a solution or an idea to this problem? > > ToMSimply make sure that you call your Sortable.create method AFTER you add the elements using innerHTML and that the elements are of the same kind (same tag) as the tag specified in the Sortable.create options. That should do it. If the sortable is created before and you add elements through innerHTML you can also use Sortable.create to re- create it and incorporate the newly added elements. Hope this helps. All the best, George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---