|
home / documentation / setup / Using Page Specific Variables in HierMenus 6
Using Page Specific Variables in HierMenus 6
As was the case with versions 4 and 5 of HierMenus, you may use page specific variables in
HierMenus version 6. Page specific variables allow you to override, for a specific Web page,
the script defaults for any configuration or global parameter; i.e., any of the 6 parameters
specified in the HM_Loader.js file or any of the configuration parameters that you
would otherwise specify in the HM_f_UpdateDefaults configuration file command. While
HierMenus 6 supports page specific parameters, it does so differently than HierMenus versions
4 and 5 did.
Do You Really Need Them?
In a great number of HierMenus 4 and 5 implementations that we saw, page specific
variables were badly misused. The fact is that you should only use page specific
variables for Web pages where you want your menu settings--such as color schemes or
click behaviors--to differ from their normal uses elsewhere on the site. In many
version 4/5 implementations what we found was that page specific variables were instead
used as the rule, i.e., they were simply assigned (the same set of
parameters) to every page on the site. We're partially to blame for this,
since our example pages all included page specific variables, leading many to no doubt
conclude they were necessary for all implementations. Our version 6 HierMenus files
rectify this, at the risk of potentially scaring some users into thinking page specific
variables are no longer supported. Don't worry, they are.
But before using them, do put some thought into the question of whether or not you
really need them, and if so, why.
If you've structured your configuration file properly, then your HM_f_UpdateDefaults
call should be handling all the global parameter settings for at least the majority if not
all of your pages.
Again, you should only need page specific variables for those--hopefully few--pages where
the default settings are inapproriate.
Page Specific Global Parameters
To specify page specific versions of the global parameters (i.e., the six parameters
you set in the HM_Loader.js file in step 1 of the
setup instructions) you simply include their assignments anywhere in your HTML page
prior to the calling of the HM_Loader.js file. For example, if I wish
to set a specific configuration file directory and file(s) for a particular page, I
might insert this JavaScript into the head of the document:
<script type="text/javascript">
HM_ConfigDir="/hm/configs2/";
HM_ConfigFiles="alt1.js,alt2.js";
</script>
Recall that when you modified the global versions of these parameters in
HM_Loader.js, we introduced you to this specific syntax:
if(typeof(window.HM_ScriptDir)=="undefined")
HM_ScriptDir = "/hm/scripts/";
If you left this syntax intact, then you can alter the variable settings as described
above. If, on the other hand, you removed the "if(...." line that precedes the variable
settings in HM_Loader.js file, then you will not be able to set page specific
versions of these parameter settings. Therefore, we recommend leaving the "if..." checks
in for exactly this purpose.
Page Specific Configuration Parameters
The configuration parameters, i.e., the parameters you set via the
HM_f_UpdateDefaults command in your configuration file, can also be overridden
on a page specific basis. You do this by implementing the page specific variables
object. To add a page specific variable object to your page, follow this syntax:
HM_o_PageDefaults = {
ParameterName1:ParameterValue1,
ParameterName2:ParameterValue2,
...
ParameterNameN:ParameterValueN
};
Note especially the following:
The object is always called HM_o_PageDefaults.
A single pair of curly brackets ({}) encloses all of the
parameter name:value pairs.
Each parameter:value pair must be separated by a comma.
The last name:value pair in the list must not be followed by a comma.
This is the golden rule in HierMenus configurations: Whenever a list of items is
specified (in this case name:value pairs) each entry in the list must be separated
by commas, but the last entry in the list must not be followed by
a comma. JavaScript syntax requires this; if you vary from this rule you will find
that your menus may not work at all.
Parameter names are always separated from their values with a colon (:).
Parameter names are always case-sensitive; ClickKill and clickKill
are two completely different parameter names in HierMenus. Parameter values are often
case sensitive, too (if you are in doubt, assume that they are).
Unlike the HM_f_UpdateDefaults configuration file entries
the HM_o_PageDefaults object is not
a command; it is simply a static object that HierMenus will look for and utilize
later. This is why it uses the standard "=" syntax, as opposed to surrounding the
name:value pairs within parentheses.
You'll need to include the HM_o_PageDefaults object in a valid JavaScript
segment of the page in order for HierMenus to recognize it. This segment can appear anywhere
on the page, before or after the HM_Loader.js call is loaded.
Full example:
<script type="text/javascript" language="JavaScript1.2">
HM_ConfigDir="/hm/configs2/";
HM_ConfigFiles="alt1.js,alt2.js";
HM_o_PageDefaults = {
FontColor:"green",
FontColorOver:"red"
};
</script>
What parameters can you set in HM_o_PageDefaults? Basically, anything you can
set in HM_f_UpdateDefaults can be set in HM_o_PageDefaults.
A complete listing and
reference can be found in our Reference Section, and we
recommend that you browse that listing to at least get a feel for the available parameters and
their capabilities. And remember that whether not a particular variable is applicable on
a global scale--ItemClass, for example applies only to items, not menus; and
MenuBGColor only to menus, not items--is irrelevant. Both of these settings
are equally welcome in HM_f_PageDefaults, where they will happily be inherited
by the menus and/or items on your page that need them. Parameter settings in
HM_o_PageDefaults will not, however, override menu or item specific parameter
settings (and remember that HM_f_SetMenuTemplate settings are considered to be
menu specific settings) just as HM_f_UpdateDefaults settings would not override
menu and item specific parameters.
|