44 lines
852 B
JavaScript
44 lines
852 B
JavaScript
|
var Storage = {
|
||
|
get: function(key) {
|
||
|
return window.localStorage.getItem(key);
|
||
|
},
|
||
|
|
||
|
set: function(key, value) {
|
||
|
if (typeof(value) == 'object') {
|
||
|
window.localStorage.setItem(key, JSON.stringify(value));
|
||
|
} else {
|
||
|
window.localStorage.setItem(key, value);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
getWithDefault: function(key, defaultValue) {
|
||
|
var value = this.get(key);
|
||
|
|
||
|
if (value != null) {
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
if (arguments[1]) {
|
||
|
this.set(key, defaultValue);
|
||
|
return defaultValue;
|
||
|
}
|
||
|
return null;
|
||
|
},
|
||
|
|
||
|
remove: function(key) {
|
||
|
var value = this.get(key);
|
||
|
window.localStorage.removeItem(key);
|
||
|
return value;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var FlightStorage = {
|
||
|
getQuery: function() {
|
||
|
return {
|
||
|
from: Storage.get('flightFrom'),
|
||
|
to: Storage.get('flightTo'),
|
||
|
date: parseInt(Storage.get('flightDate')),
|
||
|
moreDays: Storage.get('flightFiveDays') == 'true'
|
||
|
};
|
||
|
}
|
||
|
};
|