Hello again,

I'm still getting no joy with this - even when using the MoveToCargo
function and setting the value directly before the appending of the
information.. it's still copying across the old value.  I've worked
out a code route around it (by putting all the values of objects into
an array and updating them based on where their last drop location is)
- but surely that's an extreme measure that's not really needed?

// Move to Cargo function
        function MoveToCargo($item) {
                alert("Location : " + $item.data("location"));  //
shows old loc
                var $Hanger = $('#Hanger'), $Cargo = $('#Cargo');
                $item.data("location", "Cargo");
                alert("Location : " + $item.data("location")); //
shows new loc
                $item.fadeOut(function() {
                        $item.data("location", "Cargo");
                        alert("Location : " + $item.data
("location")); // shows new loc
                        $item.appendTo($Cargo).fadeIn();
                        alert("Location : " + $item.data
("location")); // shows new loc
                        CargoHanger();
                });
        }; // but the item is added with the old value??!?!?!?!

Any help on this would be appreciated before I do it the other way :)

TIA,
Paul


On Mar 30, 12:45 pm, Paul Hutson <[email protected]> wrote:
> Hello again,
>
> I've worked out where my problem is..
>
> When I've moved an item from the, in this case, hanger to the cargo
> (as in dragged an item from my "hanger" box to my "cargo" box) it
> create and item, removes it from the Hanger.. and appends it to the
> cargo.  However, when it appends it to the cargo, it's still saying
> it's a "hanger" item (as in, it's still a $('li',$Hanger).draggable,
> rather than now being something in the cargo lot).
>
> Any ideas on how to get it to be associated with the cargo draggables,
> rather than the hanger?
>
> I've attached the relevant code below.
>
> Regards,
> Paul
>
> // let the Hanger items be draggable
>                 $('li',$Hanger).draggable({
>                         cancel: 'a.ui-icon',// clicking an icon won't 
> initiate dragging
>                         revert: 'invalid', // when not dropped, the item will 
> revert back
> to its initial position
>                         helper: 'clone',
>                         cursor: 'move',
>                         zIndex: 10000,
>                         appendTo: 'body',
>                         start: function() {
>                                  $(this).data("location", "Hanger");
>                                  ToSystemChat("\nHanger thread : " + 
> $(this).data("location"));
>                         }
>                 });
>
>  // let the Cargo be droppable, accepting the Hanger items
>                 $Cargo.droppable({
>                         accept: '#Hanger  li',
>                         drop: function(ev, ui) {
>                                 if (ui.draggable.data("location") == "Hanger")
>                                 {
>                                         ToSystemChat("Start Loc : " + 
> ui.draggable.data("location"));
>                                         if 
> ((parseInt(PlayerDetails.ShipDetails.CurrentCargoAmount) +
> parseInt($(ui.draggable).attr("No"))) <=
> PlayerDetails.ShipDetails.CargoCapacity)
>                                         {
>                                                 
> PlayerDetails.ShipDetails.CurrentCargoAmount = parseInt
> (PlayerDetails.ShipDetails.CurrentCargoAmount) + parseInt($
> (ui.draggable).attr("No"));
>                                                 CurrentHangerAmount = 
> parseInt(CurrentHangerAmount) - parseInt($
> (ui.draggable).attr("No"));
>                                                 TransferCargo("Hanger", 
> ui.draggable, $(ui.draggable).attr
> ("id"), PlayerDetails.CharacterShipID, "1");
>                                                 
> document.getElementById("CargoCapacity").height = ssBarSize -
> (((PlayerDetails.ShipDetails.CurrentCargoAmount/
> PlayerDetails.ShipDetails.CargoCapacity)*100)*ssBarSizeSegment);
>                                                 
> document.getElementById("HangerCapacity").height = ssBarSize -
> (((CurrentHangerAmount/HangerSize)*100)*ssBarSizeSegment);
>                                         } else {
>                                                 alert("not enough room");
>                                         };
>                                 };
>                         }
>                 });
>
> // Move to Cargo function
>         function MoveToCargo($item) {
>                 ToSystemChat("Location : " + $item.data("location"));
>                 var $Hanger = $('#Hanger'), $Cargo = $('#Cargo');
>                 $item.data("location", "Cargo");
>                 $item.fadeOut(function() {
>                         $item.data("location", "Cargo");
>                         $item.appendTo($Cargo).fadeIn();
>                         CargoHanger();
>                 });
>         };
>
> On Mar 28, 6:23 pm, PaulHutson<[email protected]> wrote:
>
>
>
> > Richard, thank you very very much - I realise, looking up through the
> > code again, that I was being a bit thick with that last message!
>
> > On Mar 27, 3:01 pm, "Richard D. Worth" <[email protected]> wrote:
>
> > > Set a new value when it's in a new place
>
> > > $item.data("location", "newValue")
>
> > > - Richard
>
> > > On Fri, Mar 27, 2009 at 10:57 AM, PaulHutson
> > > <[email protected]>wrote:
>
> > > > Richard,
>
> > > > Fantastic - just what I was looking for!
>
> > > > I now know where the item starts.. however, when it gets to the new
> > > > location.. how do I reassociate the item with it's new home.. it seems
> > > > to copy across the information.
>
> > > > I'm using the following code to move the item :
>
> > > >        // Move to Cargo function
> > > >        function MoveToCargo($item) {
> > > >                var $Hanger = $('#Hanger'), $Cargo = $('#Cargo');
> > > >                $item.fadeOut(function() {
> > > >                        $item.appendTo($Cargo).fadeIn();
> > > >                        $item.data("location") == "Cargo";  //this was 
> > > > how
> > > > I've been trying
> > > > to reassociate it.. but no joy.
> > > >                });
> > > >        };
>
> > > > Any ideas?
>
> > > > Tia,
> > > > Paul
>
> > > > On Mar 27, 11:02 am, "Richard D. Worth" <[email protected]> wrote:
> > > > > Something like this, perhaps?
>
> > > > > $("#draggable").draggable({
> > > > >   start: function() {
> > > > >     $(this).data("location", "RIGHTBOX");
> > > > >   }});
>
> > > > > $("#droppable").droppable({
> > > > >   drop: function(event, ui) {
> > > > >     alert(ui.draggable.data("location"));
> > > > >   }
>
> > > > > });
>
> > > > > - Richard
>
> > > > > On Fri, Mar 27, 2009 at 4:58 AM, PaulHutson<
> > > > [email protected]>wrote:
>
> > > > > > Thanks for the reply Shedokan.. I'm not quite sure I'm following you
> > > > > > though. ... when I say the origin, I want to - upon clicking on an
> > > > > > item, assign it with a start location variable (scope, or something
> > > > > > else.. with say a value of "RIGHTBOX") then when I drop it 
> > > > > > somewhere I
> > > > > > want to be able to read that variable back...
>
> > > > > > Any ideas on that front?
>
> > > > > > TIA,
> > > > > > PaulHutson
>
> > > > > > On Mar 26, 11:44 pm, Shedokan <[email protected]> wrote:
> > > > > > > If your'e calling it inside a function of the draggable so you can
> > > > use
> > > > > > > $(ui.draggable).draggable('option', 'scope') because there is no
> > > > > > > ui.draggable
>
> > > > > > > alose if you mean that you want to get the left and top position 
> > > > > > > you
> > > > > > > can use ui.offset.
>
> > > > > > > On 26 מרץ, 16:57, PaulHutson<[email protected]> wrote:
>
> > > > > > > > As a bit of an addon... the thing I really want to do is find 
> > > > > > > > out
> > > > > > > > draggable objects origin location is.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" 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/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to