store.js
========
store.js exposes a simple API for cross browser local storage
```js
// Store 'marcus' at 'username'
store.set('username', 'marcus')
// Get 'username'
store.get('username')
// Remove 'username'
store.remove('username')
// Clear all keys
store.clear()
// Store an object literal - store.js uses JSON.stringify under the hood
store.set('user', { name: 'marcus', likes: 'javascript' })
// Get the stored object - store.js uses JSON.parse under the hood
var user = store.get('user')
alert(user.name + ' likes ' + user.likes)
// Get all stored values
store.getAll().user.name == 'marcus'
// Loop over all stored values
store.forEach(function(key, val) {
console.log(key, '==', val)
})
```
How does it work?
------------------
store.js uses localStorage when available, and falls back on the userData behavior in IE6 and IE7. No flash to slow down your page load. No cookies to fatten your network requests.
store.js depends on JSON for serialization to disk.
Installation
------------
Just grab [store.min.js] or [store+json2.min.js] and include them with a script tag.
`store.enabled` flag
--------------------
If your product depends on store.js, you must check the `store.enabled` flag first:
```html
<script src="store.min.js"></script>
<script>
init()
function init() {
if (!store.enabled) {
alert('Local storage is not supported by your browser. Please disable "Private Mode", or upgrade to a modern browser.')
return
}
var user = store.get('user')
// ... and so on ...
}
</script>
```
LocalStorage may sometimes appear to be available but throw an error when used. An example is Safari's private browsing mode. Other browsers allow the user to temporarily disable localStorage. Store.js detects these conditions and sets the `store.enabled` flag appropriately.
Screencast
-----------
[Introductory Screencast to Store.js](http://javascriptplayground.com/blog/2012/06/javascript-local-storage-store-js-tutorial) by Jack Franklin.
Contributors & Forks
--------------------
Contributors: https://github.com/marcuswestin/store.js/graphs/contributors
Forks: https://github.com/marcuswestin/store.js/network/members
In node.js
----------
store.js works as expected in node.js, assuming that global.localStorage has been set:
```
global.localStorage = require('localStorage')
var store = require('./store')
store.set('foo', 1)
console.log(store.get('foo'))
```
Supported browsers
------------------
- Tested in iOS 4
- Tested in iOS 5
- Tested in iOS 6
- Tested in Firefox 3.5
- Tested in Firefox 3.6
- Tested in Firefox 4.0+
- Support dropped for Firefox < 3.5 (see notes below)
- Tested in Chrome 5
- Tested in Chrome 6
- Tested in Chrome 7
- Tested in Chrome 8
- Tested in Chrome 10
- Tested in Chrome 11+
- Tested in Safari 4
- Tested in Safari 5
- Tested in IE6
- Tested in IE7
- Tested in IE8
- Tested in IE9
- Tested in IE10
- Tested in Opera 10
- Tested in Opera 11
- Tested in Opera 12
- Tested in Node.js v0.10.4 (with https://github.com/coolaj86/node-localStorage 1.0.2)
*Private mode* Store.js may not work while browsing in private mode. This is as it should be. Check the `store.enabled` flag before relying on store.js.
*Saucelabs.com rocks* Extensive browser testing of store.js is possible thanks to Saucelabs.com. Check them out, they're awesome.
*Firefox 3.0 & 2.0:* Support for FF 2 & 3 was dropped in v1.3.6. If you require support for ancient versions of FF, use v1.3.5 of store.js.
*Important note:* In IE6 and IE7, many special characters are not allowed in the keys used to store any key/value pair. With [@mferretti](https://github.com/mferretti)'s help, there's a suitable workaround which replaces most forbidden characters with "___".
Storage limits
--------------
- IE6 & IE7: 1MB total, but 128kb per "path" or "document" (see http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx)
- See http://dev-test.nemikor.com/web-storage/support-test/ for a list of limits per browser
Unsupported browsers
-------------------
- Firefox 1.0: no means (beside cookies and flash)
- Safari 2: no means (beside cookies and flash)
- Safari 3: no synchronous api (has asynch sqlite api, but store.js is synch)
- Opera 9: don't know if there is synchronous api for storing data locally
- Firefox 1.5: don't know if there is synchronous api for storing data locally
- Microsoft IIS & IE7: With meta tag & "charset=iso-8859-1", things stop working. See issue #47.
Some notes on serialization
---------------------------
localStorage, when used without store.js, calls toString on all stored values. This means that you can't conveniently store and retrieve numbers, objects or arrays:
```js
localStorage.myage = 24
localStorage.myage !== 24
localStorage.myage === '24'
localStorage.user = { name: 'marcus', likes: 'javascript' }
localStorage.user === "[object Object]"
localStorage.tags = ['javascript', 'localStorage', 'store.js']
localStorage.tags.length === 32
localStorage.tags === "javascript,localStorage,store.js"
```
What we want (and get with store.js) is
```js
store.set('myage', 24)
store.get('myage') === 24
store.set('user', { name: 'marcus', likes: 'javascript' })
alert("Hi my name is " + store.get('user').name + "!")
store.set('tags', ['javascript', 'localStorage', 'store.js'])
alert("We've got " + store.get('tags').length + " tags here")
```
The native serialization engine of javascript is JSON. Rather than leaving it up to you to serialize and deserialize your values, store.js uses JSON.stringify() and JSON.parse() on each call to store.set() and store.get(), respectively.
Some browsers do not have native support for JSON. For those browsers you should include [JSON.js](non-minified copy is included in this repo).
No sessionStorage/auto-expiration?
----------------------------------
No. I believe there is no way to provide sessionStorage semantics cross browser. However, it is trivial to expire values on read on top of store.js:
```js
var storeWithExpiration = {
set: function(key, val, exp) {
store.set(key, { val:val, exp:exp, time:new Date().getTime() })
},
get: function(key) {
var info = store.get(key)
if (!info) { return null }
if (new Date().getTime() - info.time > info.exp) { return null }
return info.val
}
}
storeWithExpiration.set('foo', 'bar', 1000)
setTimeout(function() { console.log(storeWithExpiration.get('foo')) }, 500) // -> "bar"
setTimeout(function() { console.log(storeWithExpiration.get('foo')) }, 1500) // -> null
```
Testing
-------
For a browser: Go to http://marcuswestin.github.io/store.js/test.html to test the latest version of store.js.
For a browser, locally: do `npm install node-static && ./node_modules/node-static/bin/cli.js` and go to http://localhost:8080
(Note that test.html must be served over http:// or https://. This is because localStore does not work in some browsers when using the file:// protocol.)
For Nodejs: do `npm install . localStorage && node test-node.js`
[JSON.js]: http://www.json.org/json2.js
[store.min.js]: https://raw.github.com/marcuswestin/store.js/master/store.min.js
[store+json2.min.js]: https://raw.github.com/marcuswestin/store.js/master/store+json2.min.js
没有合适的资源?快使用搜索试试~ 我知道了~
一个基于WebRTC的视频网站, 实现面对面看同一部电影
共411个文件
js:191个
less:76个
png:22个
需积分: 5 0 下载量 77 浏览量
2023-08-05
10:20:45
上传
评论
收藏 3.22MB ZIP 举报
温馨提示
一个基于WebRTC的视频网站, 实现面对面看同一部电影。 采用前端采用 React.js + FLUX 框架,服务端采用 Node.js。
资源推荐
资源详情
资源评论
收起资源包目录
一个基于WebRTC的视频网站, 实现面对面看同一部电影 (411个子文件)
.bowerrc 32B
Changelog 2KB
bootstrap.css 138KB
bootstrap.min.css 115KB
bootstrap.min.css 115KB
bootstrap.min.css 115KB
bootstrap-theme.css 22KB
bootstrap-theme.min.css 19KB
login.css 8KB
login.css 8KB
about.css 4KB
about.css 4KB
404.css 3KB
404.css 3KB
reset.css 1KB
reset.css 1KB
mainNavigator.css 998B
mainNavigator.css 998B
portal.css 889B
portal.css 889B
angular-csp.css 263B
style.css 110B
style.css 110B
.csslintrc 456B
.donotdelete 0B
.donotdelete 0B
.donotdelete 0B
.donotdelete 0B
.donotdelete 0B
.DS_Store 6KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
.gitignore 2KB
angular.min.js.gzip 49KB
mainNavigator.html 200B
profile.html 159B
setting.html 119B
movies.html 117B
chat.html 113B
activity.html 67B
favicon.ico 31KB
login.jade 5KB
about.jade 2KB
base.jade 1KB
index.jade 847B
404.jade 526B
upload.jade 217B
error.jade 92B
about.jpeg 679KB
login.jpg 664KB
p2.jpg 51KB
cover_1.jpg 40KB
bot-bar.jpg 31KB
cover_2.jpg 19KB
lg-bot-bg.jpg 16KB
lg-nav-hover.jpg 670B
angular.js 938KB
jquery.js 242KB
angular.min.js 123KB
shim.js 108KB
ReactRouter.js 100KB
jquery-1.9.1.min.js 90KB
peer.js 85KB
jquery.min.js 82KB
bootstrap.js 66KB
sizzle.js 58KB
bootstrap.min.js 35KB
bootstrap.min.js 35KB
angular-route.js 35KB
ReactRouter.min.js 33KB
shim.min.js 31KB
event.js 24KB
ajax.js 21KB
sizzle.min.js 18KB
json.js 17KB
createRouter.js 17KB
effects.js 17KB
tooltip.js 15KB
manipulation.js 15KB
Gruntfile.js 14KB
css.js 12KB
core.js 12KB
modernizr.min.js 11KB
modal.js 10KB
Route.js 8KB
carousel.js 7KB
store.js 6KB
bs-lessdoc-parser.js 6KB
collapse.js 6KB
offset.js 5KB
callbacks.js 5KB
store+json2.min.js 5KB
users.js 5KB
data.js 5KB
Data.js 5KB
affix.js 5KB
Link.js 5KB
scrollspy.js 5KB
dropdown.js 5KB
共 411 条
- 1
- 2
- 3
- 4
- 5
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6732
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功