Thursday, April 26, 2012

Phpfox: onReady with Ajax Browsing

Phpfox offers a site wide ajax browsing experience. This allows to load new pages and change the URL without actually going to another page. Clients save on resources since only needed components are loaded (things like the logo and menu are not requested).
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.

3 comments:

  1. I'm back to tackling Jabba! This will be helpful. Thank you!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. PHPFox provided the best way to create very personal social network site like facebook, myspace etc. but what after creating the website. next step is to gain the popularity by using feature enable and disable module.no matter if you are technical or not. its very easy.give it a shot.for knowledge atleast.read more http://phpfoxexpertco.blogspot.in/2015/06/how-to-turn-on-and-off-your-phpfox-module.html contact us http://phpfoxexpert.co/contact-us/

    ReplyDelete