Update of /cvsroot/dynapi/dynapi3x/src/util
In directory sc8-pr-cvs1:/tmp/cvs-serv6593/src/util

Modified Files:
        cookie.js 
Log Message:
updated/added by raymond

Index: cookie.js
===================================================================
RCS file: /cvsroot/dynapi/dynapi3x/src/util/cookie.js,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** cookie.js   10 Feb 2003 22:35:59 -0000      1.1.1.1
--- cookie.js   26 Mar 2003 02:22:31 -0000      1.2
***************
*** 10,15 ****
  
                var c = new Cookie('mycookieset');
!               c.set('name','MyName');  // re-saves cookie each time a value is added
!               c.add('array',[1,2,3]);
                
                var c = new Cookie('mycookieset');  // auto-retrieves saved cookie 
object
--- 10,14 ----
  
                var c = new Cookie('mycookieset');
!               c.add('array',[1,2,3]); // re-saves cookie each time a value is added
                
                var c = new Cookie('mycookieset');  // auto-retrieves saved cookie 
object
***************
*** 21,32 ****
  */
  
! function Cookie(name) {
!       
        this.DynObject = DynObject;
        this.DynObject();
        
-       this.name = name;
        this.data = {};
        this.exists = false;
        var c = dynapi.functions.getCookie(this.name);
        if (c) {
--- 20,32 ----
  */
  
! 
! function Cookie(name,pDType) {
        this.DynObject = DynObject;
        this.DynObject();
        
        this.data = {};
+       this.name = name;
        this.exists = false;
+       this._pdt=pDType;
        var c = dynapi.functions.getCookie(this.name);
        if (c) {
***************
*** 34,41 ****
                var a = c.split(',');
                var x,n,v;
!               for (var i=0;i<a.length;a++) {
                        x = a[i].split('=');
                        n = x[0];
!                       v = x[1];
                        if (n && v) this.data[n] = v;
                }
--- 34,41 ----
                var a = c.split(',');
                var x,n,v;
!               for (var i=0;i<a.length;i++) {
                        x = a[i].split('=');
                        n = x[0];
!                       v = Cookie.decode(x[1]);
                        if (n && v) this.data[n] = v;
                }
***************
*** 44,48 ****
        }
        else this._save();
! }
  var p = dynapi.setPrototype('Cookie','DynObject');
  p.get = function(name) {
--- 44,113 ----
        }
        else this._save();
! };
! // to-do: replace escape(),unescape() with better encoding functions
! Cookie.decode = function(t,_lvl){
!       var dt = (t+'').substring(0,2);
!       if(isNaN(_lvl)) _lvl=0; else _lvl++;
!       if(dt=='a[') {                  //array
!               t=t.substring(2,t.length-1);
!               t=t.split('\\'+_lvl);
!               for(var i=0;i<t.length;i++) t[i]=Cookie.decode(t[i],_lvl);
!       }
!       else if(dt=='o[') {     //object
!               var a,n,v;
!               t=t.substring(2,t.length-1);
!               a=t.split('\\'+_lvl);
!               t={};
!               for(var i=0;i<a.length;i++) {
!                       n=a[i].substring(0,a[i].indexOf(':'));
!                       if(n) v=a[i].substring(n.length+1);
!                       else v=null;
!                       t[n]=Cookie.decode(v,_lvl);
!               }
!       }
!       else if(dt=='n[') {     //number:float, integer
!               t=parseFloat(t.substring(2,t.length-1));
!       }
!       else if(dt=='d[') {     //date
!               t=new Date(unescape(t.substring(2,t.length-1)));
!       }
!       else if(dt=='b[') {     //boolean
!               t=(t.substring(2,t.length-1)=="1")? true:false;
!       }
!       else if(dt=='u[') {     //null
!               t=null; 
!       }
!       else{                           //string
!               t=unescape(t);
!       }
!       return t;
! };
! // to-do: replace escape(),unescape() with better encoding functions
! Cookie.encode = function(t,pDType,_lvl){
!       if (!pDType) t=escape(t);
!       if (t==null) t='u[]';
!       else if(typeof(t)=='number') t='n['+t+']';
!       else if(typeof(t)=='boolean') t='b['+((t)? 1:0)+']';
!       else if(typeof(t)!='object') t=escape(t);
!       else {
!               if(isNaN(_lvl)) _lvl=0; else _lvl++;
!               if(t.constructor==Date) t='d['+escape(t)+']';
!               else if(t.constructor==Array){  
!                       //encode array = a[n1\0n2...\0nN]
!                       var a=[];
!                       for(var i=0;i<t.length;i++) a[i]=Cookie.encode(t[i],pDType);   
                 
!                       t='a['+a.join('\\'+_lvl)+']';
!               }
!               else {                                                  
!                       //encode object = 
o[name1:value1\0name2:value2...\0nameN:valueN]
!                       var a=[];
!                       for(var i in t){
!                               a[a.length]=(i+':'+Cookie.encode(t[i],pDType,_lvl));
!                       }
!                       t='o['+a.join('\\'+_lvl)+']';
!               }
!       }
!       return t;
! };
  var p = dynapi.setPrototype('Cookie','DynObject');
  p.get = function(name) {
***************
*** 61,64 ****
--- 126,133 ----
        this._save();
  };
+ p.removeAll = function(){
+       this.data = {};
+       this._save();
+ };
  p.setExpires = function(days) {
        this.expires = days;
***************
*** 71,75 ****
        for (var i in this.data) {
                var v = this.data[i];
!               if (v) s += i + '=' + escape(v) + ',';
        }
        s = s.substring(0,s.length-1);
--- 140,144 ----
        for (var i in this.data) {
                var v = this.data[i];
!               if (v) s += i + '=' + Cookie.encode(v,this._pdt) + ',';
        }
        s = s.substring(0,s.length-1);
***************
*** 91,97 ****
  dynapi.functions.getCookie = function(name) {
        var nameEQ = name+"=";
!       var ca = dynapi.frame.document.cookie.split(';');
        for(var i=0;i<ca.length;i++) {
!               var c=ca[i];
                while (c.charAt(0)==' ') c=c.substring(1,c.length);
                if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
--- 160,166 ----
  dynapi.functions.getCookie = function(name) {
        var nameEQ = name+"=";
!       var c,ca = dynapi.frame.document.cookie.split(';');
        for(var i=0;i<ca.length;i++) {
!               c=ca[i];
                while (c.charAt(0)==' ') c=c.substring(1,c.length);
                if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);



-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: 
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! 
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
Dynapi-CVS mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dynapi-cvs

Reply via email to