lovitt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-26 00:00 UTC
Possible to restrict Sortables by CSS class?
Hello, I''m trying to implement the following with Sortable:
I have two lists -- in each list, the user can drag and drop to
reorder the elements inside. The tricky part is that some (but not
all) of the elements in the first list should also be draggable to the
second list; likewise, some from the second should be draggable to the
first.
I''ve tried implementing this using the "constraint" and
"only"
options, but neither seem to help ("constraint" determines which
source lists the target list will accept elements from; "only," I
think, determines which elements inside the given list should be
draggable within that list; but neither determines which specific
elements from outside the target list the target list will accept).
It seems like what I need is something like the "accept" option that
is available on a call to Droppables.add() -- a way to restrict
incoming elements by CSS class. Is there an equivalent way to
accomplish this with Sortables?
Sample code, which uses the nonfunctional "accept" option that I wish
existed, is below.
Thanks,
Michael
---
<div id="list1">
<div class="free_item">i should be draggable to either
list</div>
<div class="list1_locked_item">i should be draggable only in
list1</div>
</div>
<div id="list2">
<div class="free_item">i should be draggable to either
list</div>
<div class="list2_locked_item">i should be draggable only in
list2</div>
</div>
<script type="text/javascript">
Sortable.create(
"list1",
{
tag:''div'',
containment:[''list1'',''list2''],
accept:[''free_item'',''list1_locked_item'']
constraint:false,
dropOnEmpty:true,
});
Sortable.create(
"list2",
{
tag:''div'',
containment:[''list1'',''list2''],
accept:[''free_item'',''list2_locked_item'']
constraint:false,
dropOnEmpty:true,
});
</script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Should be easy enough to fix.
In dragdrop.js lines 681-688 (revision 6864) do the following:
// build options for the droppables
var options_for_droppable = {
overlap: options.overlap,
+ accept: options.accept || null,
containment: options.containment,
tree: options.tree,
hoverclass: options.hoverclass,
onHover: Sortable.onHover
}
If your Sortable is a tree, then you''ll need to add the same line a
few lines later inside the "options_for_tree" hash.
I don''t have time to test it at the moment, but I think that''s
all
it''ll take. If you try it and it works, open a ticket and submit a
patch!
TAG
On May 25, 2007, at 6:00 PM, lovitt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
wrote:
>
> Hello, I''m trying to implement the following with Sortable:
>
> I have two lists -- in each list, the user can drag and drop to
> reorder the elements inside. The tricky part is that some (but not
> all) of the elements in the first list should also be draggable to the
> second list; likewise, some from the second should be draggable to the
> first.
>
> I''ve tried implementing this using the "constraint" and
"only"
> options, but neither seem to help ("constraint" determines which
> source lists the target list will accept elements from; "only," I
> think, determines which elements inside the given list should be
> draggable within that list; but neither determines which specific
> elements from outside the target list the target list will accept).
>
> It seems like what I need is something like the "accept" option
that
> is available on a call to Droppables.add() -- a way to restrict
> incoming elements by CSS class. Is there an equivalent way to
> accomplish this with Sortables?
>
> Sample code, which uses the nonfunctional "accept" option that I
wish
> existed, is below.
>
> Thanks,
>
> Michael
>
> ---
>
> <div id="list1">
> <div class="free_item">i should be draggable to either
list</div>
> <div class="list1_locked_item">i should be draggable
only in
> list1</div>
> </div>
>
> <div id="list2">
> <div class="free_item">i should be draggable to either
list</div>
> <div class="list2_locked_item">i should be draggable
only in
> list2</div>
> </div>
>
> <script type="text/javascript">
>
> Sortable.create(
> "list1",
> {
> tag:''div'',
>
containment:[''list1'',''list2''],
>
accept:[''free_item'',''list1_locked_item'']
> constraint:false,
> dropOnEmpty:true,
> });
>
> Sortable.create(
> "list2",
> {
> tag:''div'',
>
containment:[''list1'',''list2''],
>
accept:[''free_item'',''list2_locked_item'']
> constraint:false,
> dropOnEmpty:true,
> });
>
> </script>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---