Sha256: 8508247d4a701fb1f077916a0e7015342579e65e3ffd5d699ae9a52d0af7f93e

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

/*
---

script: Hash.Cookie.js

name: Hash.Cookie

description: Class for creating, reading, and deleting Cookies in JSON format.

license: MIT-style license

authors:
  - Valerio Proietti
  - Aaron Newton

requires:
  - Core/Cookie
  - Core/JSON
  - /MooTools.More
  - /Hash

provides: [Hash.Cookie]

...
*/

Hash.Cookie = new Class({

	Extends: Cookie,

	options: {
		autoSave: true
	},

	initialize: function(name, options){
		this.parent(name, options);
		this.load();
	},

	save: function(){
		var value = JSON.encode(this.hash);
		if (!value || value.length > 4096) return false; //cookie would be truncated!
		if (value == '{}') this.dispose();
		else this.write(value);
		return true;
	},

	load: function(){
		this.hash = new Hash(JSON.decode(this.read(), true));
		return this;
	}

});

Hash.each(Hash.prototype, function(method, name){
	if (typeof method == 'function') Hash.Cookie.implement(name, function(){
		var value = method.apply(this.hash, arguments);
		if (this.options.autoSave) this.save();
		return value;
	});
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1.5 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1.4 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1.3 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1.2 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1.1 Packages/mootools-more/Source/Utilities/Hash.Cookie.js
lsd_rails-0.1 Packages/mootools-more/Source/Utilities/Hash.Cookie.js