2006-11-01 21:28:35 +01:00
|
|
|
/* custom extensions to the DOM api */
|
2007-05-28 18:12:06 +02:00
|
|
|
Element.addMethods({
|
|
|
|
|
|
|
|
addInterface: function(element, objectInterface) {
|
|
|
|
element = $(element);
|
|
|
|
Object.extend(element, objectInterface);
|
|
|
|
if (element.bind)
|
|
|
|
element.bind();
|
|
|
|
},
|
|
|
|
|
|
|
|
childNodesWithTag: function(element, tagName) {
|
|
|
|
element = $(element);
|
|
|
|
var matchingNodes = new Array();
|
|
|
|
var tagName = tagName.toUpperCase();
|
|
|
|
|
|
|
|
for (var i = 0; i < element.childNodes.length; i++) {
|
|
|
|
if (typeof(element.childNodes[i]) == "object"
|
|
|
|
&& element.childNodes[i].tagName
|
|
|
|
&& element.childNodes[i].tagName.toUpperCase() == tagName)
|
|
|
|
matchingNodes.push(element.childNodes[i]);
|
|
|
|
}
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
return matchingNodes;
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
getParentWithTagName: function(element, tagName) {
|
|
|
|
element = $(element);
|
|
|
|
var currentElement = element;
|
|
|
|
tagName = tagName.toUpperCase();
|
|
|
|
|
2006-11-01 21:28:35 +01:00
|
|
|
currentElement = currentElement.parentNode;
|
2007-05-28 18:12:06 +02:00
|
|
|
while (currentElement
|
|
|
|
&& currentElement.tagName != tagName) {
|
|
|
|
currentElement = currentElement.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentElement;
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
cascadeLeftOffset: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var currentElement = element;
|
|
|
|
|
|
|
|
var offset = 0;
|
|
|
|
while (currentElement) {
|
|
|
|
offset += currentElement.offsetLeft;
|
|
|
|
currentElement = currentElement.getParentWithTagName("div");
|
2006-11-01 21:28:35 +01:00
|
|
|
}
|
2007-05-28 18:12:06 +02:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
cascadeTopOffset: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var currentElement = element;
|
|
|
|
var offset = 0;
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
2007-05-29 16:20:13 +02:00
|
|
|
while (currentElement && currentElement.tagName) {
|
2007-05-28 18:12:06 +02:00
|
|
|
offset += currentElement.offsetTop;
|
|
|
|
currentElement = currentElement.parentNode;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
},
|
|
|
|
|
|
|
|
dump: function(element, additionalInfo, additionalKeys) {
|
|
|
|
element = $(element);
|
|
|
|
var id = element.getAttribute("id");
|
|
|
|
var nclass = element.getAttribute("class");
|
|
|
|
|
|
|
|
var str = element.tagName;
|
|
|
|
if (id)
|
|
|
|
str += "; id = " + id;
|
|
|
|
if (nclass)
|
|
|
|
str += "; class = " + nclass;
|
|
|
|
|
|
|
|
if (additionalInfo)
|
|
|
|
str += "; " + additionalInfo;
|
|
|
|
|
|
|
|
if (additionalKeys)
|
|
|
|
for (var i = 0; i < additionalKeys.length; i++) {
|
|
|
|
var value = element.getAttribute(additionalKeys[i]);
|
|
|
|
if (value)
|
|
|
|
str += "; " + additionalKeys[i] + " = " + value;
|
|
|
|
}
|
|
|
|
|
|
|
|
log (str);
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
getSelectedNodes: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var selArray = new Array();
|
|
|
|
|
|
|
|
for (var i = 0; i < element.childNodes.length; i++) {
|
|
|
|
node = element.childNodes.item(i);
|
|
|
|
if (node.nodeType == 1
|
|
|
|
&& isNodeSelected(node))
|
|
|
|
selArray.push(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return selArray;
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
getSelectedNodesId: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var selArray = new Array();
|
|
|
|
|
|
|
|
for (var i = 0; i < element.childNodes.length; i++) {
|
|
|
|
node = element.childNodes.item(i);
|
|
|
|
if (node.nodeType == 1
|
2007-06-08 22:22:18 +02:00
|
|
|
&& isNodeSelected(node)) {
|
|
|
|
selArray.push(node.getAttribute("id")); }
|
2007-05-28 18:12:06 +02:00
|
|
|
}
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
return selArray;
|
|
|
|
},
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
onContextMenu: function(element, event) {
|
|
|
|
element = $(element);
|
|
|
|
var popup = element.sogoContextMenu;
|
2006-11-01 21:28:35 +01:00
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
if (document.currentPopupMenu)
|
2007-07-05 21:13:59 +02:00
|
|
|
hideMenu(document.currentPopupMenu);
|
2007-05-28 18:12:06 +02:00
|
|
|
|
|
|
|
var menuTop = event.pageY;
|
|
|
|
var menuLeft = event.pageX;
|
|
|
|
var heightDiff = (window.innerHeight
|
|
|
|
- (menuTop + popup.offsetHeight));
|
|
|
|
if (heightDiff < 0)
|
|
|
|
menuTop += heightDiff;
|
|
|
|
|
|
|
|
var leftDiff = (window.innerWidth
|
|
|
|
- (menuLeft + popup.offsetWidth));
|
|
|
|
if (leftDiff < 0)
|
|
|
|
menuLeft -= popup.offsetWidth;
|
2007-06-02 00:35:36 +02:00
|
|
|
|
|
|
|
popup.setStyle( { top: menuTop + "px",
|
|
|
|
left: menuLeft + "px",
|
|
|
|
visibility: "visible" } );
|
2007-05-28 18:12:06 +02:00
|
|
|
|
|
|
|
document.currentPopupMenu = popup;
|
|
|
|
Event.observe(document.body, "click", onBodyClickMenuHandler);
|
|
|
|
},
|
|
|
|
|
|
|
|
attachMenu: function(element, menuName) {
|
|
|
|
element = $(element);
|
|
|
|
element.sogoContextMenu = $(menuName);
|
|
|
|
Event.observe(element, "contextmenu", element.onContextMenu.bindAsEventListener(element));
|
|
|
|
},
|
|
|
|
|
|
|
|
select: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
element.addClassName('_selected');
|
|
|
|
},
|
|
|
|
|
|
|
|
deselect: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
element.removeClassName('_selected');
|
|
|
|
},
|
|
|
|
|
2007-05-28 23:30:58 +02:00
|
|
|
deselectAll: function(element) {
|
2007-05-28 18:12:06 +02:00
|
|
|
element = $(element);
|
|
|
|
for (var i = 0; i < element.childNodes.length; i++) {
|
|
|
|
var node = element.childNodes.item(i);
|
|
|
|
if (node.nodeType == 1)
|
2007-06-08 22:22:18 +02:00
|
|
|
$(node).deselect();
|
2007-05-28 18:12:06 +02:00
|
|
|
}
|
2006-11-01 21:28:35 +01:00
|
|
|
}
|
|
|
|
|
2007-05-28 18:12:06 +02:00
|
|
|
});
|