home *** CD-ROM | disk | FTP | other *** search
HTML Component | 2001-08-08 | 13.2 KB | 589 lines |
- <PUBLIC:COMPONENT NAME="ctTree" tagName="UL" lightWeight=true supportsEditMode=false>
- <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Initialize()" FOR=element/>
- <PUBLIC:ATTACH EVENT="onclick" ONEVENT="OnClick()" />
- <PUBLIC:ATTACH EVENT="onselectstart" ONEVENT="OnSelectStart()" />
- <PUBLIC:METHOD NAME="Initialize" />
- <!-- PUBLIC:METHOD NAME="Expand" / -->
- <!-- PUBLIC:METHOD NAME="Collapse" / -->
- <!-- PUBLIC:METHOD NAME="OnClick" / -->
- <PUBLIC:METHOD NAME="GetCurrentNode" />
- <PUBLIC:METHOD NAME="GetCurrentNodeUIN" />
- <PUBLIC:METHOD NAME="GetCurrentNodeName" />
- <PUBLIC:METHOD NAME="CreateNewNode" />
- <PUBLIC:METHOD NAME="RenameNode" />
- <PUBLIC:METHOD NAME="RemoveNode" />
- <PUBLIC:METHOD NAME="MoveNode" />
- <PUBLIC:METHOD NAME="FindNodeByUIN" />
- <!-- PUBLIC:PROPERTY NAME="IsExpanded" / -->
- <PUBLIC:METHOD NAME="IsChild" />
- <PUBLIC:METHOD NAME="GetForegroundColor" />
- <PUBLIC:METHOD NAME="GetBackgroundColor" />
- <!-- Exposed custom events -->
- <PUBLIC:EVENT NAME="onSelectionChange" ID=selChangeID />
-
- <SCRIPT LANGUAGE="Jscript">
-
- function fnStringToBoolean(someString) {
- if (someString == "true" || someString == true ||
- someString == "1" || someString == 1 || someString == -1 ) {
- return true;
- }
- else if (someString == "false" || someString == false ||
- someString == "0" || someString == 0) {
- return false;
- }
- else
- return someString;
-
- };
-
-
- var oCurrentNode = null;
-
- function GetCurrentNode() {
- return oCurrentNode;
- };
-
- function GetCurrentNodeUIN() {
- if (oCurrentNode != null ) {
- if (oCurrentNode.tagName == "NOBR") {
- return oCurrentNode.parentElement.UIN;
- }
- else if (oCurrentNode.tagName == "LI") {
- return oCurrentNode.UIN;
-
- }
- else {
- return null;
- };
- }
- else {
- return null;
- };
- };
-
- function GetCurrentNodeName() {
- if (oCurrentNode != null ) {
- if (oCurrentNode.tagName == "NOBR") {
- return fnRemoveWhiteSpaces(oCurrentNode.innerText);
- }
- else if (oCurrentNode.tagName == "LI") {
- return fnRemoveWhiteSpaces(oCurrentNode.firstChild.innerText);
-
- }
- else {
- return null;
- };
- }
- else {
- return null;
- };
- };
-
- function FireSelectionChangeEvent() {
- var oEvent = createEventObject();
-
- selChangeID.fire(oEvent);
- };
-
- function FocusNode(someNode) {
- someNode.IsFocused = true;
- someNode.className = "FolderNameFocused";
- };
-
- function UnFocusNode(someNode) {
- someNode.IsFocused = false;
- someNode.className = "FolderNameNotFocused";
- };
-
- function ExpandNode(someNode) {
- if (fnStringToBoolean(someNode.IsExpandable)) {
- someNode.IsExpanded = true;
- someNode.className = "FolderExpanded";
- };
- };
- function CollapseNode(someNode) {
- if (fnStringToBoolean(someNode.IsExpandable)) {
- someNode.IsExpanded = false;
- someNode.className = "FolderCollapsed";
- };
- };
-
- function ExpandToNode(someNode) {
- var oNode = someNode.parentElement;
-
- while (oNode != null) {
- if (oNode.tagName == "LI") {
- ExpandNode(oNode);
- };
-
- oNode = oNode.parentElement;
- };
- };
-
- function CollapseFromNode(someNode) {
- var i = 0;
- if (someNode.tagName != "LI" &&
- someNode.tagName != "UL") {
-
- return;
- };
-
- if (someNode.tagName == "LI") {
- CollapseNode(someNode);
- };
-
- if (someNode.children.length > 0) {
- for (i = 0; i < someNode.children.length; i++) {
- if (someNode.children.item(i).tagName == "UL" ||
- someNode.children.item(i).tagName == "LI"
- ) {
-
- CollapseFromNode(someNode.children.item(i));
- };
- };
- };
- };
-
- function Initialize() {
-
- var oListItems = this.element.getElementsByTagName("LI");
- var i = 0;
- for (i = 0; i < oListItems.length; i++) {
- if ( ! fnStringToBoolean(oListItems[i].IsExpandable)) {
- oListItems[i].className = "FolderNotExpandable";
- };
- if (fnStringToBoolean(oListItems[i].IsExpanded)) {
- ExpandToNode(oListItems[i]);
- };
- };
-
- var oLabelItems = this.element.getElementsByTagName("NOBR");
- for (i = 0; i < oLabelItems.length; i++) {
- if (fnStringToBoolean(oLabelItems[i].IsFocused)) {
- if (oCurrentNode != null) {
- //oCurrentNode.IsFocused = false;
- UnFocusNode(oCurrentNode);
- };
- oCurrentNode = oLabelItems[i];
- ExpandToNode(oCurrentNode.parentElement);
- FocusNode(oCurrentNode);
- ScrollToNode(oCurrentNode);
- };
- };
-
- if (oCurrentNode == null) {
- oCurrentNode = this.element.firstChild.firstChild;
- ExpandToNode(oCurrentNode.parentElement);
- FocusNode(oCurrentNode);
- ScrollToNode(oCurrentNode);
- };
-
- FireSelectionChangeEvent();
-
- return true;
- };
-
- function OnSelectStart() {
- event.cancelBubble= true;
- event.returnValue = false;
- return false;
- };
-
- function OnClick() {
- if ( (event == null) || (event.srcElement == null) ) {
- return ;
- };
-
- var oldID = null;
-
- event.cancelBubble= true;
- event.returnValue = false;
- var oNode = null;
-
- var bDoExpandCollapse = false;
-
- if (event.srcElement.tagName == "UL") {
- return;
- };
-
- if ( ( event.srcElement.tagName == "LI" ) /*&&
- ( event.srcElement.className == "Folder")*/
- ) {
- oNode = event.srcElement;
-
- var rcLI = oNode.getBoundingClientRect();
- var rcLabel = oNode.firstChild.getBoundingClientRect();
-
- if (event.offsetX > oNode.firstChild.offsetLeft + oNode.firstChild.offsetWidth)
- return;
- if (event.offsetY > oNode.firstChild.offsetTop + oNode.firstChild.offsetHeight)
- return;
-
- rcLabel.left = rcLI.left;
- //event.
-
- bDoExpandCollapse = fnStringToBoolean(oNode.IsExpandable);
- };
-
-
- if ( ( event.srcElement.tagName == "NOBR" ) &&
- ( event.srcElement.parentElement.tagName == "LI" ) /*&&
- ( event.srcElement.parentElement.className == "Folder")*/
- ) {
-
- oNode = event.srcElement.parentElement;
-
- bDoExpandCollapse = false;
- };
-
- // UnfocusAll(this.element);
-
- if (oCurrentNode != null) {
- //oCurrentNode.IsFocused = false;
- UnFocusNode(oCurrentNode);
- oldID = oCurrentNode.parentElement.UIN;
- oCurrentNode = null;
-
- };
- /*
- var oFocused = this.element.document.all("Focused");
- if (oFocused != null) {
- try {
- oFocused.id = "NotFocused";
- oFocused.IsFocused = 0;
- }
- catch (err) {
- try {
- while (oFocused.length) {
- oFocused.item(0).IsFocused = 0;
- oFocused.item(0).id = "NotFocused";
- };
- //
- // for (i = 0; i < oFocused.length; i++) {
- // //oFocused.item(i).id = "NotFocused";
- // oFocused.item(i).IsFocused = 0;
- // };
- //
- }
- catch (err) {
- };
- };
- }
- else {
- };
- */
-
- if (oNode != null && bDoExpandCollapse) {
-
- if (fnStringToBoolean(oNode.IsExpanded) == false) {
- //oNode.className = "Open";
- //oNode.IsExpanded = true;
- ExpandNode(oNode);
- }
- else if (fnStringToBoolean(oNode.IsExpanded) == true) {
- //oNode.className = "Closed";
- //oNode.IsExpanded = false;
-
- CollapseNode(oNode);
- CollapseFromNode(oNode);
- };
- }
-
- if (oNode != null) {
- if (oNode.tagName == "LI")
- oNode = oNode.firstChild;
-
- //oNode.id = "Focused";
- FocusNode(oNode);
- ScrollToNode(oNode);
- //oNode.IsFocused = true;
- oCurrentNode = oNode;
-
- };
-
- //this.element.document.recalc(true);
-
- if (oCurrentNode != null && oldID != null //&& oldID != ""
- && oCurrentNode.parentNode.UIN != oldID) {
-
- FireSelectionChangeEvent();
- };
-
- return false;
- };
- function GetForegroundColor () {
- if (Expanded) {
- return "white";
- }
- else {
- return "black";
- };
- };
-
- function GetBackgroundColor () {
- if (Expanded) {
- return "blue";
- }
- else {
- return "white";
- };
- };
-
- function ScrollToNode(someNode1) {
- //alert("ScrollToNode");
- var oNode = someNode1;
- if (oNode.tagName == "LI")
- oNode = oNode.firstChild;
-
- var offTop = oNode.offsetTop;
- var offHeight = oNode.offsetHeight;
- var offLeft = oNode.offsetLeft;
- var offWidth = oNode.offsetWidth;
-
- var offParent = oNode.offsetParent;
-
-
- if (offParent.scrollTop > offTop) {
-
- //someNode.scrollIntoView(true);
- offParent.scrollTop = offTop;
- }
- else if (offParent.scrollTop +
- offParent.clientHeight <
- offTop + offHeight) {
-
- offParent.scrollTop = offTop +
- offHeight - offParent.clientHeight;
- //someNode.scrollIntoView(false);
- };
-
- if (offParent.scrollLeft > offLeft) {
-
- //someNode.scrollIntoView(true);
- offParent.scrollLeft = offLeft;
- }
- else if (offParent.scrollLeft +
- offParent.clientWidth <
- offLeft + offWidth) {
-
- //someNode.scrollIntoView(false);
- offParent.scrollLeft = offLeft - 5;/* +
- offWidth - offParent.clientWidth*/;
-
- };
-
-
- };
-
- function FindNodeByUIN(someUIN) {
-
- var oListItems = this.element.getElementsByTagName("LI");
- var i = 0;
-
- for (i = 0; i < oListItems.length; i++) {
- if (oListItems[i].UIN == someUIN)
- return oListItems[i];
- };
-
- return null;
-
- };
-
- function CreateNewNode(someParentFolderUIN,
- someNewNodeName, someNewNodeUIN) {
-
-
- var oParentNode = FindNodeByUIN(someParentFolderUIN);
-
- if (oParentNode == null) {
- return false;
- };
-
- var oUL = oParentNode.children.item("SubTree");//getElementsByTagName("UL");
-
- if (oUL == null || oUL.length == 0) {
- oUL = this.element.document.createElement("UL");
- oParentNode.appendChild(oUL);
- oUL.className = oUL.name = oUL.id = "SubTree";
-
- //oUL = oParentNode.getElementsByTagName("UL");
- }
-
- var oLI = oUL.document.createElement("LI");
- oUL.appendChild(oLI);
- oLI.className = "FolderNotExpandable";
- oLI.IsExpanded = "false";
- oLI.IsExpandable = 0;
- oLI.UIN = someNewNodeUIN;
-
- var oNOBR = oUL.document.createElement("NOBR");
- oLI.appendChild(oNOBR);
- oNOBR.className = "FolderNameNotFocused";
- oNOBR.name="FolderName";
- oNOBR.IsFocused = "false";
- oNOBR.innerText = someNewNodeName;
-
-
- oParentNode.IsExpandable = -1;
- ExpandNode(oParentNode);
- ScrollToNode(oNOBR);
-
- return true;
-
-
- };
- function RenameNode(someNodeUIN, someNewNodeName) {
- var oNode = FindNodeByUIN(someNodeUIN);
-
- if (oNode == null) {
- return false;
- };
-
- oNode.firstChild.innerText = someNewNodeName;
-
- return true;
-
-
-
- };
-
- function RemoveNode(someNodeUIN, bReSelectNode) {
- var oNode = FindNodeByUIN(someNodeUIN);
-
- if (oNode == null) {
- return null;
- };
-
- if (oNode.UIN == oCurrentNode.parentElement.UIN) {
- UnFocusNode(oNode);
- oCurrentNode = null;
- };
-
- var oParentUL = oNode.parentElement;
- var oParentLI = oParentUL.parentElement;
- var oNodeToFocus = oNode.nextSibling;
- if (oNodeToFocus == null) {
- oNodeToFocus = oNode.previousSibling;
- }
-
- oParentUL.removeChild(oNode);
- //oNode.firstChild.innerText = someNewNodeName;
-
- var oSubNodes = oParentUL.getElementsByTagName("LI");
-
- if (oSubNodes == null || oSubNodes.length == 0) {
- // Removed node was the last child.
- oParentLI.removeChild(oParentUL);
-
- oParentLI.className = "FolderNotExpandable";
- oParentLI.IsExpanded = "false";
- oParentLI.IsExpandable = 0;
-
- oNodeToFocus = oParentLI;
-
- }
- else {
- // There still are other subnodes.
-
- };
-
- if (bReSelectNode) {
- FocusNode(oNodeToFocus.firstChild);
- oCurrentNode = oNodeToFocus.firstChild;
- ScrollToNode(oCurrentNode);
- FireSelectionChangeEvent();
- };
-
- return oNodeToFocus;
- };
-
- function MoveNode(someDstNodeUIN, someSrcNodeUIN) {
-
- var oSrcNode = FindNodeByUIN(someSrcNodeUIN);
- var oDstNode = FindNodeByUIN(someDstNodeUIN);
-
-
- if (oSrcNode == null || oDstNode == null ||
- someSrcNodeUIN == someDstNodeUIN) {
-
- return null;
- };
-
- if (oSrcNode.UIN == oCurrentNode.parentElement.UIN) {
- UnFocusNode(oSrcNode.firstChild);
- oCurrentNode = null;
- };
-
- var oSrcParentUL = oSrcNode.parentElement;
- var oDstChildUL = oDstNode.children.item("SubTree");
-
- var oSrcParentLI = oSrcParentUL.parentElement;
-
- var oSrcSubNodes = oSrcParentUL.getElementsByTagName("LI");
-
- if (oDstChildUL == null) {
- oDstChildUL = this.element.document.createElement("UL");
- oDstNode.appendChild(oDstChildUL);
- oDstChildUL.id = oDstChildUL.name =
- oDstChildUL.className = "SubTree";
-
- oDstNode.IsExpandable = true;
- oDstNode.className = "FolderNotExpanded";
- oDstNode.IsExpanded = "false";
- };
-
- oDstChildUL.appendChild(oSrcNode = oSrcParentUL.removeChild(oSrcNode));
-
- if (oSrcSubNodes == null || oSrcSubNodes.length == 0) {
- // Removed node was the last child.
- oSrcParentLI.removeChild(oSrcParentUL);
-
- oSrcParentLI.className = "FolderNotExpandable";
- oSrcParentLI.IsExpanded = "false";
- oSrcParentLI.IsExpandable = 0;
- }
- else {
- // There still are other subnodes.
- };
-
-
- //if (bReSelectNode) {
- ExpandToNode(oSrcNode);
- FocusNode(oSrcNode.firstChild);
- oCurrentNode = oSrcNode.firstChild;
- ScrollToNode(oCurrentNode);
- //FireSelectionChangeEvent();
- //};
-
- return oCurrentNode;//oNodeToFocus;
- };
-
- function IsChild(someParentUIN, someChildUIN) {
-
- var oParentNode = FindNodeByUIN(someParentUIN);
- var oChildNode = FindNodeByUIN(someChildUIN);
-
-
- if (oParentNode == null) {
- return false;
- };
- if (someParentUIN == someChildUIN) {
- return false;
- };
-
- var oListItems = oParentNode.getElementsByTagName("LI");
- var i = 0;
-
- for (i = 0; i < oListItems.length; i++) {
- if (oListItems[i].UIN == someChildUIN)
- return true;
- };
-
- return false;
- };
-
- </SCRIPT>
- </PUBLIC:COMPONENT>
-
-