2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
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 */
|
|
|
|
|
2006-07-13 21:13:18 +02:00
|
|
|
logWindow = window.open('', 'logWindow',
|
|
|
|
'directories = no; location = no; menubar = no; resizable = no;'
|
|
|
|
+ 'scrollbars = yes; status = no; toolbar = no; width = 80em; height = 25em;');
|
|
|
|
logWindow.document.write('<html><head><title>JavaScript log</title></head>'
|
|
|
|
+ '<body style="font-family: monospace;'
|
|
|
|
+ 'font-size: 10pt;">'
|
|
|
|
+ '<div class="log" id="logArea"></div></body>'
|
|
|
|
+'</html>');
|
|
|
|
logWindow.resizeTo(640,480);
|
|
|
|
logArea = logWindow.document.getElementById('logArea');
|
|
|
|
logArea.innerHTML = '';
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
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+"$");
|
|
|
|
|
2006-07-11 20:11:54 +02:00
|
|
|
function sanitizeMailTo(dirtyMailTo) {
|
|
|
|
var email = "";
|
|
|
|
var name = "";
|
|
|
|
|
|
|
|
var emailre
|
|
|
|
= /([a-zA-Z0-9]+[a-zA-Z0-9\._-]+[a-zA-Z0-9]+@[a-zA-Z0-9]+[a-zA-Z0-9\._-]+[a-zA-Z0-9]+)/g;
|
|
|
|
if (emailre.test(dirtyMailTo)) {
|
|
|
|
emailre.exec(dirtyMailTo);
|
|
|
|
email = RegExp.$1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var namere = /(\w[\w\ _-]+)\ (<|<)/;
|
|
|
|
if (namere.test(dirtyMailTo)) {
|
|
|
|
namere.exec(dirtyMailTo);
|
|
|
|
name = RegExp.$1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var mailto = "";
|
|
|
|
if (name.length > 0)
|
|
|
|
mailto = name + ' <' + email + '>';
|
|
|
|
else
|
|
|
|
mailto = email;
|
|
|
|
|
|
|
|
return mailto;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* escaping */
|
|
|
|
|
|
|
|
function escapeHTML(s) {
|
|
|
|
s = s.replace(/&/g, "&");
|
|
|
|
s = s.replace(/</g, "<");
|
|
|
|
s = s.replace(/>/g, ">");
|
2006-07-11 20:11:54 +02:00
|
|
|
s = s.replace(/\"/g, """);
|
2006-06-15 21:34:10 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2006-07-07 23:27:12 +02:00
|
|
|
|
|
|
|
/* selection mechanism */
|
|
|
|
|
|
|
|
function selectNode(node) {
|
|
|
|
var classStr = '' + node.getAttribute('class');
|
|
|
|
|
|
|
|
position = classStr.indexOf('_selected', 0);
|
|
|
|
if (position < 0) {
|
|
|
|
classStr = classStr + ' _selected';
|
|
|
|
node.setAttribute('class', classStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function deselectNode(node) {
|
|
|
|
var classStr = '' + node.getAttribute('class');
|
|
|
|
|
|
|
|
position = classStr.indexOf('_selected', 0);
|
|
|
|
while (position > -1) {
|
|
|
|
classStr1 = classStr.substring(0, position);
|
|
|
|
classStr2 = classStr.substring(position + 10, classStr.length);
|
|
|
|
classStr = classStr1 + classStr2;
|
|
|
|
position = classStr.indexOf('_selected', 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
node.setAttribute('class', classStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deselectAll(parent) {
|
|
|
|
for (var i = 0; i < parent.childNodes.length; i++) {
|
|
|
|
var node = parent.childNodes.item(i);
|
|
|
|
if (node.nodeType == 1) {
|
|
|
|
deselectNode(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isNodeSelected(node) {
|
|
|
|
var classStr = '' + node.getAttribute('class');
|
|
|
|
var position = classStr.indexOf('_selected', 0);
|
|
|
|
|
|
|
|
return (position > -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptMultiSelect(node) {
|
|
|
|
var accept = ('' + node.getAttribute('multiselect')).toLowerCase();
|
|
|
|
|
|
|
|
return (accept == 'yes');
|
|
|
|
}
|
|
|
|
|
2006-07-11 20:11:54 +02:00
|
|
|
function getSelectedNodes(parentNode) {
|
2006-07-07 23:27:12 +02:00
|
|
|
var selArray = new Array();
|
|
|
|
|
|
|
|
for (var i = 0; i < parentNode.childNodes.length; i++) {
|
|
|
|
node = parentNode.childNodes.item(i);
|
|
|
|
if (node.nodeType == 1
|
|
|
|
&& isNodeSelected(node)) {
|
|
|
|
selArray.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selArray.join('|');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRowClick(node, event) {
|
2006-07-12 00:29:19 +02:00
|
|
|
// var text = document.getElementById('list');
|
|
|
|
// text.innerHTML = '';
|
2006-07-07 23:27:12 +02:00
|
|
|
|
2006-07-11 20:11:54 +02:00
|
|
|
var startSelection = getSelectedNodes(node.parentNode);
|
2006-07-07 23:27:12 +02:00
|
|
|
if (event.shiftKey == 1
|
2006-07-12 00:29:19 +02:00
|
|
|
&& (acceptMultiSelect(node.parentNode)
|
|
|
|
|| acceptMultiSelect(node.parentNode.parentNode))) {
|
2006-07-07 23:27:12 +02:00
|
|
|
if (isNodeSelected(node) == true) {
|
|
|
|
deselectNode(node);
|
|
|
|
} else {
|
|
|
|
selectNode(node);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deselectAll(node.parentNode);
|
|
|
|
selectNode(node);
|
|
|
|
}
|
2006-07-11 20:11:54 +02:00
|
|
|
if (startSelection != getSelectedNodes(node.parentNode)) {
|
2006-07-07 23:27:12 +02:00
|
|
|
var code = '' + node.parentNode.getAttribute('onselectionchange');
|
|
|
|
if (code.length > 0) {
|
|
|
|
node.eval(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-11 20:11:54 +02:00
|
|
|
|
|
|
|
/* popup menus */
|
|
|
|
|
2006-07-13 21:13:18 +02:00
|
|
|
var bodyOnClick = "";
|
|
|
|
var acceptClick = false;
|
|
|
|
var menuClickNode = null;
|
|
|
|
var currentSubmenu = null;
|
2006-07-11 20:11:54 +02:00
|
|
|
|
|
|
|
function onMenuClick(node, event, menuId)
|
|
|
|
{
|
|
|
|
event.cancelBubble = true;
|
|
|
|
event.returnValue = false;
|
|
|
|
|
|
|
|
if (event.button == 1)
|
|
|
|
acceptClick = false;
|
|
|
|
bodyOnClick = "" + document.body.getAttribute("onclick");
|
|
|
|
document.body.setAttribute("onclick", "onBodyClick('" + menuId + "'); return false;");
|
2006-07-13 21:13:18 +02:00
|
|
|
var popup = document.getElementById(menuId);
|
|
|
|
hideMenu(popup);
|
|
|
|
popup.style.top = event.pageY + "px";
|
|
|
|
popup.style.left = event.pageX + "px";
|
|
|
|
popup.style.visibility = "visible";
|
2006-07-11 20:11:54 +02:00
|
|
|
menuClickNode = node;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBodyClick(menuId)
|
|
|
|
{
|
|
|
|
if (!acceptClick)
|
|
|
|
acceptClick = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
popup = document.getElementById(menuId);
|
2006-07-13 21:13:18 +02:00
|
|
|
hideMenu(popup);
|
2006-07-11 20:11:54 +02:00
|
|
|
document.body.setAttribute("onclick", bodyOnClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-13 21:13:18 +02:00
|
|
|
function hideMenu(menuNode)
|
|
|
|
{
|
|
|
|
// log('hiding menu "' + menuNode.getAttribute('id') + '"');
|
|
|
|
if (menuNode.submenu)
|
|
|
|
{
|
|
|
|
hideMenu(menuNode.submenu);
|
|
|
|
menuNode.submenu = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuNode.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
|
2006-07-11 20:11:54 +02:00
|
|
|
function onMenuEntryClick(node, event, menuId)
|
|
|
|
{
|
|
|
|
id = node.getAttribute("id");
|
|
|
|
window.alert("clicked " + menuClickNode.tagName);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-13 21:13:18 +02:00
|
|
|
function log(message) {
|
|
|
|
if (logArea)
|
|
|
|
logArea.innerHTML = logArea.innerHTML + message + '<br />' + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function dropDownSubmenu(event)
|
|
|
|
{
|
|
|
|
var node = event.target;
|
|
|
|
var submenu = node.getAttribute("submenu");
|
|
|
|
if (submenu && submenu != "") {
|
|
|
|
if (node.parentNode.parentNode.submenu)
|
|
|
|
hideMenu(node.parentNode.parentNode.submenu);
|
|
|
|
|
|
|
|
var submenuNode = document.getElementById(submenu);
|
|
|
|
node.parentNode.parentNode.submenu = submenuNode;
|
|
|
|
var menuTop = (node.parentNode.parentNode.offsetTop
|
|
|
|
+ node.offsetTop - 1);
|
|
|
|
var menuLeft = (node.parentNode.parentNode.offsetLeft
|
|
|
|
+ node.parentNode.parentNode.offsetWidth
|
|
|
|
- 2);
|
|
|
|
submenuNode.style.top = menuTop + "px";
|
|
|
|
submenuNode.style.left = menuLeft + "px";
|
|
|
|
submenuNode.style.visibility = "visible";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* drag handle */
|
|
|
|
|
|
|
|
var dragHandle;
|
|
|
|
var dragHandleOrigX;
|
|
|
|
var dragHandleOrigLeft;
|
|
|
|
var dragHandleOrigRight;
|
|
|
|
|
|
|
|
function startHandleDragging(event) {
|
|
|
|
if (event.button == 0) {
|
|
|
|
var leftBlock = event.target.getAttribute('leftblock');
|
|
|
|
var rightBlock = event.target.getAttribute('rightblock');
|
|
|
|
|
|
|
|
dragHandle = event.target;
|
|
|
|
dragHandleOrigX = dragHandle.offsetLeft;
|
|
|
|
dragHandleOrigLeft = document.getElementById(leftBlock).offsetWidth;
|
|
|
|
dragHandleOrigRight = document.getElementById(rightBlock).offsetLeft;
|
|
|
|
|
|
|
|
document.body.setAttribute('onmouseup', 'stopHandleDragging(event);');
|
|
|
|
document.body.setAttribute('onmousemove', 'dragHandleMove(event, "'
|
|
|
|
+ leftBlock
|
|
|
|
+ '", "'
|
|
|
|
+ rightBlock
|
|
|
|
+ '");');
|
|
|
|
document.body.style.cursor = "e-resize";
|
|
|
|
|
|
|
|
dragHandleMove(event, leftBlock, rightBlock);
|
|
|
|
event.cancelBubble = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopHandleDragging(event) {
|
|
|
|
var diffX = (event.clientX - dragHandleOrigX
|
|
|
|
- (dragHandle.offsetWidth / 2));
|
|
|
|
var lBlock
|
|
|
|
= document.getElementById(dragHandle.getAttribute('leftblock'));
|
|
|
|
var rBlock
|
|
|
|
= document.getElementById(dragHandle.getAttribute('rightblock'));
|
|
|
|
|
|
|
|
lBlock.style.width = (dragHandleOrigLeft + diffX) + 'px';
|
|
|
|
rBlock.style.left = (dragHandleOrigRight + diffX) + 'px';
|
|
|
|
|
|
|
|
document.body.setAttribute('onmousemove', '');
|
|
|
|
document.body.setAttribute('onmouseup', '');
|
|
|
|
document.body.setAttribute('style', '');
|
|
|
|
event.cancelBubble = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragHandleMove(event, leftBlock, rightBlock) {
|
|
|
|
if (typeof(dragHandle) == undefined
|
|
|
|
|| !dragHandle)
|
|
|
|
stopHandling(event);
|
|
|
|
else {
|
|
|
|
var width = dragHandle.offsetWidth;
|
|
|
|
|
|
|
|
var hX = event.clientX;
|
|
|
|
if (hX > -1) {
|
|
|
|
var newLeft = hX - (width / 2);
|
|
|
|
|
|
|
|
dragHandle.style.left = newLeft + 'px';
|
|
|
|
event.cancelBubble = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragHandleDoubleClick(event) {
|
|
|
|
dragHandle = event.target;
|
|
|
|
var lBlock
|
|
|
|
= document.getElementById(dragHandle.getAttribute('leftblock'));
|
|
|
|
var lLeft = lBlock.offsetLeft;
|
|
|
|
|
|
|
|
if (dragHandle.offsetLeft > lLeft) {
|
|
|
|
var rBlock
|
|
|
|
= document.getElementById(dragHandle.getAttribute('rightblock'));
|
|
|
|
var leftDiff = rBlock.offsetLeft - dragHandle.offsetLeft;
|
|
|
|
|
|
|
|
dragHandle.style.left = lLeft + 'px';
|
|
|
|
lBlock.style.width = '0px';
|
|
|
|
rBlock.style.left = (lLeft + leftDiff) + 'px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|