Activate your free membership today | Log-in

Thursday, June 30th, 2005

Ajaxian Faces Progress Bar

Category: Component, Java

Ed Burns (JavaServer Faces spec lead) has written his first Ajaxian JSF component: A progress bar

<d:progressBar id=”progressBar” value=”#{process.percentage}” interval=”1000″ />

It is based on “Greg Murray’s very useful but utterly non-componentized Progress Bar example”.

There is also an autocomplete Ajaxian Faces component.

Posted by Dion Almaer at 3:21 pm
6 Comments

+++--
3.6 rating from 51 votes

Pushlets and XHR

Category: Library

The Pushlets team has added Ajax to their HTTP-based publish/subscribe framework.

You can check out an example here.

In the code they have functions for the various events:

function leave() {
doRequest(’/pushlet/pushlet.srv?p_event=leave&p_id=’ + sessionID );
}

and then the typical XHR to access the pushlet server side:

function doRequest(url) {
// Create XMLHttpRequest object and open URL in async mode
xmlhttp = new XMLHttpRequest();
xmlhttp.open(”GET”, url, true);

// Response handler
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
onResponse(xmlhttp.responseText);
}
}
// No need to send body
xmlhttp.send(null);
}

and the meat in onResponse:

function onResponse(responseText) {
// Response is XML document: parse it using XParse
// Using XML DOM is too much hassle…
var xmlDoc = Xparse(responseText);

// XML document is parsed into tree of arrays, contents[0] is element
eventElements = xmlDoc.contents[0].contents;

// Go through all elements
for (i=0; i< eventElements.length; i++) {
nextEvent = eventElements[i];

// Determine action based on event type
eventType = nextEvent.attributes['p_event'];
if (eventType == ‘refresh’) {
// Pull mode: need to sleep and refresh
refreshURL = nextEvent.attributes['p_url'];
timeout = nextEvent.attributes['p_wait'];
setTimeout(”refresh()”, timeout);
} else if (eventType == ‘join-listen-ack’) {
sessionID = nextEvent.attributes['p_id'];
} else if (eventType == ‘leave-ack’) {
sessionID = null;
eventCount = 0;
}
}
}

Posted by Dion Almaer at 2:49 pm
Comment here

++++-
4 rating from 11 votes

Code: Try.these(func1, func2, func3)

Category: JavaScript

In the “cool JavaScript snippets” department, we delve into the Prototype library for a nice function which tries to fire and forget through a set of operations.

Defining Try.these

var Try = {
  these: function() {
    var returnValue;

    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }

    return returnValue;
  }
}

Example using the function

var Ajax = {
  getTransport: function() {
    return Try.these(
      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      function() {return new XMLHttpRequest()}
    ) || false;
  },

  emptyFunction: function() {}
}

Posted by Dion Almaer at 2:42 pm
2 Comments

++++-
4 rating from 10 votes

Wednesday, June 29th, 2005

Using CSS selectors to apply Javascript functionality

Category: Articles, JavaScript, Usability

Ben Nolan has written a nice piece called Using CSS selectors to apply Javascript functionality. He looks at Ajaxian showcases, and doesn’t always like the code that is mixed in the HTML.

He goes on to explain how to use CSS selectors to abstract this code out, giving you the other benefit of a clean graceful failback model.

For example, migrating from:

<li>
<a onclick=”this.parentNode.removeChild(this)” href=”#”>
Click me to delete me
</a>
</li>

to:

<ul id=”example”>
<li>
<a href=”/someurl”>Click me to delete me</a>
</li>
</ul>

And then use css selectors to select that <a> element and add javascript functions to it.

var myrules = {
‘#example li’ : function(el){
el.onclick = function(){
this.parentNode.removeChild(this);

}
}
};

Behaviour.register(myrules);

How important is this? Especially if frameworks are churning out the code for you?

Posted by Dion Almaer at 3:25 pm
7 Comments

++++-
4.6 rating from 9 votes

Tuesday, June 28th, 2005

Microsoft Atlas: Ajax all along

Category: Library

Microsoft got hit by the Ajax term like everyone else. They have been “doing Ajax” for a long time, as many companies had been, before the Ajax term took off. If you looked at ASP.NET 2.0 (Whidbey) you would have seen Ajax all over the shop. They have components that you can drag and drop in that use Ajaxian techniques.

They want the world to know that “WE DID AJAX!”, so they packaged together Atlas:

Microsoft’s Atlas is a “Web client framework” designed to make the job of building AJAX-style applications simpler, said Charles Fitzgerald, the company’s general manager for platform technologies.

