f18c764ffa
Monotone-Revision: 9054022ef1ca8aeba6e34842d27d9b94ce002b89 Monotone-Author: dev-unix.inverse.qc.ca Monotone-Date: 2006-06-15T19:34:10 Monotone-Branch: ca.inverse.sogo
169 lines
4.2 KiB
JavaScript
169 lines
4.2 KiB
JavaScript
/*
|
|
Copyright (C) 2005 SKYRIX Software AG
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
later version.
|
|
|
|
OGo 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 Lesser General Public
|
|
License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
02111-1307, USA.
|
|
*/
|
|
/* some generic JavaScript code for SOGo */
|
|
|
|
// TODO: replace things with Prototype where applicable
|
|
|
|
/* generic stuff */
|
|
|
|
function ml_stripActionInURL(url) {
|
|
if (url[url.length - 1] != '/') {
|
|
var i;
|
|
|
|
i = url.lastIndexOf("/");
|
|
if (i != -1) url = url.substring(0, i);
|
|
}
|
|
if (url[url.length - 1] != '/') // ensure trailing slash
|
|
url = url + "/";
|
|
return url;
|
|
}
|
|
|
|
/* emails */
|
|
|
|
var uixEmailUsr =
|
|
"([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
|
|
var uixEmailDomain =
|
|
"([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
|
|
var uixEmailRegex = new RegExp("^"+uixEmailUsr+"\@"+uixEmailDomain+"$");
|
|
|
|
/* escaping */
|
|
|
|
function escapeHTML(s) {
|
|
s = s.replace(/&/g, "&");
|
|
s = s.replace(/</g, "<");
|
|
s = s.replace(/>/g, ">");
|
|
s = s.replace(/"/g, """);
|
|
return s;
|
|
}
|
|
function unescapeHTML(s) {
|
|
s = s.replace(/</g, "<");
|
|
s = s.replace(/>/g, ">");
|
|
s = s.replace(/"/g, '"');
|
|
s = s.replace(/&/g, "&");
|
|
return s;
|
|
}
|
|
|
|
function createHTTPClient() {
|
|
// http://developer.apple.com/internet/webcontent/xmlhttpreq.html
|
|
if (typeof XMLHttpRequest != "undefined")
|
|
return new XMLHttpRequest();
|
|
|
|
try { return new ActiveXObject("Msxml2.XMLHTTP"); }
|
|
catch (e) { }
|
|
try { return new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
catch (e) { }
|
|
return null;
|
|
}
|
|
|
|
function resetSelection(win) {
|
|
var t = "";
|
|
if (win && win.getSelection) {
|
|
t = win.getSelection().toString();
|
|
win.getSelection().removeAllRanges();
|
|
}
|
|
return t;
|
|
}
|
|
|
|
function refreshOpener() {
|
|
if (window.opener && !window.opener.closed) {
|
|
window.opener.location.reload();
|
|
}
|
|
}
|
|
|
|
/* query string */
|
|
|
|
function parseQueryString() {
|
|
var queryArray, queryDict
|
|
var key, value, s, idx;
|
|
queryDict.length = 0;
|
|
|
|
queryDict = new Array();
|
|
queryArray = location.search.substr(1).split('&');
|
|
for (var i in queryArray) {
|
|
if (!queryArray[i]) continue ;
|
|
s = queryArray[i];
|
|
idx = s.indexOf("=");
|
|
if (idx == -1) {
|
|
key = s;
|
|
value = "";
|
|
}
|
|
else {
|
|
key = s.substr(0, idx);
|
|
value = unescape(s.substr(idx + 1));
|
|
}
|
|
|
|
if (typeof queryDict[key] == 'undefined')
|
|
queryDict.length++;
|
|
|
|
queryDict[key] = value;
|
|
}
|
|
return queryDict;
|
|
}
|
|
|
|
function generateQueryString(queryDict) {
|
|
var s = "";
|
|
for (var key in queryDict) {
|
|
if (s.length == 0)
|
|
s = "?";
|
|
else
|
|
s = s + "&";
|
|
s = s + key + "=" + escape(queryDict[key]);
|
|
}
|
|
return s;
|
|
}
|
|
|
|
function getQueryParaArray(s) {
|
|
if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
|
|
return s.split("&");
|
|
}
|
|
function getQueryParaValue(s, name) {
|
|
var t;
|
|
|
|
t = getQueryParaArray(s);
|
|
for (var i = 0; i < t.length; i++) {
|
|
var s = t[i];
|
|
|
|
if (s.indexOf(name) != 0)
|
|
continue;
|
|
|
|
s = s.substr(name.length, s.length - name.length);
|
|
return decodeURIComponent(s);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* opener callback */
|
|
|
|
function triggerOpenerCallback() {
|
|
/* this code has some issue if the folder has no proper trailing slash! */
|
|
if (window.opener && !window.opener.closed) {
|
|
var t, cburl;
|
|
|
|
t = getQueryParaValue(window.location.search, "openerurl=");
|
|
cburl = window.opener.location.href;
|
|
if (cburl[cburl.length - 1] != "/") {
|
|
cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
|
|
}
|
|
cburl = cburl + t;
|
|
window.opener.location.href = cburl;
|
|
}
|
|
}
|