Skip to content

Commit

Permalink
Release v0.1.4, Fix #35, Fix Safari Private Browsing and IE protected…
Browse files Browse the repository at this point in the history
… mode localStorage exceptions
  • Loading branch information
MrSwitch committed Mar 17, 2014
1 parent 75256d6 commit e4a8669
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hello",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "http://adodson.com/hello.js/",
"license" : "https://github.com/MrSwitch/hello.js/blob/master/LICENSE",
"repository": {
Expand Down
77 changes: 60 additions & 17 deletions dist/hello.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,34 +589,77 @@ hello.utils.extend( hello.utils, {

//
// Local Storage Facade
store : function (name,value,days) {
store : (function(localStorage){

// Local storage
var json = JSON.parse(localStorage.getItem('hello')) || {};
//
// LocalStorage
var a = [localStorage,window.sessionStorage],
i=0;

if(name && typeof(value) === 'undefined'){
return json[name];
}
else if(name && value === ''){
// Set LocalStorage
localStorage = a[i++];

while(localStorage){
try{
delete json[name];
localStorage.setItem(i,i);
localStorage.removeItem(i);
break;
}
catch(e){
json[name]=null;
localStorage = a[i++];
}
}
else if(name){
json[name] = value;
}
else {
return json;

if(!localStorage){
localStorage = {
getItem : function(prop){
prop = prop +'=';
var m = document.cookie.split(";");
for(var i=0;i<m.length;i++){
var _m = m[i].replace(/(^\s+|\s+$)/,'');
if(_m && _m.indexOf(prop)===0){
return _m.substr(prop.length);
}
}
return null;
},
setItem : function(prop, value){
document.cookie = prop + '=' + value;
}
};
}

localStorage.setItem('hello', JSON.stringify(json));
// Does this browser support localStorage?

return json;
},
return function (name,value,days) {

// Local storage
var json = JSON.parse(localStorage.getItem('hello')) || {};

if(name && typeof(value) === 'undefined'){
return json[name];
}
else if(name && value === ''){
try{
delete json[name];
}
catch(e){
json[name]=null;
}
}
else if(name){
json[name] = value;
}
else {
return json;
}

localStorage.setItem('hello', JSON.stringify(json));

return json;
};

})(window.localStorage),

//
// Create and Append new Dom elements
Expand Down
26 changes: 13 additions & 13 deletions dist/hello.all.min.js

Large diffs are not rendered by default.

77 changes: 60 additions & 17 deletions dist/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,34 +589,77 @@ hello.utils.extend( hello.utils, {

//
// Local Storage Facade
store : function (name,value,days) {
store : (function(localStorage){

// Local storage
var json = JSON.parse(localStorage.getItem('hello')) || {};
//
// LocalStorage
var a = [localStorage,window.sessionStorage],
i=0;

if(name && typeof(value) === 'undefined'){
return json[name];
}
else if(name && value === ''){
// Set LocalStorage
localStorage = a[i++];

while(localStorage){
try{
delete json[name];
localStorage.setItem(i,i);
localStorage.removeItem(i);
break;
}
catch(e){
json[name]=null;
localStorage = a[i++];
}
}
else if(name){
json[name] = value;
}
else {
return json;

if(!localStorage){
localStorage = {
getItem : function(prop){
prop = prop +'=';
var m = document.cookie.split(";");
for(var i=0;i<m.length;i++){
var _m = m[i].replace(/(^\s+|\s+$)/,'');
if(_m && _m.indexOf(prop)===0){
return _m.substr(prop.length);
}
}
return null;
},
setItem : function(prop, value){
document.cookie = prop + '=' + value;
}
};
}

localStorage.setItem('hello', JSON.stringify(json));
// Does this browser support localStorage?

return json;
},
return function (name,value,days) {

// Local storage
var json = JSON.parse(localStorage.getItem('hello')) || {};

if(name && typeof(value) === 'undefined'){
return json[name];
}
else if(name && value === ''){
try{
delete json[name];
}
catch(e){
json[name]=null;
}
}
else if(name){
json[name] = value;
}
else {
return json;
}

localStorage.setItem('hello', JSON.stringify(json));

return json;
};

})(window.localStorage),

//
// Create and Append new Dom elements
Expand Down
2 changes: 1 addition & 1 deletion dist/hello.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "HelloJS",
"version": "0.1.3",
"version": "0.1.4",
"scripts": {
"test": "karma start",
"build": "node _build.js"
Expand Down

0 comments on commit e4a8669

Please sign in to comment.