This is a port of jquery-hashchange to the Kynetx Rules Language. Many thanks to Phil Windley for describing how to build a single page interface in KBlog: Making the Back Button Work.
The primary purpose of this module is to provide an evented controller for navigation within a single page interface.
The hashchange module has been placed in the Kynetx Public Module Directory. To use the module add the following use module
pragma to the meta section of your ruleset:
meta {
...
use module a169x567
}
Load the jQuery plugin that provides an interface to browser hashchange events.
rule page_init {
select when pageview ".*"
a169x567:init();
}
Set a new URL hashtag.
rule sitenav_login_complete {
select when explicit login_complete
{
siteNav:setHash"/myprofile");
}
}
Since I have been spending a lot of time with Twitter Bootstrap lately this action was included. This sets the active navbar.
rule sitenav_about {
select when web hash_change newhash "/about$"
{
siteNav:setActiveNav("#navAbout");
}
}
Note: The selector can be any valid jQuery selector.
Likewise this action has been included to as a result of my work with Twitter Bootstrap. This displays a specific section of the document, while hiding all of the other sections.
rule sitenav_about {
select when web hash_change newhash "/about$"
{
siteNav:setActiveNav("#navAbout");
siteNav:showPanel("#sectionAbout");
}
}
Note: The selector can be any valid jQuery selector.