Tag Archives: Notes

Notes for “Advanced jQuery” by John Resig

I just finished watching John Resig’s talk titled “Advanced jQuery” which he gave at Ajax Experience. Like I said before, I am posting notes which I took while watching the video, so that I can refer to them at a later point of time (It is easier to search when it is not on paper 🙂 ). Also it might help someone to get the outline of the talk before actually watching the video. The original video runs for more than an hour.

Also be warned that the following is my own interpretation of the video and I might have missed or could have interpreted some point differently. 🙂

About the speaker, John Resig

As you all know John Resig is the creator of the excellent jQuery library. He works for Mozilla corporation and you can get more information about him from his blog.

Some Advanced features of jQuery

Chaining

The most useful and the powerful feature of jQuery. (Personally this is my favorite feature in jQuery). Every function in jQuery returns the jQuery object and you can continue to call functions on that object. end() stops chaining andSelf() adds the current element into the chain.

Isolation

Once of the design goal of jQuery is that, jQuery should not affect or get affected on any HTML page, no matter what is present in the HTML page, either another library or even another version of jQuery itself. The only exception is when a new property is added to object.prototype.

Isolation in jQuery is achieved by the following

jQuery Wrapper

Everything in jQuery is wrapped. Only the $ function and the jQuery variable are exposed.

Plugin Wrapping

All Plugin code should be wrapped between

(function($) {

})(jQuery);

noConflict

Even the global jQuery variable can be unrolled by using jQuery.noConflict(true). This allows two versions of jQuery to run on a single HTML document without any conflict.

Sizzle

Sizzle is a selector engine written by John in pure JavaScript. It is around 1.5x to 4x faster and the major advantage of sizzle is that it can be integrated with other libraries, since it doesn’t have any dependency on jQuery.

Sizzle works from backwards while selecting and is therefore faster in most cases. It also caches the DOM tree and frees it by listening to the DOMAttrModified, DOMNodeInserted and DOMNodeRemoved events.

Sizzle has a separate homepage and you can get more information from it’s homepage.

DOM Manipulation

By far, most time of a script execution is spent only in DOM Manipulation.

jQuery automatically converts single tags to double tags using the following function. (I never know this before. The function seems to be very precise and well thought of)

