kis-js/docs/store.js.html

167 lines
3.5 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: modules/store.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: modules/store.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Store
*
* Wrapper for local / sessionstorage
*/
(function (undefined){
"use strict";
//Shortcuts for wrapper
var l = localStorage,
s = sessionStorage;
/**
* Wrapper for localstorage / sessionstorage data serialization.
* Each method has a boolean parameter, that when set as true switches the method
* to use sessionStorage rather than the default localStorage.
*
* @name store
* @namespace
* @memberOf $_
*/
var store = {
/**
* Retrieves and deserializes a value from localstorage,
* based on the specified key
*
* @param {string} key
* @param {bool} session
* @name get
* @memberOf $_.store
* @function
* @return {Object}
*/
get: function (key, sess)
{
var val = (sess) ? s.getItem(key) : l.getItem(key);
return JSON.parse(val);
},
/**
* Puts a value into localstorage at the specified key,
* and JSON-encodes the value if not a string
*
* @param {string} key
* @param {mixed} value
* @param {bool} session
* @name set
* @memberOf $_.store
* @function
*/
set: function (key, value, sess)
{
// Localstorage generally only accepts strings
value = JSON.stringify(value);
(sess) ? s.setItem(key, value) : l.setItem(key, value);
},
/**
* Removes the specified item from storage
*
* @param {string} key
* @param {bool} session
* @name remove
* @memberOf $_.store
* @function
*/
remove: function (key, sess)
{
(sess) ? s.removeItem(key) : l.removeItem(key);
},
/**
* Returns an object of all the raw values in storage
*
* @param {bool} session
* @name getAll
* @memberOf $_.store
* @function
* @return {Object}
*/
getAll: function (sess)
{
var i,
len,
data = {},
k,
o;
//Reference to session/localstorage
o = (sess) ? l : s;
len = o.length;
for (i = 0; i &lt; len; i++)
{
k = o.key(i);
data[k] = o.getItem(k);
}
return data;
},
/**
* Removes all values from the same domain storage
*
* @param {bool} session
* @name clear
* @memberOf $_.store
* @function
*/
clear: function(sess)
{
(sess) ? s.clear() : l.clear();
}
};
$_.ext('store', store);
}());</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Namespaces</h3><ul><li><a href="$_.html">$_</a></li><li><a href="$_.dom.html">dom</a></li><li><a href="$_.event.html">event</a></li><li><a href="$_.store.html">store</a></li></ul><h3>Global</h3><ul><li><a href="global.html#data[undefined]">data[undefined]</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Fri Sep 05 2014 11:56:00 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>