This is pretty cool and makes for a smoother experience to the end user but some developers have had a hard time coupling their javascript routines into this model.
Meet $Behavior
$Behavior is a namespace that is triggered every time a page is loaded, even in ajax browsing mode. If your old JavaScript code looked like this:$(document).ready(function() {
// Your code here
});
You will have to change that to:
$Behavior.anyNameYouWant = function(){
// Your code here
};
They are both equivalent except that with ajax browsing enabled it will trigger your "anyNameYouWant" function and not the JQuery one.
Similarly this replaces the following:
$(function() {
// Your code here
});
since that is the same as $(document).ready
Even if site wide ajax browsing is disabled, the $Behavior namespace will be triggered, so you can safely code in $Behavior and not worry about site wide ajax browsing being enabled or disabled.