Professional Documents
Culture Documents
• Widgets
• Libraries
• Raw JavaScript
What we’ve just seen...
• Widgets
• Libraries
• Raw JavaScript
Why use a library?
Prototype
Browser jQuery Backbase
Only Yahoo UI SmartClient
Dojo
What kind of libraries exist?
Open Source Commercial
Atlas
Client/ AjaxCFC
Backbase for
Server Qcodo
Struts
Prototype
Browser jQuery Backbase
Only Yahoo UI SmartClient
Dojo
Open Source Libraries
Browser Only Client/Server
Scriptaculous
Task AjaxCFC
moo.fx
Specific Qcodo
Open Rico
Prototype
General jQuery Ruby on Rails
Purpose Yahoo UI CakePHP
Dojo
Open Source Libraries
Browser Only Client/Server
Scriptaculous
Task AjaxCFC
moo.fx
Specific Qcodo
Open Rico
Prototype
General jQuery Ruby on Rails
Purpose Yahoo UI CakePHP
Dojo
Why these libraries?
Ajaxian Survey
Prototype jQuery Yahoo UI Dojo
20%
35%
21%
25%
http://ajaxian.com/archives/ajaxian-2007-survey-results
Google Trends
Prototype
jQuery
Dojo
Yahoo UI
http://google.com/trends?q=prototype+javascript%2C+jquery+javascript%2C+yui+javascript%2C+dojo+javascript&ctab=0&geo=all&date=all&sort=0
The Libraries
Prototype
Prototype: Overview
• Good Architecture
• Open Licensing
• Wide Browser Support
• Small File Size
Project
• Traversal
• Using CSS selectors to locate elements
• Modification
• Create/remove/modify elements
• Having a DOM builder is important
DOM Traversal
• Prototype:
$$(“table > tr”)
• jQuery:
$(“div > p:nth-child(odd)”)
• Dojo:
dojo.query(“table tr:nth-child(even)”)
• Yahoo UI:
No querying support
DOM Modification
• Prototype:
Insertion.Bottom(“list”,”<li>Another item</li>”);
• jQuery:
$(“#li”).append(“<li>An item</li>”);
• Yahoo UI:
YAHOO.util.Event.addEventListener(“list”, “click”, function(){
alert(“List Clicked”);
});
• Dojo:
dojo.connect(dojo.byId("mylink"), "click", function(){
alert(“Link clicked”);
});
Custom Events
• $(“#list”).bind(“drag”, function(){
$(this).addClass(“dragged”);
});
• $(“#test”).trigger(“drag”);
Ajax
• Request and load remote documents
• Prototype:
new Ajax.Request(“test.html”, {
method: “GET”,
onComplete: function(res){
$(‘results’).innerHTML = res.responseText;
}
});
• jQuery:
$(“#results”).load(“test.html”);
Ajax (cont.)
• Yahoo UI
YAHOO.util.Connect.asyncRequest(
'GET', “test.html”, function(data){
YAHOO.util.Dom.id(“results”).innerHTML = data;
}
);
• Dojo
dojo.io.bind({
url: "test.html",
method: "get",
mimetype: "text/html",
load: function(type, data) {
dojo.byId(“results”).innerHTML = data;
}
});
Ajax (cont.)
• jQuery is only one capable of doing DOM
traversing over XML
• jQuery.get(“test.xml”, function(xml){
$(“user”, xml).each(function(){
$(“<li/>”).text( $(this).text() )
.appendTo(“#userlist”);
});
});
Animations
• Simple animations (hide/show/toggle)
• Provide elegant transitions
• No animations in Prototype Core (see
Scriptaculous, instead)
• jQuery:
$(“#menu”).slideDown(“slow”);
Animations (cont.)
• Yahoo UI:
new YAHOO.util.Anim(“list”, { width: { from: 10, to: 100 } }, 1,
YAHOO.util.Easing.easeOut
);
• Dojo:
dojo.fadeOut({ node: dojo.byId(“list”), duration: 500 });
Core Feature Summary
DOM Events Anim. Ajax
Prototype X X - X
jQuery X X X X
Yahoo UI / X X X
Dojo / X X X
User Interface Widgets
• ejohn.org <-- slides
• Difficult to implement components, made
easy
• Commonly used, save duplication
• Some common components:
Drag & Drop, Tree, Grid, Modal Dialog,
Tabbed Pane, Menu / Toolbar, Datepicker,
Slider
User Interface Packages
• A navigable hierarchy
(like a folder/file
explorer)
• Good Architecture
• Open Licensing
• Wide Browser Support
• Small File Size
Architecture
• Bottom Up (Prototype, jQuery)
vs. Top Down (Dojo,Yahoo UI)
• jQuery, Dojo, and Yahoo UI all use a single
namespace
• Prototype extends native objects (high
likelihood of inter-library conflict)
• jQuery is extensible with plugins
Licensing
• Everyone supports:
IE 6+, Firefox 2+, Safari 2+, Opera 9+
• Except:
• Prototype doesn’t support Opera
• Dojo is dropping support for Safari 2
File Size
• Serving your JavaScript minified + Gzipped
• Optimal level of compression and speed
•35.00Core file size (in KB):
26.25
17.50
8.75
0
Prototype jQuery Yahoo UI Dojo
Project
• jQuery:
• Learning jQuery (Packt)