1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

wrapping localStorage.key(n) in try { ... } block to not break in FF

This commit is contained in:
Alex Dorey 2012-05-15 11:49:40 -04:00
parent f583d510c1
commit 08f0fbc523

View File

@ -161,10 +161,12 @@ window.zerobin = {
getKeys: function(){
var keys = [];
if(localStorage.key(i) !== null){
keys[i] = parseInt(localStorage.key(i), 10);
}
for(var i = 0; i < localStorage.length; i++){
try {
if(localStorage.key(i) !== null){
keys[i] = parseInt(localStorage.key(i), 10);
}
} catch(e) {}
}
return keys.sort(zerobin.numOrdA);
},
@ -222,15 +224,17 @@ window.zerobin = {
date = zerobin.getFormatedDate();
keys.reverse();
var paste = localStorage.getItem(keys[i]).split(';');
var displayDate = paste[0].split(' ')[0];
var prefix = 'the ';
if (displayDate === date){
displayDate = paste[0].split(' ')[1];
prefix = 'at ';
}
pastes.push({displayDate: displayDate, prefix: prefix, link: paste[1]});
for (var i = 0; i < keys.length; i++) {
try {
var paste = localStorage.getItem(keys[i]).split(';');
var displayDate = paste[0].split(' ')[0];
var prefix = 'the ';
if (displayDate === date){
displayDate = paste[0].split(' ')[1];
prefix = 'at ';
}
pastes.push({displayDate: displayDate, prefix: prefix, link: paste[1]});
} catch(e) {}
}
return pastes;