Author: A.Skokov
Date: 2007-06-27 12:33:47 -0400 (Wed, 27 Jun 2007)
New Revision: 1349
Modified:
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
Log:
http://jira.jboss.com/jira/browse/RF-295
Modified:
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
---
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-06-27
16:17:02 UTC (rev 1348)
+++
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-06-27
16:33:47 UTC (rev 1349)
@@ -18,10 +18,10 @@
if (this.onContextMenu) {
this.eventRightClick = this.onContextMenu.bindAsEventListener();
}
-
+
this.observeEvents();
},
-
+
observeEvents: function() {
Event.observe(this.elements.icon, "mousedown", this.eventSelectionClick);
Event.observe(this.elements.text, "mousedown", this.eventSelectionClick);
@@ -46,9 +46,9 @@
this.elements.text.oncontextmenu = this.eventRightClick;
}
},
-
+
getElements: function() {
- ($(this.id)).object = this;
+ //($(this.id)).object = this; //dublicate: see initialize()
this.nodeStateInput = $(this.id + "NodeExpanded");
this.childs = [];
var childsRowId = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;
@@ -60,22 +60,29 @@
this.elements.handleImgCollapsed = $(handleId + Tree.ID_DEVIDER +
Tree.ID_HANDLE_IMG_COLLAPSED);
this.elements.icon = $(this.id + Tree.ID_DEVIDER + Tree.ID_ICON);
this.elements.text = $(this.id + Tree.ID_DEVIDER + Tree.ID_TEXT);
-
+
var contextMenu = Richfaces.getNSAttribute("oncontextmenu",
this.elements.icon);
if (contextMenu && contextMenu.length > 0) {
this.onContextMenu = new Function(contextMenu + "; return true;");
}
-
+
var childsTd = $(childsRowId + Tree.ID_DEVIDER + Tree.ID_CHILDS_TD);
if (childsTd) {
- for (var i = 0; i < childsTd.childNodes.length; i++) {
+ for(var child = childsTd.firstChild; child != null; child = child.nextSibling
) {
+ if (child.nodeType == 1 && child.tagName.toLowerCase() ==
"table") {
+ this.addChild(new Tree.Item(child.id, this.tree, this,
this.childs.length, this.switchType, this.toggleOnClick));
+ }
+ }
+ /*
+ for (var i = 0; i < childsTd.childNodes.length; i++) {
var child = childsTd.childNodes[i];
if (child.nodeType == 1 && child.tagName.toLowerCase() == "table")
{
this.addChild(new Tree.Item(child.id, this.tree, this, this.childs.length,
this.switchType, this.toggleOnClick));
}
}
+ */
}
-
+
this.elements.mainRow = $(mainRowId);
},
@@ -87,29 +94,29 @@
fireExpansionEvent: function() {
var props = new Object();
props[Richfaces.TreeExpandEvent] = true;
- props["expandedNode"] = this.id;
- props["treeItem"] = this;
+ props["expandedNode"] = this.id;
+ props["treeItem"] = this;
Richfaces.createEvent("click", this.tree.element, null, props).fire();
},
fireCollapsionEvent: function() {
var props = new Object();
props[Richfaces.TreeCollapseEvent] = true;
- props["collapsedNode"] = this.id;
- props["treeItem"] = this;
+ props["collapsedNode"] = this.id;
+ props["treeItem"] = this;
Richfaces.createEvent("click", this.tree.element, null, props).fire();
},
toggleCollapsion: function() {
if (this.hasChilds()) Element.toggle(this.elements.row);
-
+
// Rerender main row to avoid bad representation in Opera and Konqueror/Safari
if (this.elements.mainRow) {
Element.hide(this.elements.mainRow);
Element.show(this.elements.mainRow);
}
-
+
if (this.isCollapsed()) {
this.elements.handleImgExpanded.style.display="none";
this.elements.handleImgCollapsed.style.display="";
@@ -117,11 +124,11 @@
Element.removeClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
}
-
+
if (this.nodeStateInput) {
this.nodeStateInput.value = "false";
}
-
+
this.fireCollapsionEvent();
} else {
this.elements.handleImgExpanded.style.display="";
@@ -134,7 +141,7 @@
if (this.nodeStateInput) {
this.nodeStateInput.value = "true";
}
-
+
this.fireExpansionEvent();
}
@@ -148,7 +155,7 @@
if (!this.isCollapsed() && this.switchType!="client") {
if (this.toggleOnClick) {
if (this.elements.mainRow)
- this.elements.mainRow.onclick();
+ this.elements.mainRow.onclick();
} else {
if (this.elements.handle)
this.elements.handle.onclick();
@@ -171,7 +178,7 @@
if (this.isCollapsed() && this.switchType!="client") {
if (this.toggleOnClick) {
if (this.elements.mainRow)
- this.elements.mainRow.onclick();
+ this.elements.mainRow.onclick();
} else {
if (this.elements.handle)
this.elements.handle.onclick();
@@ -209,7 +216,7 @@
}
if (window.drag){
this.dragLeave(e);
- }
+ }
}
}
},
@@ -225,7 +232,7 @@
}
if (window.drag) {
this.dragEnter(e);
- }
+ }
}
}
},
@@ -233,63 +240,63 @@
toggleSelection: function(e) {
if (e && !e[Richfaces.TreeSelectEvent] &&
!Richfaces.eventIsSynthetic(e)) {
if (e && e.type == "mousedown" /* can be keydown */) {
- if(Event.isLeftClick(e)) {
+ if(Event.isLeftClick(e)) {
var src = Event.element(e);
if(src.tagName && (
src.tagName.toUpperCase() == 'INPUT' ||
src.tagName.toUpperCase() == 'SELECT' ||
src.tagName.toUpperCase() == 'OPTION' ||
src.tagName.toUpperCase() == 'BUTTON' ||
- src.tagName.toUpperCase() == 'TEXTAREA'))
+ src.tagName.toUpperCase() == 'TEXTAREA'))
return;
-
+
Event.stop(e);
} else {
- //do not process non-left clicks
+ //do not process non-left clicks
return ;
}
}
var props = new Object();
props[Richfaces.TreeSelectEvent] = true;
- props["originatingEventType"] = e.type;
- props["treeItem"] = this;
- props["selectedNode"] = this.id;
+ props["originatingEventType"] = e.type;
+ props["treeItem"] = this;
+ props["selectedNode"] = this.id;
var evt = Richfaces.createEvent("click", this.tree.element, null, props);
evt.fire();
-
+
return !evt.event["cancelSelection"];
} else {
this.tree.deselectAll();
-
+
/*
var attr = this.elements.text.attributes;
var s = "";
for (var i = 0; i < attr.length; i++) {
s += attr[i].nodeName + ": " + attr[i].nodeValue + "; ";
}
-
+
alert(s);
*/
-
+
var sClass = Richfaces.getNSAttribute("selectedclass", this.elements.text);
if (sClass) {
-
+
var classNames = sClass.split(' ')
for (var i = 0; i < classNames.length; i++) {
Element.addClassName(this.elements.text, classNames[i]);
}
this.tree.input.value = this.id;
this.tree.selectionManager.activeItem = this;
-
+
if (this.tree.options.onSelection) this.tree.options.onSelection(this.id);
this.tree.showNode(this.elements.text.parentNode);
-
+
if (e && e["originatingEventType"] == "mousedown" /* can
be keydown */) {
this.startDrag(e);
}
}
-
+
return true;
}
},
Modified:
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
===================================================================
---
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-06-27
16:17:02 UTC (rev 1348)
+++
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-06-27
16:33:47 UTC (rev 1349)
@@ -35,7 +35,7 @@
this.inputId = input;
this.input = $(this.inputId);
this.toggleOnClick = toggleOnClick;
-
+
var options = Object.extend({
columnCount: 0
}, arguments[1] || {}
@@ -51,27 +51,27 @@
Event.observe(this.element, "click", function(event) {
if (Richfaces.eventIsSynthetic(event)) {
var treeItem = event["treeItem"];
-
+
if (event[Richfaces.TreeSelectEvent]){
Event.stop(event);
-
+
var itemOnSelect = treeItem.getRichAttribute("onselected");
itemOnSelect = new Function('event', (itemOnSelect ? itemOnSelect :
"") + "; return true;");
-
- var selectResult = itemOnSelect(event);
+
+ var selectResult = itemOnSelect(event);
if (!selectResult) {
event["cancelSelection"] = true;
- return ;
+ return ;
}
- selectResult = this.onselect(event);
+ selectResult = this.onselect(event);
if (!selectResult) {
event["cancelSelection"] = true;
- return ;
+ return ;
}
-
+
treeItem.toggleSelection(event);
-
+
var attr = Richfaces.getNSAttribute("ajaxselectedlistener",
$(event.selectedNode + Tree.ID_DEVIDER + Tree.ID_ICON));
if (attr) {
this.onAjaxSelect(event);
@@ -84,7 +84,7 @@
new Function('event', handler).call(Event.element(event), event);
}
- this.onexpand(event);
+ this.onexpand(event);
} else if (event[Richfaces.TreeCollapseEvent]){
Event.stop(event);
@@ -92,8 +92,8 @@
if (handler) {
new Function('event', handler).call(Event.element(event), event);
}
-
- this.oncollapse(event);
+
+ this.oncollapse(event);
}
}
}.bindAsEventListener(this));
@@ -109,12 +109,19 @@
this.elements.contentTd = $(contentId);
if (this.elements.contentTd) {
- for (var i = 0; i < this.elements.contentTd.childNodes.length; i++) {
+ for(var child = this.elements.contentTd.firstChild; child != null; child =
child.nextSibling ) {
+ if (child.nodeType == 1 && child.tagName.toLowerCase() ==
"table") {
+ this.addChild(new Tree.Item(child.id, this, this, this.childs.length,
this.switchType, this.toggleOnClick));
+ }
+ }
+ /*
+ for (var i = 0; i < this.elements.contentTd.childNodes.length; i++) {
var child = this.elements.contentTd.childNodes[i];
if (child.nodeType == 1 && child.tagName.toLowerCase() == "table")
{
this.addChild(new Tree.Item(child.id, this, this, this.childs.length,
this.switchType, this.toggleOnClick));
}
}
+ */
}
},
@@ -126,7 +133,7 @@
var dim = {};
var bc = {width: 0, height: 0};
-
+
/* - commented by nick
if (/MSIE/.test(navigator.userAgent)) {
bc.width = parseInt(Element.getStyle(this.element, "border-left-width")) +
parseInt(Element.getStyle(this.element, "border-right-width"));
@@ -161,7 +168,7 @@
this.items.each(function(item) {item.deselect();} );
},
-
+
getNodeElements: function(nodeIds) {
if (nodeIds) {
for (var i = 0; i < nodeIds.length; i++ ) {
@@ -171,7 +178,7 @@
this.selectionManager.restoreSelection();
}
},
-
+
_getNodeElements: function(node, nodeId) {
if (node.id == nodeId) {
node.getElements();
@@ -183,7 +190,7 @@
}
}
},
-
+
showNode: function(itemNode) {
var node = itemNode;
var offsetTopItem = 0;
@@ -201,7 +208,7 @@
this.element.scrollTop = nodeBottom - this.element.clientHeight;
}
},
-
+
getElement: function() {
return $(this.id);
}