mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-31 13:10:23 +00:00
54 lines
996 B
JavaScript
54 lines
996 B
JavaScript
(function() {
|
|
var defaults = [
|
|
{
|
|
type: "currency",
|
|
from: "USD",
|
|
to: "EUR"
|
|
},
|
|
{
|
|
type: "distance",
|
|
from: "Miles",
|
|
to: "Kilometer",
|
|
rate: 1.609344
|
|
},
|
|
{
|
|
type: "distance",
|
|
from: "inch",
|
|
to: "centimeter",
|
|
rate: 2.54
|
|
}
|
|
];
|
|
|
|
// TODO fallback to whatever else when localStorage isn't available
|
|
function get() {
|
|
return JSON.parse(localStorage.getItem("conversions"));
|
|
}
|
|
function set(value) {
|
|
console.log("storing conversion: "+ JSON.stringify(value))
|
|
localStorage.setItem("conversions", JSON.stringify(value));
|
|
}
|
|
|
|
var conversions = get("conversions");
|
|
if (!conversions) {
|
|
conversions = $.extend([], defaults);
|
|
}
|
|
set(conversions);
|
|
window.conversions = {
|
|
store: function() {
|
|
set(conversions);
|
|
},
|
|
all: function() {
|
|
return conversions;
|
|
},
|
|
clear: function() {
|
|
conversions.length = 0;
|
|
this.store();
|
|
},
|
|
restore: function() {
|
|
conversions.length = 0;
|
|
$.extend(conversions, defaults);
|
|
this.store();
|
|
}
|
|
};
|
|
|
|
})();
|