I have a site built with simple templates; header.tpl, navigation.tpl, body_home.tpl, body_about.tpl, body_anotherpage.tpl, etc. The navigation.tpl contains jQuery and is used to dynamically build a drop down navigation menu. When an element is clicked on the first drop down menu, the next is built based on what element was clicked. At some point there's no more drop downs and a variable is set, such as: var action = "dropdowncomplete". Now, in the body_*.tpl template files there's more jQuery which is ran when the action === "dropdowncomplete" evaluates to true. However, I don't know how to do this check with jQuery (nor with JS). Here's a simplified piece of code to illustrate how it works:
/* header.tpl (<head>) - setting this global variable */
var action = null;
/* navigation.tpl - for simplicity's sake, when link is clicked, the var is set */
$(document).ready(function() {
$('a').live('click', function() {
action = "dropdowncomplete";
}); });
/* body_*.tpl - this should be executed when the var is set, in this case when a link is clicked */
if(action === "dropdowncomplete") {
// do something
}
Note that all the above 3 pieces of JS/jQuery code are in separate script blocks!
Thanks.