]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/WebServerResources/generic.js
8cb97c5b42ab71e1d9739dbd93d0ace16043f93a
[scalable-opengroupware.org] / SOGo / 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 /* generic stuff */
24
25 function ml_stripActionInURL(url) {
26   if (url[url.length - 1] != '/') {
27     var i;
28     
29     i = url.lastIndexOf("/");
30     if (i != -1) url = url.substring(0, i);
31   }
32   if (url[url.length - 1] != '/') // ensure trailing slash
33     url = url + "/";
34   return url;
35 }
36
37 function escapeHTML(s) {
38         s = s.replace(/&/g, "&");
39         s = s.replace(/</g, "&lt;");
40         s = s.replace(/>/g, "&gt;");
41         s = s.replace(/"/g, "&quot;");
42         return s;
43 }
44 function unescapeHTML(s) {
45         s = s.replace(/&lt;/g, "<");
46         s = s.replace(/&gt;/g, ">");
47         s = s.replace(/&quot;/g, '"');
48         s = s.replace(/&amp;/g, "&");
49         return s;
50 }
51
52 function createHTTPClient() {
53   // http://developer.apple.com/internet/webcontent/xmlhttpreq.html
54   if (typeof XMLHttpRequest != "undefined")
55     return new XMLHttpRequest();
56   
57   try { return new ActiveXObject("Msxml2.XMLHTTP"); } 
58   catch (e) { }
59   try { return new ActiveXObject("Microsoft.XMLHTTP"); } 
60   catch (e) { }
61   return null;
62 }
63
64 function resetSelection(win) {
65   var t = "";
66   if (win && win.getSelection) {
67     t = win.getSelection().toString();
68     win.getSelection().removeAllRanges();
69   }
70   return t;
71 }
72
73 function refreshOpener() {
74   if (window.opener && !window.opener.closed) {
75     window.opener.location.reload();
76   }
77 }
78
79 function getQueryParaArray(s) {
80   if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
81   return s.split("&");
82 }
83 function getQueryParaValue(s, name) {
84   var t;
85   
86   t = getQueryParaArray(s);
87   for (var i = 0; i < t.length; i++) {
88     var s = t[i];
89     
90     if (s.indexOf(name) != 0)
91       continue;
92     
93     s = s.substr(name.length, s.length - name.length);
94     return decodeURIComponent(s);
95   }
96   return null;
97 }
98
99 function triggerOpenerCallback() {
100   /* this code has some issue if the folder has no proper trailing slash! */
101   if (window.opener && !window.opener.closed) {
102     var t, cburl;
103     
104     t = getQueryParaValue(window.location.search, "openerurl=");
105     cburl = window.opener.location.href;
106     if (cburl[cburl.length - 1] != "/") {
107       cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
108     }
109     cburl = cburl + t;
110     window.opener.location.href = cburl;
111   }
112 }