diff --git a/README.md b/README.md
index 5647cb2..a69ab4a 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,83 @@
# $.store jQuery plugin #
-$.store
is a simple, yet easily extensible, plugin to persistently store data on the client side of things. It uses window.localStore
where available. Older Internet Explorers will use userData
. If all fails $.store
will save your data to window.name
.
+'$.store' is a simple, yet easily extensible, plugin to persistently store data on the client side of things. It uses 'window.localStore' where available. Older Internet Explorers will use 'userData'. If all fails '$.store' will save your data to 'window.name'.
-*Note*: The windowName
will only do JSON serialization. windowName
is not persistent in the sense of making it accross a closed browser window. If you need that ability you should check $.storage.driver.scope == "browser"
.
+*Note*: The 'windowName' driver will only do JSON serialization. 'windowName' is not persistent in the sense of making it across a closed browser window. If you need that ability you should check '$.storage.driver.scope == "browser"'.
## Usage ##
-
-//initialize
-$.storage = new $.store();
+ //initialize
+ $.storage = new $.store();
+
+ // save a value
+ $.storage.set( key, value );
+
+ // read a value
+ $.storage.get( key );
+
+ // deletes a value
+ $.storage.del( key );
+
+ // delete all values
+ $.storage.flush();
-// save a value
-$.storage.set( key, value );
+ // get the number of stored entries
+ $.storage.length();
+
+ // get a key by index (order is not guaranteed, use for iterating through keys)
+ $.storage.key( index );
+
+## Adding Serializers ##
-// read a value
-$.storage.get( key );
+You can easily add your own serializers to the stack. Make sure to add them before initializing the '$.store'.
-// deletes a value
-$.storage.del( key );
+*Note:* Serializers do not apply to the 'windowName' storage driver.
-// delete all values
-$.storage.flush();
-
+ $.store.serializers.yaddayadda = {
+ ident: "$.store.serializers.yaddayadda",
+ init: function( encoders, decoders )
+ {
+ // register your serializer with en/decoder stack
+ encoders.unshift( "yaddayadda" );
+ decoders.push( "yaddayadda" );
+ },
+
+ isYaddaYadda: function( value )
+ {
+ // determine if value should be processed by this serializer
+ return true;
+ },
+
+ encode: function( value )
+ {
+ // check if the value can be encoded
+ if( !value || value._serialized || !this.isYaddaYadda( value ) )
+ return value;
+
+ // prepare serialized-data-wrapper
+ var _value = { _serialized: this.ident, value: value };
+
+ // work your magic
+ _value.value = "serializedVersionOf data";
+
+ return value;
+ },
+
+ decode: function( value )
+ {
+ // check if the value can be decoded
+ if( !value || !value._serialized || value._serialized != this.ident )
+ return value;
+
+ // work your magic
+ value.value = "unserializedVersionOf data";
+
+ return this.isYaddaYadda( value.value ) ? value.value : undefined;
+ }
+ };
## License ##
-$.store is published under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
\ No newline at end of file
+'$.store' is published under the [MIT license][].
+
+[MIT license]: http://www.opensource.org/licenses/mit-license.php
\ No newline at end of file
diff --git a/index.html b/index.html
index d11b903..713206b 100644
--- a/index.html
+++ b/index.html
@@ -60,23 +60,17 @@
document.write( 'Initialized $.storage with driver ' + $.storage.driver.ident + '
' ); -
- $.store
is a simple, yet easily extensible, plugin to persistently store data on the client side of things.
- It uses window.localStore
where available. Older Internet Explorers will use userData
.
- If all fails $.store
will save your data to window.name
.
-
- Note: The windowName
will only do JSON serialization. windowName
- is not persistent in the sense of making it accross a closed browser window. If you need
- that ability you should check $.storage.driver.scope == "browser"
.
-
//initialize ++ +$.store jQuery plugin
+ ++ +
$.store
is a simple, yet easily extensible, plugin to persistently store data on the client side of things. It useswindow.localStore
where available. Older Internet Explorers will useuserData
. If all fails$.store
will save your data towindow.name
.The optional
+ +cookie
driver requires the$.cookie
plugin.Note: The
+ +windowName
driver will only do JSON serialization.windowName
is not persistent in the sense of making it across a closed browser window. If you need that ability you should check$.storage.driver.scope == "browser"
.Usage
+ +- -//initialize $.storage = new $.store(); // save a value @@ -89,16 +83,16 @@
Usage
$.storage.del( key ); // delete all values -$.storage.flush();Adding Serializers
- -- You can easily add your own serializers to the stack. - Make sure to add them before initializing the
-$.store
. - Note: Serializers do not apply to thewindowName
storage driver. -$.store.serializers.yaddayadda = { +$.storage.flush(); ++ +Adding Serializers
+ +You can easily add your own serializers to the stack. Make sure to add them before initializing the
+ +$.store
.Note: Serializers do not apply to the
+ +windowName
storage driver.+}; +$.store.serializers.yaddayadda = { ident: "$.store.serializers.yaddayadda", init: function( encoders, decoders ) { @@ -139,8 +133,12 @@
Adding Serializers
return this.isYaddaYadda( value.value ) ? value.value : undefined; } -};
$.store
is published under the MIT license.