diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-14 14:39:35 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-14 14:39:35 +0000 |
| commit | 1efbabd9e03272f5ee71e048c4d4ef2a2e4880aa (patch) | |
| tree | 3d2cb016b6bd97c9bc7e9e3209a831fe0204f55b /frontends/php | |
| parent | 3273577ef09fe936c968074b9c7ef199ff122c70 (diff) | |
- improved js class "cookies" (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@4300 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/js/cookies.js | 104 |
1 files changed, 64 insertions, 40 deletions
diff --git a/frontends/php/js/cookies.js b/frontends/php/js/cookies.js index 5d1bdfbc..b080533f 100644 --- a/frontends/php/js/cookies.js +++ b/frontends/php/js/cookies.js @@ -1,40 +1,64 @@ -// JavaScript Document
-
-var cookie ={
-time : '',
-path : '/',
-
-create : function(name,value,time) {
- if((typeof(time) != 'undefined')) {
- var date = new Date();
- date.setTime(date.getTime()+time);
- var expires = "; expires="+date.toGMTString();
- document.cookie = name+"="+value+expires+'; path='+this.path;
- return;
- } else if(this.time != '') {
- var date = new Date();
- date.setTime(date.getTime()+this.time);
- var expires = "; expires="+date.toGMTString();
- document.cookie = name+"="+value+expires+'; path='+this.path;
- return;
- } else {
- document.cookie = name+"="+value;
- }
-},
-
-read : function(name) {
- var nameEQ = name + "=";
- var ca = 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);
- }
- return null;
-},
-
-erase : function(name) {
- this.create(name,"",-1);
-}
-
-}
\ No newline at end of file +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +// JavaScript Document + +var cookie ={ +init: function () { + var allCookies = document.cookie.split('; '); + for (var i=0;i<allCookies.length;i++) { + var cookiePair = allCookies[i].split('='); + this[cookiePair[0]] = cookiePair[1]; + } +}, + +create: function (name,value,days) { + if(days) { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + }else{ + var expires = ""; + } + + document.cookie = name+"="+value+expires+"; path=/"; + this[name] = value; +}, + +read : function(name){ + if(typeof(this[name]) != 'undefined'){ + return this[name]; + } else { + var nameEQ = name + "="; + var ca = 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 this[name] = c.substring(nameEQ.length,c.length); + } + } + return null; +}, + +erase: function (name) { + this.create(name,'',-1); + this[name] = undefined; +} + +} +cookie.init();
\ No newline at end of file |
