- MooTools -
- December 29th, 2008,
- 2 Responses
MooWindowSession
- 29 December
A few months back a guy named Thomas Frank figured out a clever way of carrying variables throughout a window session using window object's name property, which can hold a number of data bytes even if you navigate out of the site and come back.
What I did is a simplistic MooTools-based window session manager implementation.
The pretty cool thing about the library is the fact that the values of the session can be stored as simple strings of as objects, which makes it really easy for us to manage.
Storing a simple session
// init MooWindowSession var Session = new MooWindowSession(); // store a string Session.set("first", "first value"); // returns: "first value" Session.get()
Storing multiple session values
// init MooWindowSession var Session = new MooWindowSession(); // store an object Session.set({ first: "first value", second: "second value" }); // returns: {first: "first value", second: "second value"} Session.get() // returns: "first value" Session.get().first
Clearing the session
// init MooWindowSession var Session = new MooWindowSession(); // store an object Session.set({ first: "first value", second: "second value" }); // clear the session Session.remove() // returns: null Session.get()
- Example
- Get MooWindowSession (1.1Kb) – (latest from SVN)
- Documentation
- Requires mootools-1.2.0-core.js or newer
2 responses so far. Care to add one yourself?
-
Shaun January 3rd, 2009 at 14:18
This is a very good port to MooTools, well done.
I like to look and idea of this, but don’t know yet if I would use it in my CMS as I am using PHP Sessions. But I will store this script away as I might use it in a new drag ‘n’ drop shopping cart I am working on for a customer!
Thanks and keep up the good work.
-
Oskar Krawczyk January 3rd, 2009 at 16:45
Thanks! Also, not a port – Frank’s script is a whole huge library, when my version allows you to do the most common things – nothing less, nothing more.