Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




Previous Table of Contents Next

item(parent, text, depth)

// constructor function to create an entry (parent or child)
function item(parent, text, depth) {
  this.parent = parent // is this item a parent?
  this.text = text // text for link (may include HTML)
  this.depth = depth // nested depth
}

The constructor function item() accepts three arguments and creates three properties with the same names as the function’s parameters: parent, text, and depth. The first parameter (and property), parent, accepts a Boolean value indicating whether or not the item is a parent. An item is considered a parent only if it has children, or nested items. In Figure 24-3, “Software” is a parent, but “Microsoft” is not. The function’s second argument, text, accepts an HTML-valid string such as <A HREF="http://www.jumbo.com">Jumbo</A> for the “Jumbo” entry in Figure 24-3. You can use virtually any HTML-valid string such as plain text, a link (as in the “Jumbo” example), or even a small image. The last argument, depth, is the depth of the item being created, i.e., it specifies how deep the item is nested. The topmost level item’s depth property is 0, whereas its children’s depth property is 1, and so forth.

makeArray(length)

// constructor function to create array (compatible
// with all browsers)
function makeArray(length) {
  this.length = length // length of array (integer)
}

This function is an alternative to the built-in Array() constructor of Navigator and MSIE. We decided to write an array-constructor on our own in order to make the script compatible with all JavaScript-enabled browsers, and for didactic purposes. We used JavaScript’s support for adding properties to an object, to explicitly create length, which holds the number of elements in the array, or the number of its properties (not counting length itself), to be exact.

makeDatabase()

// create items of outline
function makeDatabase() {

  outline = new makeArray(9) // create global object
  // create items in outline
  outline[0] = new item(true, 'computer companies', 0)
  outline[1] = new item(false, '<A HREF="http://www.intel
   .com">Intel</A>', 1)
  outline[2] = new item(true, 'software', 1)
  outline[3] = new item(false, '<A HREF="http://www.netscape
   .com">Netscape</A>', 2)
  outline[4] = new item(false, '<A HREF="http://www.microsoft
   .com">Microsoft</A>', 2)
  outline[5] = new item(false, '<A HREF="http://www.netscent
   .com">Netscent</A>', 1)
  outline[6] = new item(true, 'shareware Web sites', 0)
  outline[7] = new item(false, '<A HREF="http://www.jumbo
   .com">Jumbo</A>', 1)
  outline[8] = new item(false, '<A HREF="http://www.windows95
   .com">Windows95.com</A>', 1)

// determine current state of each item and assign
// to state properties
  setStates()
  // set image for each item (only items with true state)
  setImages()
}

This function creates the main array used for the outline structure. Notice that the outline array is declared without the keyword var and thus is global. Try adding var to this statement to find out how important “one small word” can be. The next portion of this function deals with the properties (elements) of the outline array. Each property becomes an instance of the item object. The order of the elements in the array is very important. An item’s children should immediately follow the item, so the order in the outline array is the order in which the entries appear, from top to bottom, in a fully expanded table of contents.

The function then calls setStates() and setImages().

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us