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

WordPress Plugin readme generator now supports changelog

One of the most missed features in the official WordPress Plugin repository is the ability to specify the change log for your Plugins. There was no unified way for the Plugin developers to specify the changes that were made to the Plugin in each version.

Thanks to some great work done by Peter Westwood and Mdawaffe, we now have support for changelogs in the WordPress Plugin Readme standard. The information specified in the changelog will be displayed in a separate tab in the WordPress extend pages like shown in the below screenshot from WTC.

Changelog in Action

Since it has become as part of the readme file standard, I have added support for changelogs to my WordPress Plugin readme generator which I have released sometime ago. Now you can create readme files for your Plugins with changelogs using the WordPress Plugin readme generator. Try it out and let me know if you face any issues or have any suggestions.

Posted in WordPress | Tagged , , , | 3 Comments

When PR mange the company’s Twitter account

This is what happens when a company’s Twitter account is managed by PR.

dna

Update: Okay it seems that this Twitter account is not run by PR but by Journalists.

Posted in Random/Personal | Tagged , , | 5 Comments

Joining Yahoo

Well guys, got some good news for you all. I am joining Yahoo Research, Bangalore next week.

I am relocating to Bangalore and may not be available online for a couple of days, so if you have sent an email, you may have to wait for some more time for reply.

This is the first time in my entire life, I am leaving the comfort of my home and Chennai, so a little nervous about it. But I guess everything should be fine once I get settled there.

So Bangalore, here I come 😉

Posted in Random/Personal | Tagged , , | 17 Comments

Moved to Linode for hosting

Long time readers of my blog will know that I moved to Slicehost around 15 months back. I was pretty happy with their service, but now I have left them and have moved all my sites to Linodelinode_logo_gray

Both Slicehost and Linode are good but when compared with Linode, Slicehost was slightly costlier. I realized it after reading the comparison done by David. I bought an account in Linode for testing and was quite happy with it. But I was lazy to move all my sites, since it involved some work.

The recent announcement by Linode to give 33% additional disk space wooed me enough and I gave in. 🙂

Now I am getting some additional features with Linode but for less cost. 😉

Posted in Unix/Server Stuff | Tagged , , | 4 Comments

Updated FeedBurner stats Google Gadget

I have updated my FeedBurner stats Google Gadget, to change the API endpoint to feedburner.google.com. If you have already added the gadget to iGoogle or have embedded it in your web pages, the changes will apply automatically and you don’t need to change anything.

The Gadget ceased to work after Google changed the API endpoint and it should continue to work after this change.

The full source code of this gadget is available here and if you are interested you can add it to your Google personalised page by clicking this button. Add to Google

Let me know if you still face any issues with the Gadget.

Posted in API's/Mashup | Tagged , , | 2 Comments

Exciting new features for developers in WordPress 2.8

Update: WordPress 2.8 is out now. Update at your earliest and enjoy 🙂

WordPress 2.8 is tentatively scheduled to be released on June 10. Even though there are no major new features, there are certain features that will be exciting for WordPress developers like me 🙂grey-l

I am listing out some of them below.

Custom Taxonomies

WordPress 2.8 is going to support custom taxonomies in addition to the three built-in taxonomies category, tag and link_category. I am very excited about this, because when a new taxonomy is added, WordPress 2.8 will automatically add meta boxes in the Write Post page and will also add new Admin menus to handle them. Justin Tadlock has written article where he describes custom Taxonomies in detail.

New Widget API

There is going to be a new and improved API for writing widgets in WordPress 2.8. Right now creating widgets, especially multi-instance widgets is complex.

In WordPress 2.8, there is going to be a new class called WP_Widget which will abstract most of the complexity involved in creating widgets. This new class supports both single and multi-instance widgets. Justin Tadlock has also written an excellent guide which explains how widgets can be created using the new widget API.

Enhanced code Editor

The Plugin and theme editors have been enhanced tremendously. They now have support for syntax highlighting and function lookup. Personally, this is a great news for me because I edit most my Plugins using this editor and syntax highlighting will surely help me to do it quickly.

wordpress-plugin-editor

Promotion to migrate to PHP 5

Even though WordPress 2.8 will continue to support PHP 4, the automatic upgrader will suggest those running PHP 4 to switch to PHP 5. It will also link to a Codex page describing how to switch for various hosts should be provided. At last there are symptoms of light at the end of the tunnel 😉

Authentication more pluggable

