]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/generic.js
added default to disable etag caching in mail objects
[scalable-opengroupware.org] / UI / WebServerResources / generic.js
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 /* some generic JavaScript code for SOGo */
22
23 // TODO: replace things with Prototype where applicable
24
25 /* generic stuff */
26
27 function ml_stripActionInURL(url) {
28   if (url[url.length - 1] != '/') {
29     var i;
30     
31     i = url.lastIndexOf("/");
32     if (i != -1) url = url.substring(0, i);
33   }
34   if (url[url.length - 1] != '/') // ensure trailing slash
35     url = url + "/";
36   return url;
37 }
38
39 /* emails */
40
41 var uixEmailUsr = 
42   "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
43 var uixEmailDomain = 
44   "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
45 var uixEmailRegex = new RegExp("^"+uixEmailUsr+"\@"+uixEmailDomain+"$");
46
47 /* escaping */
48
49 function escapeHTML(s) {
50         s = s.replace(/&/g, "&");
51         s = s.replace(/</g, "&lt;");
52         s = s.replace(/>/g, "&gt;");
53         s = s.replace(/"/g, "&quot;");
54         return s;
55 }
56 function unescapeHTML(s) {
57         s = s.replace(/&lt;/g, "<");
58         s = s.replace(/&gt;/g, ">");
59         s = s.replace(/&quot;/g, '"');
60         s = s.replace(/&amp;/g, "&");
61         return s;
62 }
63
64 function createHTTPClient() {
65   // http://developer.apple.com/internet/webcontent/xmlhttpreq.html
66   if (typeof XMLHttpRequest != "undefined")
67     return new XMLHttpRequest();
68   
69   try { return new ActiveXObject("Msxml2.XMLHTTP"); } 
70   catch (e) { }
71   try { return new ActiveXObject("Microsoft.XMLHTTP"); } 
72   catch (e) { }
73   return null;
74 }
75
76 function resetSelection(win) {
77   var t = "";
78   if (win && win.getSelection) {
79     t = win.getSelection().toString();
80     win.getSelection().removeAllRanges();
81   }
82   return t;
83 }
84
85 function refreshOpener() {
86   if (window.opener && !window.opener.closed) {
87     window.opener.location.reload();
88   }
89 }
90
91 /* query string */
92
93 function parseQueryString() {
94   var queryArray, queryDict
95   var key, value, s, idx;
96   queryDict.length = 0;
97   
98   queryDict  = new Array();
99   queryArray = location.search.substr(1).split('&');
100   for (var i in queryArray) {
101     if (!queryArray[i]) continue ;
102     s   = queryArray[i];
103     idx = s.indexOf("=");
104     if (idx == -1) {
105       key   = s;
106       value = "";
107     }
108     else {
109       key   = s.substr(0, idx);
110       value = unescape(s.substr(idx + 1));
111     }
112     
113     if (typeof queryDict[key] == 'undefined')
114       queryDict.length++;
115     
116     queryDict[key] = value;
117   }
118   return queryDict;
119 }
120
121 function generateQueryString(queryDict) {
122   var s = "";
123   for (var key in queryDict) {
124     if (s.length == 0)
125       s = "?";
126     else
127       s = s + "&";
128     s = s + key + "=" + escape(queryDict[key]);
129   }
130   return s;
131 }
132
133 function getQueryParaArray(s) {
134   if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
135   return s.split("&");
136 }
137 function getQueryParaValue(s, name) {
138   var t;
139   
140   t = getQueryParaArray(s);
141   for (var i = 0; i < t.length; i++) {
142     var s = t[i];
143     
144     if (s.indexOf(name) != 0)
145       continue;
146     
147     s = s.substr(name.length, s.length - name.length);
148     return decodeURIComponent(s);
149   }
150   return null;
151 }
152
153 /* opener callback */
154
155 function triggerOpenerCallback() {
156   /* this code has some issue if the folder has no proper trailing slash! */
157   if (window.opener && !window.opener.closed) {
158     var t, cburl;
159     
160     t = getQueryParaValue(window.location.search, "openerurl=");
161     cburl = window.opener.location.href;
162     if (cburl[cburl.length - 1] != "/") {
163       cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
164     }
165     cburl = cburl + t;
166     window.opener.location.href = cburl;
167   }
168 }