elem = elem.replace(/(<(\w+)[^>]*?)\/>/q, function (all, front, tag) {

return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? all : front + "></" + tag + ">";

}

jQuery 1.3 uses document Fragment for DOM manipulation and is much faster when compared with older versions.

Events

In jQuery you can bind event to any JavaScript Object.

Namespaced Events

From jQuery 1.2, Plugins can use namespaced events. The major advantage in using name spaced events is that it is very easy to clean up later and uses less memory space.

Special Events

From jQuery 1.2.2 some special events are available for easy event handling.

Events like mouseEnter, mouseLeave and mouseWheel are not actual events but are exposed by jQuery. jQuery does the internal implementation for these events.

Video

So my dear readers what you think about my notes. Also let me know if you like notes for videos in this format. If there is a demand, then I can post some of my notes on other videos which I have already viewed.

Posted in JavaScript/jQuery | Tagged , , , , | 2 Comments

Summary of Google Wave Keynote video

After watching the Google I/O keynote video about Google Wave, I got really excited Google_Wave_logoabout it and have been talking about Google Wave to most of my friends and colleagues. Some of them asked me to explain about it. I tried, but I am not sure whether I fully succeeded. 😉 In the end I said, go watch the keynote video and after sometime they replied, “Damn! it’s about 80 minutes long and do you have a summary”. And so guys here is the summary of the Google Wave keynote video given at Google I/O.

Google Wave

Google Wave is a product that helps users communicate and collaborate on the web. A “wave” is equal parts conversation and document, where users can almost instantly communicate and work together with richly formatted text, photos, videos, maps, and more.

People behind Google Wave

Google Wave is the brain child of two bothers from Sydney, Lars Rasmussen and Jens Rasmussen who were the original developers of Google Map. You can also know about the Google Wave team from the team bio pages.

Just a developer preview

Google wave has been under development for more than one and a half years now and it might take another year before a beta version is released for the outside world. This is the first time, people outside Google are seeing the demo. The reason for showing the demo now is to woo the developers and to build an ecosystem around it. Google Wave was fully developed using Google Web Toolkit and the code is going to be released to the open source world.

3Ps

The presentation consists of three parts

  • Product
  • Platform
  • Protocol

Product

Email is the most used communication tool of the present day internet. But email was created around 40 years back, before the internet was developed. The internet has evolved and the network has improved in these 40 years, but email is not taking advantage of them.

Google wave is what email will look like if it was developed today. It is the new way of communication in the internet.

Every typed character is transmitted in real time

Traditional email works like snail mail, but Google wave is real-time. At this point, they showed a demo of Google wave, where every character typed by one person is visible to the other person in real time, without waiting for the Done button to be clicked. Google wave is transmitting a packet for every character that is typed, and it can be disabled if needed. (This was my first wow movement 🙂 ). See the demo.

Google_Wave_concurrent_edit

Step by step playback

When a new person is added to the wave (conversation) he can playback all the changes that have been done from the time it was created. You cannot understand it unless you see the demo. (This was my next wow movement). See the demo.

Drag and Drop attachment

Adding attachments to the wave is as simple as drag and dropping them. When a image is dragged and dropped, even the thumbnail is transmitted in real-time to the other person. If the caption is changed, even that will be reflected in real-time. See the demo.

Platform

Google Wave can also be considered as a platform with a rich set of open APIs that allow developers to embed waves in other web services. They can also build new extensions that work inside waves. More information about the Google wave API can be found at Google wave API page.

Most of the features of Google Wave are developed as extensions. The following are some of these extensions.

Bloggy

Bloggy is an extension which acts like a blog client. Bloggy lets you make a blog post as a wave. These posts reflect the state of the wave in real-time and when people comment, they join the conversation and these conversations are immediately reflected in the wave and the blog post.

Spelly

Spelly is an extension which acts as a spell-checker. Spelly not only compares the current word but it is contextual and checks the entire sentence before offering suggestions. It uses the entire corpus of the web as its dictionary.

Google_Wave_spelly_steh

Linky

Linky is a link-recognition engine that is clever enough to recognize that the link you just entered is a YouTube video, or a link to a photo, and give you the option to embed the target of the link into the wave.

Buggy

Buggy is a bug-reporting tool. When Buggy is added as a participant in a wave, it can be used to file bug reports directly from the wave.

Polly

Polly is an extension which lets you to incorporate polls into a wave. In the wave shown below, participants are asked whether they can make it to a party. As soon as someone replies the responses appear immediately in the wave.

Google_Wave_yes_no_maybe_inbox

Game and Twitter Extension

There is an extension for embedding interactive games like chess in a wave and also an extension to integrate your tweets.

Google_Wave_inbox_chess

Protocol

The Google Wave protocol is the underlying format for storing and sharing waves. This includes the “live” concurrency control, which allows edits to be reflected instantly across users and services. The protocol is designed for open federation, such that anyone’s Wave services can interoperate with each other and with the Google Wave service. This means that anyone can operate their own wave server and it can interoperate with other wave servers. To encourage adoption of the protocol, Google will open source the code behind Google Wave. More information about Google Wave protocol can be found from the site dedicated to wave protocol.

Video

Hope I have given a good summary of the video. But in order to fully experience the “wow” movement, you must watch the video. I have embedded the video below.

Links

Some useful links about Google Wave.

Credits

Screenshots and Video from Google.

Posted in Google/Yahoo | Tagged , , , | 7 Comments

Notes for “DOM is a mess” by John Resig

I just finished viewing John Resig’s talk titled “DOM is a mess” at Yahoo. I took some notes while watching the video and I am posting them here, so that I can refer to them at a later point of time (It is easier to search when it is not on paper 🙂 ). Also it might help someone to get the outline of the talk before actually watching the video. The original video runs for more than an hour.

Also be warned that the following is my own interpretation of the video and I might have missed or could have interpreted some point differently. 🙂

About the speaker, John Resig

As you all know John Resig is the creator of the excellent jQuery library. He works for Mozilla corporation and you can get more information about him from his blog.

DOM is a mess

This is the first thing John Resig said about DOM methods after saying that DOM is a messy

Nearly every DOM method is broken in some way, in some browser.

The following are some of the bugs in the DOM methods

getElementByID ()

IE and Old versions of Opera return elements whose name == id

getElementByTagName ()

.length gets overwritten in IE if an element with an ID = “length” is found

getElementsByClassName ()

Opera doesn’t match a second specified class

querySelectorAll ()

Safari 3.2 can’t match uppercase characters in quirks mode.

So the moral is that almost every method in DOM is messed up.

Writing Cross-browser code

Find out the cost/benefit ratio for supporting a browser and then pick the browsers you are going to support before writing your code.

He talked about Yahoo’s graded support and jQuery browser Support.

Escaping from DOM’s mess

The following are some of the tips to escape from DOM’s mess.

  • Having a good test suite is not a facility but a requirement.
  • Don’t introduce global variables or extend native objects.
  • The order in which style sheets are included matters.
  • Don’t use browser sniffing, but use Object detection or feature simulation instead.
  • Don’t assume a browser will always have a bug. They might get fixed in a future release.
  • Gracefully degrade for old browsers
  • As your code matures, the number of assumptions should reduce.
  • While removing elements from DOM, clean it by unbinding the events

Links

So my dear readers what you think about my notes. Also let me know if you like notes for videos in this format. If there is a demand, then I can post some of my notes on other videos which I have already viewed.

Posted in JavaScript/jQuery | Tagged , , , , , | 1 Comment