jQuery - Write less, Do more
Print Browser View
jQuery
WELCOME!!!! This is the notes slide where I will write about things I am going to talk on.
What is it?

A JavaScript Library

jQuery.com
It is a free and open source (MIT and GPL) that is ~55k in size (minified).
Why do we need it?

Seperation of Concerns
Before/After

<a href="#" onclick="alert('hello');"><font color="#ff0000"><strong>Click Me</strong></font></a>
                            
<!-- CSS: Same file or different -->
.clicker
{
    color: #FF0000;
    font-weight: bold;
}

<!-- JavaScript: Same file or different -->
$(document).ready(function(){
    $(".clicker").click(function(){
        alert('hello');
    });     
});

<!-- HTML -->
<span class=”clicker”>Click Me</span>
                            

"Hell is other Browsers"

Additional Functionality

Seperation of concerns is a web dev principal. We have been using it for years with seperating the concern of content (i.e. HTML) and display (i.e. CSS). It's logical that we do the same with JavaScript, we seperate it from the html. What does that mean? Seperate JavaScript files? Not at all - think the onclick event handler on almost anything in HTML, that is tightly linking the javascript to the element - even if it calls a javascript method in a seperatye file. Seperation means that something externally attaches the javascript to the element at runtime, like CSS does for design.

