|
Under some situations you may want to be able to display or hide a
toolbar. For example, you could create a project with two toolbars:
one which is always visible and the other that its only displayed
under a specific section of your web site. The toolbars' visibility is controlled through the state of
a condition known as
the "Visibility Condition".
To access this parameter, click Tools->Toolbars Editor->Advanced
The condition must be defined by the body of a function that,
when evaluated, must return either true (visible) or false (hidden).
So, for example, if you add this code to the Visibility Condition
of a toolbar:
return
document.title.indexOf("Customers")!=-1;
The toolbar will remain hidden unless the title of the document
being displayed contains the "Customers" string in its title.
If you need to match the exact title of an HTML document to
determine the visibility state of a toolbar you could use this code:
return
document.title == "Ink Cartridges - Color";
In this case, the toolbar will remain hidden unless the title of
an HTML document exactly matches the "Ink Cartridges - Color"
string.
These are just some basic examples that take advantage of the
page title to determine the visibility state of a toolbar... but you
could be a lot more creative and use some more complex conditions.
For example, you could create a condition that depends on some other
javascript variable in your page, or perhaps a condition that
depends on the actual time or date.
The possibilities are just endless...
Modifying the Visibility Condition programmatically
The state of a toolbar can also be changed by directly accessing
the variable that controls their visibility by adding some code into
an HTML document.
For example, this code will turn the toolbar number 1 off:
<script
language="JavaScript">
tbVisC[1] = new Function("return false");
SetupToolbar();
</script>
The first line of code defines the body of a simple function that
returns a false value setting the visibility state for the toolbar
number 1 to be hidden.
The second line of code causes a refresh in all the toolbars by
re-evaluating all their parameters. If the second line is omitted
the visibility state will not change.
Creating a blinking effect
Although it may not be a useful thing to have a toolbar blink it
demonstrates the power and versatility of this new feature in DHTML
Menu Builder 4.1 (and above)
Here's the code used in the Visibility Condition of the toolbar:
var m=new Date().getMilliseconds();
if(!SM)window.setTimeout("SetupToolbar()", 100); return (m<800);
First of all, notice that the code must always be contained in a
single line and must always return either true or false.
So, let's analyze the code, piece by piece:
var m=new Date().getMilliseconds();
The first piece of code queries the system and retrieves the
current time, but only the milliseconds. The result is stored in the
variable 'm'.
The second section of the code:
if(!SM)window.setTimeout("SetupToolbar()",
100);
This code setups a timer so the SetupToolbar() function is called again.
This will force the code to keep re-evaluating our condition until
the page is unloaded. Notice that this timer is only required on
Internet Explorer; this is why we use the "if(!SM)" condition, which
means: "...if its not a mozilla-based browser, then...".
And finally, the third piece of code:
return (m<800);
...is the return statement.
In this statement we're comparing the value in the variable 'm' with
the number 800. If the value in 'm' is less than 800 the function
will return true, otherwise it will return false.
This causes the function to return true for about 800
milliseconds and false for about 200. This will cause the toolbar to
remain invisible (hidden) for about 200 milliseconds per every
second.
| Related topics of interest:
|
|