Cookie script to LocalStorage?
Hello all, I need some help here. I'm new to HTML 5 and I'm not sure how to convert my cookie script over to HTML 5 LocalStorage. If anyone could help, I would appreciate it greatly.
Here's my cookie script:
Code:
var currentRotation=null;
function checkOrientAndLocation(){
if(currentRotation != window.orientation){
setOrientation();
}
}
function setOrientation(){
switch(window.orientation){
case 0:
orient = 'portrait';
break;
case 90:
orient = 'landscape';
break;
case -90:
orient = 'landscape';
break;
}
currentRotation = window.orientation;
document.body.setAttribute("orient",orient);
setTimeout(scrollTo,0,0,1);
}
$(window).unload(function() { // On page unload
$('.remember').each(function() { // Save each value to expire in a year
$.cookie(this.id, this.value, {expires: 365});
});
$('.draggable').each(function() { // Save draggable positions
var draggable = $(this);
$.cookie(this.id, draggable.css('top') + '_' + draggable.css('left'), {expires: 365});
$.cookie('disp' + this.id, draggable.css('display'), {expires: 365});
});
});
$(function() {
var val, pos, disp;
setInterval(checkOrientAndLocation,1000);
$('.remember').each(function() {
var val = $.cookie(this.id); // Retrieve value for this element
if (val) {
this.value = val;
}
}
);
$('.draggable').each(function() {
var pos = $.cookie(this.id); // Retrieve values for this element
if (pos) {
pos = pos.split('_');
$(this).css({position: 'absolute', top: pos[0], left: pos[1]});
}
var disp = $.cookie('disp' + this.id);
if (disp) {
this.style.display = disp;
}
}
).touch({animate: false, sticky: false, dragx: true, dragy: true,
rotate: false, resort: false, scale: false
});
});