“People who do (AJAX development) are rocket scientists,” Fitzgerald said. “In some ways, this papers over the mess that is JavaScript development. It’s easy-to-build ’spaghetti’ code.”

Atlas–which is a downloadable piece of JavaScript code–gives developers a more structured environment for building applications, providing time-saving services such as an object model and debugging, he said. It will work across any Web browser that supports AJAX technologies.

Read more

Microsoft Wants a Piece of the Ajax Action

Microsoft Plans An Alternative To Ajax

Microsoft Gets Hip to Ajax

Posted by Dion Almaer at 11:52 am
1 Comment

++++-
4.4 rating from 7 votes

Prototype and DWR: function $()

Category: JavaScript, Prototype

You may have seen $('someId') in some of the JavaScript frameworks out there such as Prototype and DWR.

We have had people wonder what kind of magic that is, and it is just a function. The name of that function just happens to be ‘$’, which is totally valid in JS.

Prototype, being nice and pragmatic, saw that there was a LOT of document.getElementById(element) all over the shop. So they give us the shorthand of $(element). A lot nicer :)

To see one implementation check out the DWR JavaScript docs.

function $()
{
var elements = new Array();

for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == ’string’) {
if (document.getElementById)
{
element = document.getElementById(element);
}
else if (document.all)
{
element = document.all[element];
}
}

if (arguments.length == 1) {
return element;
}

elements.push(element);
}

return elements;
}

Posted by Dion Almaer at 11:41 am
10 Comments

+++--
3.8 rating from 18 votes

Monday, June 27th, 2005

Grokking Prototype-based OO in JavaScript

Category: JavaScript

“JavaScript doesn’t seem very OO”. I hear that a lot. How far from the truth it is though. A lot of us are just trained to think that OO == CLASS BASED OO, which has won out in a lot of popular OO languages of late.

JavaScript is fully OO, and arguably more so than many other languages (everything is an object, thank god). It just so happens that Brenden Eich was a fan of Self, and choose to sent JS down the path of prototype based OO.

Take some time looking into the way that JS works. It is actually ridiculously elegant, and if you need to grok inheritence read the smart article Object Hierarchy and Inheritance in JavaScript.

Another way to grok this all, is to go to Glenn Vanderburg’s talk about JavaScript on the NoFluffJustStuff conference tour.

His opening intro is one of the best starts to a presentation I have ever seen. Absolutely classic.

Armed with the knowledge, you will find your head exploding as you realise the power that you have in JavaScript. You can change anything. Hence the quote that JavaScript is LISP with a different syntax!

Posted by Dion Almaer at 11:25 am
5 Comments

+++--
3.2 rating from 14 votes

Jazmin and JavaScript Minifier

Category: Utility

A blast from the past here. A lot of people are not aware of Douglas Crawford’s JavaScript Minifier which does what it says on the box:

JSMin is a filter which removes comments and unnecessary whitespace from JavaScript files. It typically reduces filesize by half, resulting in faster downloads. It also encourages a more expressive programming style because it eliminates the download cost of clean, literate self-documentation.

Think,

jsmin yourjsfile.js condensed.js

There has been a more recent port to C#, called Jazmin.

Posted by Dion Almaer at 11:13 am
2 Comments

++++-
4 rating from 6 votes

Friday, June 24th, 2005

Ajaxian Spell Checker 2.2 Update

Category: Examples, Library

Garrison Locke has updated his Ajaxian spell checker with a 2.2 release.

A few of the major updates to the spell checker are:

  • Added a Beta wrapper for aspell so you don’t have to have pspell installed.
  • Added a preview mode (with image support) so you can see it even if you don’t have misspellings.
  • Won’t interfere with other code that uses onClick.
  • Added fix for the magic quotes problem (more server compatibility).
  • Results and suggestion divs are now dynamically generated so you can have multiple spell checkers on the same page.
  • You no longer have to include spell_checker.php on every page if you dont’ want to.
  • Code will strip out code between html tags so that people can’t abuse the html feature.
  • Text box no longer flashes the updates after you hit resume text.
  • Various other bug fixes. See the change log for the whole list.

Nice work Garrison!

Posted by Dion Almaer at 9:39 am
2 Comments

+----
1.7 rating from 3 votes

del.icio.us direc.tor: An Ajax Web Service Broker

Category: Showcase

Johnvey Hwang has created an alternative UI for del.icio.us that enables you to browse all of your bookmarks in a more interactive fashion.

