Reputation: 10256
How do i save a draggable element so the next time i load it, i don't have to issue the draggable()
function again.
I thought having the class ui-draggable
will automatically make the element get recognized as draggable but i see that's not the case.
This is the saved draggble element.
<div id="one" class="ui-draggable">test 1 </div>
Do i have to issue the draggable() function again to make it draggable.
Upvotes: 0
Views: 463
Reputation: 14630
You always have to issue the draggable(). I would suggest sticking with FishBasket's response and just doing it.
The reason you have to do it again is because it's behavior - not content. So it's done with JS, not HTML. Saving the HTML doesn't help you, and you can't "save" the JS execution - you just have to run it again.
If you're masochistic, you can do it collectively for all your draggables on the page though using a live event / delegate on mouseover. But I wouldn't recommend a live mouseover as it's a performance concern for older browsers.
$(document).delegate('selectorForDraggables', 'mouseover', function() {
var $this = $(this);
$this.data('isDraggable') || $this.draggable().data('isDraggable', true);
});
This will delay the draggable call for an element until you mouseover that element. The problem is now you have to check EVERY element onmouseover to see whether to do the draggable call...
Upvotes: 1
Reputation: 23142
The short answer is: Yes, you have to call draggable every time the page loads. I would just call it in the ready event. That's the typical way to do it.
Upvotes: 1