Browser compatibility is another issue - different browsers have both a different DOM, and JavaScript engine. Compatibility is tough - so jQuery (tries) to hide the differences from developers. It is not perfect, as I found out with KeyPress issues in FireFox (bug #3311 and $(document) vs $(body)), but it is better than starting off yourself.

Additional functionality like the ability to have a foreach loop.

Stamp of Approval
Development High Profile Usage
Microsoft
  • PSS Support
  • VS 2008 support for it
  • Bundled in VS 2010
  • Bundled in ASP.NET MVC
Nokia
  • Plans to include in Web Run-Time Platform
Google
  • Part of their hosted libraries
Match
Google
Amazon
Twitter
NBC
MLB
Bank of America
Technorati
Salesforce
Monster
xerox
jQuery isn't just some proof of concept or an idea waiting for it's time - it's got major support and implementations.
Microsoft is supporting it by providing support via Product Support Services, VS 2008 has intellisense support for it, ASP.NET MVC and SharePoint 2010 and VS 2010 will ship with it.
Nokia will include it in their web run-time platform which is their gadget framework.
Google actually hosts it, so you can use their hosted one instead of hosting it yourself.
It is also included in a number of large sites.
Demo
<span>Some text in a paragraph tag</span>

<span>Some more text in another paragraph tag</span>

<span id="span1">Last text in a paragraph but has an id</span>
Selector:

Some things to try:

  • span
  • #span1
  • span:first
  • span:odd
  • span:contains("more")
  • span:lt(2)
  • span:#span1

View Code
$(document).ready(function() { 
    $("#demo1input").keyup(function(e) { 
        $($("#demo1input").val()).css("background-color","yellow"); 
    }); 
});
                            
Ajax

Ajax not AJAX

Crossing the boundary

AJAX is Async JavaScript And XML, while Ajax is the modern thinking where the X isn't XML - it could be something like JSON.

Going across domain boundaries is a tough problem - how do i get results outside of my domain? From 1.2+ jQuery allows you to go over domain boundaries because of a cool callback system.

Demo

JSON Data: json.txt

View Code
$(document).ready(function() {
    $("#demo2Button").click(function(e) {
        $.getJSON("json.txt", function(data) {
            var message = "Welcome :" + data.firstName;
            $.each(data.website, function(i, value) {
                message += "\n<br/>Website " + i + ": " + value;
            });
            $("#demo2SampleArea").append(message);
        });
    });
});
                            
Effects

15 Effects - show, hide, slide in, slide out etc...

Toggling with one function

Callbacks

15 effects, including a custom animation solution is available which makes an easy to build your own.
Most effects can be toggled with a the cool toggle method, this makes it very easy to apply them and then switch them on/off on buttons and such.
Another nice feature of effects is the ability have a callback method, so that when the effect is completed specific code can be run post an event.
Extending

jQuery object and function level support.

View jQuery Object Plugin Code

jQuery.fn.debug = function() {
  return this.each(function(){
    alert(this);
  });
};
                            

View jQuery Object Plugin Usage

$(":submit").debug();
                            

http://plugins.jquery.com
jQuery offers a mechanism for adding in methods and functionality, bundled as plugins. Most of the methods and functions included in the default download are written using the jQuery plugin construct.
Using jQuery.extend you can also extend things in jQuery itself, like adding new selector options.
jQueryUI

UI is a optional plugin

jQueryUI.com
UI is an offical (developed by different team though) and massive plugin which is meant to allow jQuery to build interfaces, so it contains more advanced interface components than HTML normally has, things like dialog boxes (seen in the demos), sliders, tabs, date pickers, progress bars, accorions (like Outlook) and drag&drop solutions.
It also extends the effects library a lot by adding 10+ effects.
It is also fully themed using CSS and images. Available is approx 20 themes plus there is also a custom theme builder available online to tailor it specifically as needed.
If there is one part I think that is most important for business apps, this is it.
jQueryUI & Effects Demo
Slider:
Progress Bar:

Date Picker:

View Code
$(document).ready(function() {
    $("#demo3Tabs").tabs();

    $("#demo3ProgressBar").progressbar();

    $("#demo3Slider").slider({
        change: function(event, ui) {
            $('#demo3ProgressBar').progressbar('option', 'value', $('#demo3Slider').slider('option', 'value'));
        }
    });

    $("#demo3DatePicker").datepicker();
});
                            

Puff Out/ Puff In

Fold Out/ Fold In

View Code
$(document).ready(function() {
    $("#demo4PuffOut").click(function() {
        $("#chastingStarsImage").hide("puff");
    });

    $("#demo4PuffIn").click(function() {
        $("#chastingStarsImage").show("puff");
    });

    $("#demo4FoldOut").click(function() {
        $("#chastingStarsImage").hide("fold");
    });

    $("#demo4FoldIn").click(function() {
        $("#chastingStarsImage").show("fold");
    });

    $("#demo4Pulsate").click(function() {
        $("#chastingStarsImage").effect("pulsate", { times: 3 }, 1000);
    });
});
                            
You can drag me around
I am a drop target.
I'll say something interesting if you drop on me

View Code
$(document).ready(function() {
    $("#demo5Draggable").draggable();
    $("#demo5Droppable").droppable({
        drop: function(event, ui) {
        $("#demo5Droppable").html("<strong>I lied - nothing interesting</strong>");
        }
    });
});
                            
  1. First Version - It is great
  2. Second Version - First version rewrite
  3. Third - First stable version
  4. Forth - First version with new features
  5. Fifth - Finally getting great

View Code
$(document).ready(function() {
    $("#demo6Selectable").selectable();
});
                            
Limitations
No offline storage.

Thanks to http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
Thanks to the Wikipedia I can compare the jQuery with other frameworks and see where it falls short compared to other frameworks and the only option that is missing is that of offline storage.
Offline storage is like Google Gears, which Dojo and the Google Webtoolkit both use. Ext also supports Gears, but also Adobe Air.
Glimmer

Build effects easier

Free tool from Microsoft

Detailed review: http://www.sadev.co.za/node/356

Glimmer is a free tool from Microsoft created to make working with jQuery effects easier. It contains 3 wizard interfaces: Create tooltip, create menu and image roller. It also contains an interface for building custom ones.
It is (IMHO) a beta tool though because of a lot of UI issues and bugs.
Demo
About

Entire presentation built in HTML & jQuery

Everything (exluding images) ~100k

Less than 100 lines of JavaScript for all slide show functionality

Q&A