del.icio.us direc.tor uses the XML/XSL features of the browser to handle very large record sets. It works by downloading your entire bookmark file from the API, and managing it in the browser.

delicious-director.gif

Posted by Dion Almaer at 8:48 am
2 Comments

++++-
4.2 rating from 5 votes

JSCalc: When you really want to do math in the browser

Category: Showcase

Today’s Friday item is the JSCalc: the JavaScript calculator bookmarklet.

With this bookmarklet you will never have the feeling of:

Man, I need to do a quick calculation, but I don’t want to open Calc!

JSCalc

Posted by Dion Almaer at 8:42 am
1 Comment

+++--
3 rating from 7 votes

Showcase: Enviro - Swedish Ajaxian Search

Category: Showcase

A swedish search engine, Enviro, which uses Ajaxian techniques.

If you search for someone like ‘pettersson’ and the click on a result, you will see an example in action.

eniro.jpg

Posted by Dion Almaer at 8:37 am
1 Comment

+++--
3.3 rating from 4 votes

Thursday, June 23rd, 2005

Google AJAXSLT: Google opens up JavaScript code

Category: JavaScript, Library

The land of Google Code has released a little library used in their Ajaxian applications (such as Google Maps and Suggest). The first piece released is Google AJAXSLT.

AJAXSLT is an implementation of XSL-T in JavaScript, intended for use in fat web pages, which are nowadays referred to as AJAX applications. Because XSL-T uses XPath, it is also an implementation of XPath that can be used independently of XSL-T.

To be honest, I think it is a little funny that this JavaScript XSL/T library has Ajax in the name :)

There are also other XSL resources such as:

Great to see Google giving back in this way, hopefully we will see some real Ajaxian libraries and components soon :)

Posted by Dion Almaer at 10:53 am
2 Comments

+++--
3.7 rating from 9 votes

script.aculo.us: JavaScript Libraries

Category: JavaScript, Library, Prototype, Ruby

Thomas Fuchs has given birth to: script.aculo.us. (Note to self. Must. Kill. .us domains that make words).

script.aculo.us provides you with easy-to-use, compatible and, ultimately, totally cool JavaScript libraries to make your web sites and web applications fly, Web 2.0 style.

script.aculo.us builds on Prototype, and gives you interesting items such as:

  • Visual Effects: The core effects are Effect2.Opacity(), Effect2.Scale(), Effect2.MoveBy() and Effect2.Parallel(). They get combined to give you: Appear, Fade, Puff, DropOut, Shake, SwitchOff, BlindDown, BlindUp, SlideDown, and SlideUp.
  • Drag And Drop: “Want some more user interaction than the same old INPUT elements and drop-downs? How about drag-and-drop with built-in support for sortable lists, floats and AJAX serializing?”

Great to see libraries like this making app developers lives so much easier.

Posted by Dion Almaer at 12:33 am
2 Comments

++++-
4 rating from 6 votes

Trapping the Tab

Category: Usability

The more I use the new Ajaxified del.icio.us the more I like it.

I had a “duh” moment when I realised that you could tab complete tags.

This brought up a usability issue. On the web we are trained to think:

Tab == Go To Next Field (or element if not in a form)

I think that del.icio.us and anyone trapping the tab (and others) need to follow the rules of:

  • Is it REALLY smart to trap a tab here. Do I add value.
  • If it makes sense, then I need to indicate to the user that “For One Nite Only, TAB == something else!”

What do you think?

Delicious Tab

Posted by Dion Almaer at 12:20 am
9 Comments

++---
2.5 rating from 2 votes

Wednesday, June 22nd, 2005

Showcase: Image Panning and Dragging

Category: Showcase

Michal Migurski has put up a Giant-Ass Image Viewer showcase, which shows how to pan and scan a la Google Maps.

This is a draggable, zoomable satellite mosaic of Antarctica that Eric found. (This space used to have a print from Ernst Haeckel’s Kunstformen der Natur, but the current image is 4x larger) Please use Mozilla, Opera or Safari to view. I’m getting closer to getting this working in IE, mostly by accident - as soon as I have a chance to see why IE complains about killing the onmousemove handler, it’ll be pretty much done.

It doesn’t seem too happy when it comes to clicking and such, so it moves around like crazy sometimes.

There is a python script that takes the roll of splitting up the main image into the small square pieces that get painted.

Posted by Dion Almaer at 2:29 pm
3 Comments

+++--
3.4 rating from 10 votes

Next Page »