Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

精确检测localstorage是否可用 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions 1.1/build/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ KISSY.add('gallery/storage/1.1/basic', function(S, JSON) {
}
store.getAll = function() {
}

store.key = function(index) {
}
store.serialize = function(value) {
return JSON.stringify(value)
}
Expand Down Expand Up @@ -103,6 +104,9 @@ KISSY.add('gallery/storage/1.1/basic', function(S, JSON) {
}
return ret
}
store.key = function(index) {
return storage.key(index);
}
}
else if (doc.documentElement.addBehavior) {
var storageOwner,
Expand Down Expand Up @@ -195,16 +199,31 @@ KISSY.add('gallery/storage/1.1/basic', function(S, JSON) {
}
return ret
})
store.key = withIEStorage(function(storage, index) {
var keys = []
store.forEach(function(key, val) {
keys.push(key)
})
return keys[index]
})
}

//alert(namespace + '-' + store.get(namespace));
try {
store.set(namespace, namespace)
//alert(namespace + '-' + store.get(namespace));
if (store.get(namespace) != namespace) {
store.disabled = true
//精确检测,防止我们自己cache大于storage的上限以后,检测不准
var tempKey = store.key(0)
var tempData = store.get(tempKey)
if(tempKey) {
store.remove(tempKey)
store.set(tempKey, tempData)
} else {
store.set(namespace, namespace)
//alert(namespace + '-' + store.get(namespace));
if (store.get(namespace) != namespace) {
store.disabled = true
}
store.remove(namespace)
}
store.remove(namespace)
} catch (e) {
store.disabled = true
}
Expand All @@ -223,5 +242,4 @@ KISSY.add('gallery/storage/1.1/basic', function(S, JSON) {
return window.__storejs;
}, {
requires: ['json']
});

});