Nick Van der Vrekens blog & portfolio

AJAXed website - Automatically convert to AJAX website - com.bydust.ajax

October 17th, 2008

AJAX, Browsers, CSS, Javascript, Noteworthy, Projects, Themes, Wordpress

The com.bydust.ajax class is simply a javascript class that automatically converts your static website into a full-blown ajaxed website. Whenever a user visits your website, the class will perform a browser-check. If your visitor’s browser is capable of running the needed javascript, it will convert the website automatically. If not, the script deactivates itself and the visitor browses through your website as it is ( without ajax request etc. ).

You can download the script and view the howto at http://www.bydust.com/examples/com.bydust.ajax/

Basic implementation

The implementation of the javascript class is really easy, you just need to add a few lines of code into your pages. These will load and launch the script, and mark the area’s you want to refresh on each page. Look at the implementation page on the manual for more information.

Customizable animations

Yes, animations. Its only eye-candy, but it improves the style of your website alot, and the users impression of your website.
There are two types of animations available in the script, we have the tweens who smoothly fit your content into your page, and the alpha transitions which display your content with a nice fade in. As if that isn’t enough yet, these animations are customizable !
There are 13 types of tweens available, from normal easeIn or easeOut tweens to elastic and bouncy. There’s also an option to disable the tweens and alpha transitions, this might be good for large pages since they demand some CPU usage from the visitors computer. Don’t think you’ll need to disable tho :)

You can add more eye-candy in the customizable loading-messages, for example a nice loading image in gif-format or even little flash-movies. By adding CSS-styles in the loading-messages this can be very easy.

Functionalities

Its a bit more than your average “Hey-I-can-do-ajax”-script. With this script you can add event listeners, set up custom rules and custom animations, manage the filetypes handled by the script, and so on.

Attaching event listeners to certain events launched by the script allows you to execute certain pieces of code whenever an event happens, for example on errors ( but offcourse these never occur :) ) or page loads. Attaching an event listener is very easy, you can attach an event with one line of code. Just like in actionscript, we can use the “addEventListener”-function with the same two parameters, the event and the function to execute.

Custom rules allow us to tell the script to discard certain links or forms, or even to only notify the server when a user has clicked a certain link or posted a form. These rules can come in handy when you don’t want certain links to be parsed in ajax, for example feeds or trackbacks. When implemented in a Wordpress theme, you’ll need to add these rules for the wp-admin folder, feed and trackback links.

Error handling is often overlooked, but not here. The class is able to discover whenever an error occured, and will fix it when possible. If it notices that there is no way to fix the error, for example if one of the requested pages doesn’t have the information it needs, it will shut down itself and serve the page as a normal browser request, without any ajax. The ajax-class will then load again when the new page is fully loaded. If the script is able to fix the error, an error-event containing all information will be raised and an appropriate message will be shown. These messages are also customizable offcourse :)

Webpages often contain images, thats why I’ve built in some image preloading functions. When the ajax-class receives the new page from the server, it starts looking for images in the content areas that need to be refreshed. As long as its preloading, a ( customizable ! ) message will be shown to the user. When the images are fully loaded or the maximum load time has been reached the script will display the page. And, as you can guess, the maximum load time can also be specified by the user.

Since this is a pretty big project I’ve set up a small howto-website with loads of information about the script, and an example for you to download. You’ll find a detailed manual for the basic implementation there, along with the more advanced stuff.

The script is completely free for non-commercial use, but I’d like you to leave the credits in the classfiles and maybe a small link back to this page - if its not too much trouble. I’ll link back to your website if you’re using the script, so others have some more working examples. Contact me for commercial use :)

Com.bydust.ajax has been featured on several websites and communities:

Subscribe for updates

Please give us your email adress to unsubscribe.



There are 207 replies to this item:




XHTML:Please use "<pre>" to insert code: <pre lang="actionscript asp css html4strict javascript php sql xml[pick any of these languages]" line="45[starting line, optional]"> your code here </pre>

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  • #207

    August 14th, 2010

    JeFF says:

    Hi Nick

    i have this error when i finish write all the code in my website.

    “Please define the primary content region by putting an “!” in front of the id”

    FYI: i doing dynamic php content website.

    please help me where did i go wrong :(

    or can u chat in msn? i already added u in my msn.

  • #206

    March 13th, 2010

    lance says:

    hi.. great script… just wondering:
    - how can i delay the animation on the loading section until all the content is loaded?
    - how do i add gif in front of loading like this site has?
    - how can i make the page only resize to the new content and not shrink for the loading box?
    thanks,
    lance.

  • #205

    February 15th, 2010

    Erik says:

    Hi…

    I just posted my clients website with your ajaxed framework and I’m getting complaints the website is “showing up as text” at first and appears correctly after a refresh”. I myself haven’t seen this problem yet, but other viewers are.

    I am puzzled…

    The only reason I can think, I’m still posting the website through a sub domain for designing purposes.

    Could everyone take a look at this and see if the same problem occurs?

    http://www.naturalskin.com/ras/

    Many thanks.

    Cheers,
    Erik

  • #204

    November 23rd, 2009

    Caillou says:

    This is a very or js. I enjoyed it. I’m trying to put it into wordpress theme but it does not work. You can help me? This is my Gmail.

  • #203

    November 20th, 2009

    Jim says:

    Hi Nick,

    Just wanted to thank you…
    My whole website is now done, with additional api’s , like google search,translate, ive written em in jquery….

    Hope you like em…
    check it out here http://www.jobstriker.com

    Thanks for this…appreciate it!

    Regards,
    Jim.

  • #202

    November 15th, 2009

    Nick says:

    Hi Travis,

    the content is replaced because wrapping divs are added, in order to animate and replace the content. Links are also changed so they’d work with AJAX instead of the regular browser functions. (but this is done through the DOM, has nothing to do with the replacement)

    Cheers,

    Nick

  • #201

    November 12th, 2009

    Travis says:

    Hi Nick -

    Great script. I was curious why, in the initialization of the script, you are resetting the content of the primaryRegion with its own innerHTML content (line 159). Is the purpose of this to strip any previous event handlers from that content area that might conflict with your AJAX controller?

    Thanks,
    Travis

  • #200

    October 30th, 2009

    Nick says:

    Hi Maicol,

    if you need to trigger the AJAX via flash you can use some built-in classes to talk from flash to javascript (google). The getURL() function from Flash allows you to call HTML pages too as Sharon said.

    Sharon, thanks for the help :)

  • #199

    October 30th, 2009

    George says:

    Thanks, it worked.!

  • #198

    October 30th, 2009

    Sharon says:

    Hi George,

    Im sure Nick(the author) appreciates you like the script.

    I just tested it, YES! IFrames do work and get refreshed.
    You can add it to the refresh div, or in main content area.

    It will reload the HTML of the iframe within the div.
    No Javascript within iframe.
    However, the html you are calling within the iframe, may have javascript, it does not need to be parsed, it is just called.(reloaded)

    Hope this helps!

    If Im wrong, im sure Nick will correct me :)

    Regards,
    Sharon.