As far as for what's available without server side code, a javascript cookie is about the best. Cookies can be disabled though, even when javascript is active. Usually they are active. Whatever method you choose, as far as I know, the information can only be stored as a string.
I see that the touch() code uses the element's id. I don't think it needs to be activated by that id. If so, you can give each draggable the same class, and keep each ones unique id. That way you could initialize them all with - say the class was, 'draggable', replacing this and similar:
Code:
$('#touchme1').touch({
animate: false,
sticky: false,
dragx: true,
dragy: true,
rotate: false,
resort: false,
scale: false
});
with a single:
Code:
$('.draggable').touch({
animate: false,
sticky: false,
dragx: true,
dragy: true,
rotate: false,
resort: false,
scale: false
});
But it might not work like that. But if we add the class anyway, we can simplify the cookie. You could make the name be the id. That way we could be setting a cookie for each draggable, only if they get moved:
Code:
function touchmove(e){
if(_dragging && !_sizing && _animate) {
var _lastleft = (isNaN(parseInt($('#'+_target).css("left")))) ? 0:parseInt($('#'+_target).css("left"));
var _lasttop = (isNaN(parseInt($('#'+_target).css("top")))) ? 0:parseInt($('#'+_target).css("top"));
}
$(e.changedTouches).each(function(){
e.preventDefault();
_left = (this.pageX-(parseInt($('#'+_target).css("width"))/2));
_top = (this.pageY-(parseInt($('#'+_target).css("height"))/2));
if(_dragging && !_sizing) {
if(_animate){
_xspeed = Math.round((_xspeed + Math.round( _left - _lastleft))/1.5);
_yspeed = Math.round((_yspeed + Math.round( _top - _lasttop))/1.5);
}
if(_dragx || _dragy) $('#'+_target).css({ position: "absolute" });
if(_dragx) $('#'+_target).css({ left: _left+"px" });
if(_dragy) $('#'+_target).css({ top: _top+"px" });
if(_dragx || _dragy) $.cookie(_target,($('#'+_target).css('top')||'')+'_'+($('#'+_target).css('left')||''));
$('#'+_target).css({ backgroundColor: "" });
$('#'+_target+' b').text('');
}
});
};
resulting in up to eight short cookies if all of the draggables get moved.
Then, when the page loads again, you could do as part of your document ready code:
Code:
$('.draggable').each(function(){
if($.cookie(this.id)){
var pos = $.cookie(this.id).split('_');
$(this).css({position: 'absolute', top: pos[0], left: pos[1]});
}
}
);
Bookmarks