测试版
This commit is contained in:
9
node_modules/store/storages/all.js
generated
vendored
Normal file
9
node_modules/store/storages/all.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = [
|
||||
// Listed in order of usage preference
|
||||
require('./localStorage'),
|
||||
require('./oldFF-globalStorage'),
|
||||
require('./oldIE-userDataStorage'),
|
||||
require('./cookieStorage'),
|
||||
require('./sessionStorage'),
|
||||
require('./memoryStorage')
|
||||
]
|
||||
61
node_modules/store/storages/cookieStorage.js
generated
vendored
Normal file
61
node_modules/store/storages/cookieStorage.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// cookieStorage is useful Safari private browser mode, where localStorage
|
||||
// doesn't work but cookies do. This implementation is adopted from
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
|
||||
|
||||
var util = require('../src/util')
|
||||
var Global = util.Global
|
||||
var trim = util.trim
|
||||
|
||||
module.exports = {
|
||||
name: 'cookieStorage',
|
||||
read: read,
|
||||
write: write,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll,
|
||||
}
|
||||
|
||||
var doc = Global.document
|
||||
|
||||
function read(key) {
|
||||
if (!key || !_has(key)) { return null }
|
||||
var regexpStr = "(?:^|.*;\\s*)" +
|
||||
escape(key).replace(/[\-\.\+\*]/g, "\\$&") +
|
||||
"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"
|
||||
return unescape(doc.cookie.replace(new RegExp(regexpStr), "$1"))
|
||||
}
|
||||
|
||||
function each(callback) {
|
||||
var cookies = doc.cookie.split(/; ?/g)
|
||||
for (var i = cookies.length - 1; i >= 0; i--) {
|
||||
if (!trim(cookies[i])) {
|
||||
continue
|
||||
}
|
||||
var kvp = cookies[i].split('=')
|
||||
var key = unescape(kvp[0])
|
||||
var val = unescape(kvp[1])
|
||||
callback(val, key)
|
||||
}
|
||||
}
|
||||
|
||||
function write(key, data) {
|
||||
if(!key) { return }
|
||||
doc.cookie = escape(key) + "=" + escape(data) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
if (!key || !_has(key)) {
|
||||
return
|
||||
}
|
||||
doc.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
each(function(_, key) {
|
||||
remove(key)
|
||||
})
|
||||
}
|
||||
|
||||
function _has(key) {
|
||||
return (new RegExp("(?:^|;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(doc.cookie)
|
||||
}
|
||||
38
node_modules/store/storages/localStorage.js
generated
vendored
Normal file
38
node_modules/store/storages/localStorage.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
var util = require('../src/util')
|
||||
var Global = util.Global
|
||||
|
||||
module.exports = {
|
||||
name: 'localStorage',
|
||||
read: read,
|
||||
write: write,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll,
|
||||
}
|
||||
|
||||
function localStorage() {
|
||||
return Global.localStorage
|
||||
}
|
||||
|
||||
function read(key) {
|
||||
return localStorage().getItem(key)
|
||||
}
|
||||
|
||||
function write(key, data) {
|
||||
return localStorage().setItem(key, data)
|
||||
}
|
||||
|
||||
function each(fn) {
|
||||
for (var i = localStorage().length - 1; i >= 0; i--) {
|
||||
var key = localStorage().key(i)
|
||||
fn(read(key), key)
|
||||
}
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
return localStorage().removeItem(key)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
return localStorage().clear()
|
||||
}
|
||||
39
node_modules/store/storages/memoryStorage.js
generated
vendored
Normal file
39
node_modules/store/storages/memoryStorage.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// memoryStorage is a useful last fallback to ensure that the store
|
||||
// is functions (meaning store.get(), store.set(), etc will all function).
|
||||
// However, stored values will not persist when the browser navigates to
|
||||
// a new page or reloads the current page.
|
||||
|
||||
module.exports = {
|
||||
name: 'memoryStorage',
|
||||
read: read,
|
||||
write: write,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll,
|
||||
}
|
||||
|
||||
var memoryStorage = {}
|
||||
|
||||
function read(key) {
|
||||
return memoryStorage[key]
|
||||
}
|
||||
|
||||
function write(key, data) {
|
||||
memoryStorage[key] = data
|
||||
}
|
||||
|
||||
function each(callback) {
|
||||
for (var key in memoryStorage) {
|
||||
if (memoryStorage.hasOwnProperty(key)) {
|
||||
callback(memoryStorage[key], key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
delete memoryStorage[key]
|
||||
}
|
||||
|
||||
function clearAll(key) {
|
||||
memoryStorage = {}
|
||||
}
|
||||
42
node_modules/store/storages/oldFF-globalStorage.js
generated
vendored
Normal file
42
node_modules/store/storages/oldFF-globalStorage.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// oldFF-globalStorage provides storage for Firefox
|
||||
// versions 6 and 7, where no localStorage, etc
|
||||
// is available.
|
||||
|
||||
var util = require('../src/util')
|
||||
var Global = util.Global
|
||||
|
||||
module.exports = {
|
||||
name: 'oldFF-globalStorage',
|
||||
read: read,
|
||||
write: write,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll,
|
||||
}
|
||||
|
||||
var globalStorage = Global.globalStorage
|
||||
|
||||
function read(key) {
|
||||
return globalStorage[key]
|
||||
}
|
||||
|
||||
function write(key, data) {
|
||||
globalStorage[key] = data
|
||||
}
|
||||
|
||||
function each(fn) {
|
||||
for (var i = globalStorage.length - 1; i >= 0; i--) {
|
||||
var key = globalStorage.key(i)
|
||||
fn(globalStorage[key], key)
|
||||
}
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
return globalStorage.removeItem(key)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
each(function(key, _) {
|
||||
delete globalStorage[key]
|
||||
})
|
||||
}
|
||||
127
node_modules/store/storages/oldIE-userDataStorage.js
generated
vendored
Normal file
127
node_modules/store/storages/oldIE-userDataStorage.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
// oldIE-userDataStorage provides storage for Internet Explorer
|
||||
// versions 6 and 7, where no localStorage, sessionStorage, etc
|
||||
// is available.
|
||||
|
||||
var util = require('../src/util')
|
||||
var Global = util.Global
|
||||
|
||||
module.exports = {
|
||||
name: 'oldIE-userDataStorage',
|
||||
write: write,
|
||||
read: read,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll,
|
||||
}
|
||||
|
||||
var storageName = 'storejs'
|
||||
var doc = Global.document
|
||||
var _withStorageEl = _makeIEStorageElFunction()
|
||||
var disable = (Global.navigator ? Global.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\./) // MSIE 9.x, MSIE 10.x
|
||||
|
||||
function write(unfixedKey, data) {
|
||||
if (disable) { return }
|
||||
var fixedKey = fixKey(unfixedKey)
|
||||
_withStorageEl(function(storageEl) {
|
||||
storageEl.setAttribute(fixedKey, data)
|
||||
storageEl.save(storageName)
|
||||
})
|
||||
}
|
||||
|
||||
function read(unfixedKey) {
|
||||
if (disable) { return }
|
||||
var fixedKey = fixKey(unfixedKey)
|
||||
var res = null
|
||||
_withStorageEl(function(storageEl) {
|
||||
res = storageEl.getAttribute(fixedKey)
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
function each(callback) {
|
||||
_withStorageEl(function(storageEl) {
|
||||
var attributes = storageEl.XMLDocument.documentElement.attributes
|
||||
for (var i=attributes.length-1; i>=0; i--) {
|
||||
var attr = attributes[i]
|
||||
callback(storageEl.getAttribute(attr.name), attr.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function remove(unfixedKey) {
|
||||
var fixedKey = fixKey(unfixedKey)
|
||||
_withStorageEl(function(storageEl) {
|
||||
storageEl.removeAttribute(fixedKey)
|
||||
storageEl.save(storageName)
|
||||
})
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
_withStorageEl(function(storageEl) {
|
||||
var attributes = storageEl.XMLDocument.documentElement.attributes
|
||||
storageEl.load(storageName)
|
||||
for (var i=attributes.length-1; i>=0; i--) {
|
||||
storageEl.removeAttribute(attributes[i].name)
|
||||
}
|
||||
storageEl.save(storageName)
|
||||
})
|
||||
}
|
||||
|
||||
// Helpers
|
||||
//////////
|
||||
|
||||
// In IE7, keys cannot start with a digit or contain certain chars.
|
||||
// See https://github.com/marcuswestin/store.js/issues/40
|
||||
// See https://github.com/marcuswestin/store.js/issues/83
|
||||
var forbiddenCharsRegex = new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]", "g")
|
||||
function fixKey(key) {
|
||||
return key.replace(/^\d/, '___$&').replace(forbiddenCharsRegex, '___')
|
||||
}
|
||||
|
||||
function _makeIEStorageElFunction() {
|
||||
if (!doc || !doc.documentElement || !doc.documentElement.addBehavior) {
|
||||
return null
|
||||
}
|
||||
var scriptTag = 'script',
|
||||
storageOwner,
|
||||
storageContainer,
|
||||
storageEl
|
||||
|
||||
// Since #userData storage applies only to specific paths, we need to
|
||||
// somehow link our data to a specific path. We choose /favicon.ico
|
||||
// as a pretty safe option, since all browsers already make a request to
|
||||
// this URL anyway and being a 404 will not hurt us here. We wrap an
|
||||
// iframe pointing to the favicon in an ActiveXObject(htmlfile) object
|
||||
// (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)
|
||||
// since the iframe access rules appear to allow direct access and
|
||||
// manipulation of the document element, even for a 404 page. This
|
||||
// document can be used instead of the current document (which would
|
||||
// have been limited to the current path) to perform #userData storage.
|
||||
try {
|
||||
/* global ActiveXObject */
|
||||
storageContainer = new ActiveXObject('htmlfile')
|
||||
storageContainer.open()
|
||||
storageContainer.write('<'+scriptTag+'>document.w=window</'+scriptTag+'><iframe src="/favicon.ico"></iframe>')
|
||||
storageContainer.close()
|
||||
storageOwner = storageContainer.w.frames[0].document
|
||||
storageEl = storageOwner.createElement('div')
|
||||
} catch(e) {
|
||||
// somehow ActiveXObject instantiation failed (perhaps some special
|
||||
// security settings or otherwse), fall back to per-path storage
|
||||
storageEl = doc.createElement('div')
|
||||
storageOwner = doc.body
|
||||
}
|
||||
|
||||
return function(storeFunction) {
|
||||
var args = [].slice.call(arguments, 0)
|
||||
args.unshift(storageEl)
|
||||
// See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx
|
||||
// and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx
|
||||
storageOwner.appendChild(storageEl)
|
||||
storageEl.addBehavior('#default#userData')
|
||||
storageEl.load(storageName)
|
||||
storeFunction.apply(this, args)
|
||||
storageOwner.removeChild(storageEl)
|
||||
return
|
||||
}
|
||||
}
|
||||
38
node_modules/store/storages/sessionStorage.js
generated
vendored
Normal file
38
node_modules/store/storages/sessionStorage.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
var util = require('../src/util')
|
||||
var Global = util.Global
|
||||
|
||||
module.exports = {
|
||||
name: 'sessionStorage',
|
||||
read: read,
|
||||
write: write,
|
||||
each: each,
|
||||
remove: remove,
|
||||
clearAll: clearAll
|
||||
}
|
||||
|
||||
function sessionStorage() {
|
||||
return Global.sessionStorage
|
||||
}
|
||||
|
||||
function read(key) {
|
||||
return sessionStorage().getItem(key)
|
||||
}
|
||||
|
||||
function write(key, data) {
|
||||
return sessionStorage().setItem(key, data)
|
||||
}
|
||||
|
||||
function each(fn) {
|
||||
for (var i = sessionStorage().length - 1; i >= 0; i--) {
|
||||
var key = sessionStorage().key(i)
|
||||
fn(read(key), key)
|
||||
}
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
return sessionStorage().removeItem(key)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
return sessionStorage().clear()
|
||||
}
|
||||
Reference in New Issue
Block a user