1 /* custom extensions to the DOM api */
2 HTMLElement.prototype.addInterface = function(objectInterface) {
3 Object.extend(this, objectInterface);
8 HTMLElement.prototype.childNodesWithTag = function(tagName) {
9 var matchingNodes = new Array();
10 var tagName = tagName.toUpperCase();
12 for (var i = 0; i < this.childNodes.length; i++) {
13 // log("(" + tagName + ") childNodes " + i + " = " + this.childNodes[i]);
14 if (typeof(this.childNodes[i]) == "object"
15 && this.childNodes[i].tagName
16 && this.childNodes[i].tagName.toUpperCase() == tagName)
17 matchingNodes.push(this.childNodes[i]);
20 // log ("matching: " + matchingNodes.length);
25 HTMLElement.prototype.addClassName = function(className) {
26 var classStr = '' + this.getAttribute("class");
28 position = classStr.indexOf(className, 0);
30 classStr = classStr + ' ' + className;
31 this.setAttribute('class', classStr);
35 HTMLElement.prototype.removeClassName = function(className) {
36 var classStr = '' + this.getAttribute('class');
38 position = classStr.indexOf(className, 0);
39 while (position > -1) {
40 classStr1 = classStr.substring(0, position);
41 classStr2 = classStr.substring(position + 10, classStr.length);
42 classStr = classStr1 + classStr2;
43 position = classStr.indexOf(className, 0);
46 this.setAttribute('class', classStr);
49 HTMLElement.prototype.hasClassName = function(className) {
50 var classStr = '' + this.getAttribute('class');
51 position = classStr.indexOf(className, 0);
52 return (position > -1);
55 HTMLElement.prototype.getParentWithTagName = function(tagName) {
56 var currentElement = this;
57 tagName = tagName.toUpperCase();
59 currentElement = currentElement.parentNode;
61 && currentElement.tagName != tagName) {
62 currentElement = currentElement.parentNode;
65 return currentElement;
68 HTMLElement.prototype.cascadeLeftOffset = function() {
69 var currentElement = this;
72 while (currentElement) {
73 offset += currentElement.offsetLeft;
74 currentElement = currentElement.getParentWithTagName("div");
80 HTMLElement.prototype.cascadeTopOffset = function() {
81 var currentElement = this;
87 && currentElement instanceof HTMLElement) {
88 offset += currentElement.offsetTop;
89 currentElement = currentElement.parentNode;
96 HTMLElement.prototype.dump = function(additionalInfo, additionalKeys) {
97 var id = this.getAttribute("id");
98 var nclass = this.getAttribute("class");
100 var str = this.tagName;
102 str += "; id = " + id;
104 str += "; class = " + nclass;
107 str += "; " + additionalInfo;
110 for (var i = 0; i < additionalKeys.length; i++) {
111 var value = this.getAttribute(additionalKeys[i]);
113 str += "; " + additionalKeys[i] + " = " + value;
119 HTMLElement.prototype.getSelectedNodes = function() {
120 var selArray = new Array();
122 for (var i = 0; i < this.childNodes.length; i++) {
123 node = this.childNodes.item(i);
124 if (node.nodeType == 1
125 && isNodeSelected(node))
132 HTMLElement.prototype.getSelectedNodesId = function() {
133 var selArray = new Array();
135 for (var i = 0; i < this.childNodes.length; i++) {
136 node = this.childNodes.item(i);
137 if (node.nodeType == 1
138 && isNodeSelected(node))
139 selArray.push(node.getAttribute("id"));
145 HTMLElement.prototype.onContextMenu = function(event) {
146 var popup = this.sogoContextMenu;
148 if (document.currentPopupMenu)
149 hideMenu(event, document.currentPopupMenu);
151 var menuTop = event.pageY;
152 var menuLeft = event.pageX;
153 var heightDiff = (window.innerHeight
154 - (menuTop + popup.offsetHeight));
156 menuTop += heightDiff;
158 var leftDiff = (window.innerWidth
159 - (menuLeft + popup.offsetWidth));
161 menuLeft -= popup.offsetWidth;
163 popup.style.top = menuTop + "px;";
164 popup.style.left = menuLeft + "px;";
165 popup.style.visibility = "visible;";
166 // setupMenuTarget(popup, event.target);
168 bodyOnClick = "" + document.body.getAttribute("onclick");
169 document.body.setAttribute("onclick", "onBodyClick(event);");
170 document.currentPopupMenu = popup;
172 // event.cancelBubble = true;
173 // event.returnValue = false;
176 HTMLElement.prototype.attachMenu = function(menuName) {
177 this.sogoContextMenu = $(menuName);
178 this.addEventListener("contextmenu", this.onContextMenu, true);
181 HTMLElement.prototype.select = function() {
182 this.addClassName('_selected');
185 HTMLElement.prototype.deselect = function() {
186 this.removeClassName('_selected');
189 HTMLElement.prototype.deselectAll = function () {
190 for (var i = 0; i < this.childNodes.length; i++) {
191 var node = this.childNodes.item(i);
192 if (node.nodeType == 1)