From 96bbb17199b46f950641216411daa2f74a6e2f12 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Wed, 18 Apr 2012 08:19:33 +0200 Subject: [PATCH] cookie mgmt functions and url_append_args func facility added --- web/xynt/xynt-commons.js | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/web/xynt/xynt-commons.js b/web/xynt/xynt-commons.js index cb8076f..45b5c85 100644 --- a/web/xynt/xynt-commons.js +++ b/web/xynt/xynt-commons.js @@ -1,3 +1,5 @@ +var cookiepath = "/xynt/"; + function $(id) { return document.getElementById(id); } function getStyle(x,IEstyleProp, MozStyleProp) @@ -91,9 +93,80 @@ function getStyle(x,IEstyleProp, MozStyleProp) return y; } + + function doSomething(e) { if (!e) var e = window.event // handle event e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); +} + +/* + * GESTIONE DEI COOKIES + */ +function createCookie(name,value,hours,path) { + if (hours) { + var date = new Date(); + date.setTime(date.getTime()+(hours*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + } + else var expires = ""; + document.cookie = name+"="+value+expires+"; path="+path; +} + +function readCookie(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; +} + +function eraseCookie(name) { + createCookie(name,"",-1); +} + +function url_append_arg(url, name, value) +{ + var pos, sep, pref, rest; + + if ((pos = url.indexOf('?'+name+'=')) == -1) { + pos = url.indexOf('&'+name+'='); + } + if (pos == -1) { + if ((pos = url.indexOf('?')) != -1) + sep = '&'; + else + sep = '?'; + + return (url+sep+name+"="+encodeURIComponent(value)); + } + else { + pref = url.substring(0, pos+1); + rest = url.substring(pos+1); + // alert("rest: "+rest+" pos: "+pos); + if ((pos = rest.indexOf('&')) != -1) { + rest = rest.substring(pos); + } + else { + rest = ""; + } + return (pref+name+"="+encodeURIComponent(value)+rest); + } +} + +function url_append_args(url) +{ + var i, ret; + + ret = url; + for (i = 1 ; i < arguments.length-1 ; i+= 2) { + ret = url_append_arg(ret, arguments[i], arguments[i+1]); + } + + return (ret); } \ No newline at end of file -- 2.17.1