randyk (1) [Avatar] Offline
#1
I just started the book and I am enjoying it. I have minor comment on the code in section 2.6.2. You might want to drop a note explaining how the line "$(ui.draggable).data('id')" works. This appeared to be a little magical to me at least. It wasn't until I drilled down into the jQuery.extend code that I figured out how the "data("id")" was able to return data stored in the data-id attribute. Thanks.
stephan.hochhaus (92) [Avatar] Offline
#2
Re: Comment on 2.6.2
Thank you, I have added this to my list for the next update to chapter 2.
Jay Cheroske (4) [Avatar] Offline
#3
I too found this code confusing, so I put some logging calls in to look at the various objects. What I found was that
ui.draggable
was already a jQuery object. Which meant that:

$(ui.draggable).data('id')


should be able to be replaced with:

ui.draggable.data('id')


with no ill effects. I tested it and my little app still works. What am I missing?
stephan.hochhaus (92) [Avatar] Offline
#4
You are not missing anything - both variants work well. We decided to use the slightly more verbose approach to indicate that we're dealing with jQuery functionality here.
Added a remark in the chapter to be included in the next MEAP update.


Edit After sleeping on it we will use your code instead - it's much shorter and less confusing. Thanks again for bringing it up! It's much appreciated
stephan.hochhaus (92) [Avatar] Offline
#5
Changed in MEAP v8, but it is actually 2.5.2 now.