[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/template/lib/mootools/more/Utilities/ -> Hash.Cookie.js (source)

   1  /*
   2  ---
   3  
   4  script: Hash.Cookie.js
   5  
   6  name: Hash.Cookie
   7  
   8  description: Class for creating, reading, and deleting Cookies in JSON format.
   9  
  10  license: MIT-style license
  11  
  12  authors:
  13    - Valerio Proietti
  14    - Aaron Newton
  15  
  16  requires:
  17    - Core/Cookie
  18    - Core/JSON
  19    - /MooTools.More
  20  
  21  provides: [Hash.Cookie]
  22  
  23  ...
  24  */
  25  
  26  Hash.Cookie = new Class({
  27  
  28      Extends: Cookie,
  29  
  30      options: {
  31          autoSave: true
  32      },
  33  
  34      initialize: function(name, options){
  35          this.parent(name, options);
  36          this.load();
  37      },
  38  
  39      save: function(){
  40          var value = JSON.encode(this.hash);
  41          if (!value || value.length > 4096) return false; //cookie would be truncated!
  42          if (value == '{}') this.dispose();
  43          else this.write(value);
  44          return true;
  45      },
  46  
  47      load: function(){
  48          this.hash = new Hash(JSON.decode(this.read(), true));
  49          return this;
  50      }
  51  
  52  });
  53  
  54  Hash.each(Hash.prototype, function(method, name){
  55      if (typeof method == 'function') Hash.Cookie.implement(name, function(){
  56          var value = method.apply(this.hash, arguments);
  57          if (this.options.autoSave) this.save();
  58          return value;
  59      });
  60  });


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7