Anonymous
Domino 2.0 Rich Internet Applications with IBM Lotus Notes/Domino
You are here: Today » And there was Ajax... unobtrusively entering Domino 2.0 blog
« Adding a user registration system to my blog
Essence of a Domino hosted website »

And there was Ajax... unobtrusively entering Domino 2.0 blog

Ajax is not only fetching data from the server without reloading the page. It's also adding behaviours to the page after it is loaded. I am a strong believer of unobtrusive javascript (progressive enhancement). All basic functions of this blog will still work if you turn off JavaScript or CSS. I also tried my best to write my JavaScript 'the Ajax way'.

The core functions

Nowadays, writing JavaScript is far from coding functions like:
function doSometing(a){alert('I'm doing something with '+a)}
It's all about object oriented programming, avoiding global namespace pollution and JSON. So I picked one namespace: 'Mme' (some characters of my name) as a Factory object for my coding:

This gives me access to three very useful functions:

I also enhanced the String object a bit using my new Mme.extend function:

Next thing is adding generic functions to bind JavaScript behaviour to specific HTML elements. For this, each behaiour has a 'pattern' property, same as a CSS rule but very limited for performance reasons:

So I extended my Mme factory with .init to initialize the Mme, .initLib to initialize a module and .getRange to get the HTML elements that correspond with the pattern.

To finish it off, I launch the Mme.init() when the document is loaded:
window.onload=function(){Mme.init()}. And now the behaviours.

Making links open in another window

One of the first things my boss noticed when he looked at my blog, was that all links opened up in the same window. So if he clicked on a link, he would loose my site. This had a reason: in XHTML, the target attribute of a hyperlink is forbidden. So we need JavaScript to help. When links have the className external, they should open in another window:

Protecting e-mails

On my Tangosite, I used to display the e-mail addresses from people who signed my guest book. But not for long: someone scraped all the e-mail addresses of my site and used it to spam. So it's a very good idea to hide the addresses. I change them into "my DOT name AT mycompany DOT org" and change them back to real e-mail addresses with this behaviour:

So here's my e-mail address, in case you want to send me feedback. Keep in mind that I hardly ever respond to e-mails, unless I know you very well or my job is at stake ;-)

Striped tables

Oh well, everybody loves striped tables, no? Give any table the className stripe and it will get striped even before you can say 'unobtrusive javascript'.

stripestripe
stripestripe
stripestripe
stripestripe
stripestripe
stripestripe
stripestripe
stripestripe
stripestripe

Where's the zip you can download? There is none for the moment. It will be available for registered users. I'm still working on the registration. Don't panic: it will be free. I just want to know you before I give you my car keys and let you drive my car :-))

Star rating

0%

Comments

  1. 03/11/2006 17:14:10, Dimitri Baudonck

    Like this article, love the mailto-solution. Will use this definitely.

To add a comment, log in or register as new user. It's free and safe.