Click here to Skip to main content
Licence 
First Posted 22 Jan 2004
Views 43,499
Bookmarked 23 times

JScript tree control menu

By | 25 Jan 2004 | Article
JScript tree control menu

Introduction

This is a tree control menu in JavaScript. Usage is simple and convenient.

Explanation

I will introduce this tree control embodying to JavaScript. This menu will be more accurate than other such controls. First point that this control differs with other controls is that this is embodied by multiplex distribution. It is actually possible, though some people think that multiplex arrangement is impossible with JavaScript.

  Item[iLength]  = new Array();
  Item[iLength][0] = parentItem;
  Item[iLength][1] = description;
  Item[iLength][2] = hreference;
  Item[iLength][3] = target;
  Item[iLength][4] = iDepth;
  Item[iLength][5] = true;

I enabled multiplex arrangement by assigning distribution (that is new again) on the 0th arrangement article. In this way, that we have an embodied arrangement of multidimensional items.

And I will explain about the code that changes the tree node image. First, see code.

DocWrite("<img id=wsTreeNodeImg_" + i + 
  " src='" + ImgDir + TempNodeImg + "' border='0'>"); 
...
//case NS6

Doc.getElementById(ItemName + iItem).src = ImgName;
//case IE6

Doc[ItemName + iItem].src = ImgName;

Method that checks for browser:-

  if (document.all) { //IE4
   Doc = document.all;
   browserVersion = 1;  
   
  }else if (document.layers) { //NS4 
   Doc = document.layers;
   browserVersion = 2; 

  }else if(document.getElementById) { //NS6
   Doc = document;
   browserVersion = 3;  
   
  }else { //other 
   Doc = document.all;
   browserVersion = 0; 
  }

First, I create wsTreeCtrl's instance. And I call initialization function (initializeDocument).

 m_wsTreeCtrl = new wsTreeCtrl();
 m_wsTreeCtrl.initializeDocument();

Now, I put items to add in the tree through InsItem function. The first parameter is the parent item (in some cases, it is child item.), the second parameter establishes the text to be seen, and the third is the hyper link, and I establish target of hyper link finally. The following is the code that establishes tree of contents such as an upside image.

 iItem = m_wsTreeCtrl.InsItem(null, "Profile", "", "_blank");
 m_wsTreeCtrl.InsItem(iItem, 
   "whitespray", "http://whitespray.com/">http://whitespray.com/", "_blank");
 
 iItem = m_wsTreeCtrl.InsItem(null, "Homepage", "", "_blank");
 m_wsTreeCtrl.InsItem(iItem, "jongha.pe.kr", 
   "http://jongha.pe.kr/">http://jongha.pe.kr/", "_blank");
 m_wsTreeCtrl.InsItem(iItem, "whitespray.com", 
   "http://whitespray.com/">http://whitespray.com/", "_blank");
 m_wsTreeCtrl.InsItem(iItem, "hizine.net", 
   "http://hizine.net/">http://hizine.net/", "_blank");
 
 iItem = m_wsTreeCtrl.InsItem(null, "Email", 
   "mailto:ahn@jongha.pe.kr">mailto:ahn@jongha.pe.kr", "_blank");
   
 m_wsTreeCtrl.GenerateCode();
 m_wsTreeCtrl.RecudeAllTree();
 
 function Recude() {
  m_wsTreeCtrl.RecudeAllTree();
 }
 
 function Expand()  {
  m_wsTreeCtrl.ExpandAllTree();
 }

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jongha Ahn

Software Developer

Korea (Republic Of) Korea (Republic Of)

Member

Computer Programmer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralOne Indent Bug PinmemberFrank Su18:26 8 Aug '04  
GeneralRe: One Indent Bug Pinmemberwhitespray17:45 10 Aug '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120528.1 | Last Updated 26 Jan 2004
Article Copyright 2004 by Jongha Ahn
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid