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

The second section of the global statement section consists of only two statements, but they are important for understanding the entire script. The first statement in this section assigns an empty string to the global variable state. The clearState() function is called next. It modifies the value of the global variable state, by assigning it n0” characters, where n is the length of the current message. The variable state is basically constructed of 0s and 1s. Suppose the first character is a 0. That means that the first character of the current message has not been popped up yet. The same applies to the second character and all the following ones. Therefore, the string starts off at all 0s, and the message is finished when all characters are 1s.

stopBanner()

See explanation of this function in the T-banner.

startBanner()

See explanation of this function in the T-banner.

clearState()

See the section “Global Statements” for information regarding this function.

getRandom(max)

This simply returns an integer between 0 and max – 1 (see explanation of Math.random()).

getString()

function getString() {
// set variable to true (it will stay true unless proven otherwise)
var full = true

// set variable to false if a free space is found in string (a
not-displayed char)
for (var j = 0; j < state.length; ++j) {
 // if character at index j of current message has not been
placed in displayed string
 if (state.charAt(j) == 0)
   full = false
}

// return true immediately if no space found (avoid infinitive
  loop later)
if (full)
   return true
// search for random until free space found (broken up via
 break statement)
while (1) {
// a random number (between 0 and state.length – 1 ==
   message.length – 1)
var num = getRandom(ar[message].length)

// if free space found break infinitive loop
if (state.charAt(num) == "0")
  break
 }

// replace the 0 character with 1 character at place found
state = state.substring(0, num) + "1" + state.substring(num + 1,
state.length)

// return false because the string was not full (free space
 was found)
return false
}

At first, the variable full is initialized to true. An infinite loop (terminated by the break statement) is employed to go over all 0 and 1 characters of the state string. If a 0 character is found, the variable full is changed to false. It is not mandatory to break up the loop (as done above in getString()) when a free space, or 0, is found, because efficiency is not a concern in a random banner.

The remaining part of the function is executed only if a free space is available.

An infinite loop generates a new random index every iteration and checks if the space at that index is taken up. The loop continues to execute as long as the space at the random index is taken up. When a free space is finally found, the loop breaks up, returning the index num of the free space.

The value of state is updated by replacing the 0 character at index num with a 1 character. The function returns false upon termination, indicating that the message was not completed.

showBanner()

Like in the T-banner script, this function is the main one.

The function getString()is called to update the value of state and to check if the message has been completed. If it has, the current message is updated to the following one by incrementing the value of message, representing the index of the array’s element where the current message is. If the new value is out of range, it is reset to the initial zero value. The function clearState() is called to set up the variable state, as explained above in the “Global Statements” section. The function is then called recursively after pause milliseconds.

In an ordinary case in which the message is not complete yet, the special display effects are generated. An empty string is assigned to the local variable str, ready to accumulate characters for display. A for loop iterates through the characters of the string ar[message]. If there is a 1 at the same index of the string state, the character from ar[message] is appended to the end of str. An alternative string is appended if a 0 character is found in the string state. The only way to create a right-to-left scrolling effect is to use a fairly long alternative string of a few spaces. Since a space has a very small horizontal span (characters are not uniform in width), a single-space alternative string will create a friendly left-to-right movement! Using an empty alternative string squeezes the string and creates a different right-to-left movement. The built-up string is placed in the status bar, and the function is called recursively after a pause of speed milliseconds.

Event Handlers

When the document is completely loaded, the startBanner() function is called by the onLoad event handler.

N-banner

The N(normal)-banner scrolls from right to left in the status bar. You have probably seen hundreds of these banners on the Web. Here is a script to implement such a banner:

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us