Even though the support for oAuth has been moved to 2.9, the initial steps towards the integration have been done and now the authentication code of WordPress is more pluggable.

SimplePie in core

SimplePie, the well know PHP library for RSS parsing is going to be included in the core. This is going to be great news because, this will make available the power of RSS parsing to all Plugins without installing the SimplePie core Plugin.

Loading JavaScript in footer

The high performance website rule states that we have to push JavaScript to the footer for better performance. WordPress 2.8 now makes it possible for Plugins to specify whether a script should be included in the header or in the footer. Isn’t that exciting? 😉

Other minor exciting features

In addition to the above major features, WordPress 2.8 also has the following features which may be of interest to developers.

  • Filters for AIM, Yahoo, and Jabber IM labels, in user profile, so that, they can be changed via Plugins.
  • New hook “after_db_upgrade”, which you can use to add upgrade functions for your Plugin.
  • Added support for blocking all outbound HTTP requests via Plugins.
  • Ability for a Plugin to control how many posts are displayed on edit pages.
  • Support for proxy. Helpful, if your installation is in an intranet.
  • Menus can be reordered via Plugin

Update libraries bundled with WordPress

The following are the libraries (with their version numbers) that are updated in WordPress 2.8

  • TinyMCE – 3.2.4.1
  • jQuery – 1.3.2
  • Jcrop – 0.9.8
  • pclzip – 2.8
  • PHPMailer – 2.0.4
  • SWFUpload – 2.2.0.1

I am pretty excited about WordPress 2.8 and eagerly waiting for it. If you want to get your hands dirty with it right now, you can try out WordPress 2.8 Release candidate 1.

Update: WordPress 2.8 is out now. Update at your earliest and enjoy 🙂

Posted in WordPress | Tagged | 2 Comments

Making Yahoo Pipes feed work in wp-o-matic

Recently I was playing with wp-o-matic WordPress Plugin using a feed from Yahoo pipes. For the uninitiated, wp-o-matic is a WordPress Plugin which enables you to create new posts automatically from RSS or Atom feeds and Yahoo pipes is an interactive feed aggregator and manipulator.

After configuring everything, wp-o-matic kept on saying “0 posts fetched”, even though there were some posts in the feed generated by Yahoo pipes. After some research, I found out that I was not the only one facing this issue and there seems to be a bug in wp-o-matic which breaks feed urls having ampersand (&) character.

After digging into the code further, I found out the url is HTML encoded and stored in the database and is not decoded while retrieved. This occurs in the addCampaignFeed() function at line 1011 in the wpomatic.php file.

function addCampaignFeed($id, $feed)
{
    global $wpdb;
    $simplepie = $this->fetchFeed($feed, true);
    $url = $wpdb->escape($simplepie->subscribe_url());
    // code continues

In the above code, the function $simplepie->subscribe_url() returns the html encoded url. So to fix this, we have to pass the url to the htmlspecialchars_decode function. So to fix the bug we have to use the below code.

function addCampaignFeed($id, $feed)
{
    global $wpdb;
    $simplepie = $this->fetchFeed($feed, true);
    $url = $wpdb->escape(htmlspecialchars_decode($simplepie->subscribe_url()));
    // code continues

I have also notified the Plugin author about this and hopefully should be fixed soon, till then you can use the above code change if you are using feed from Yahoo pipes.

Posted in WordPress | Tagged , , | 21 Comments

Google Wave related videos

My crush for Google Wave didn’t stop by watching the Google Wave keynote video alone. I watched other videos related to Google wave and thought of indexing them here, so that it may be of help to others like me 🙂

First is the granddaddy of all, the Google I/O keynote video

Technical Details about Google Wave

Programming With and For Google Wave. Google I/O video, which explain how to use Google Wave with demos, samples and code

Google Wave team talks about their experience in building Google Wave entirely using Google Web Toolkit (GWT)

Google engineer David Wang explains how collaborative editing through concurrency control and operational transform work in Google Wave.

Google Engineer Casey Whitelaw describes the natural language processing behind Google Wave’s spelling correction on the deck of the Sydney office.

Interviews

Google co-founder Sergey Brin about Google Wave

Google Wave founding Team Interview by TechCrunch

Vic Gundotra, VP Engineering of Google talks about Google Wave

Interview of Stephanie Hannon, Program Manager for Wave

Fun

And at last, a video about how the Google wave team got played off by keyboard cat 😉

Posted in Google/Yahoo | Tagged , | 6 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