VJ’s Warez

Archive for the ‘JAVASCRIPT’ Category

Sam Ruby has that way about him that sees things very clearly. He just took a peak at jQuery for the first time and was able to really put into words what I think jQuery enthusiasts like about the library:

The notable thing about this is that despite all of the asynchronous events taking place, the code is sequential (nested, but sequential), and that the JSON results of the AJAX call is immediately available to the function that is invoked when the selection changes.

This is based on the following code that he wrote:

  1. $(“#archive”).click(function() {
  2. $.getJSON(‘unscanned.cgi’, {}, function(unscanned) {
  3. // replace realname input field with a selection list
  4. var select = $(‘<select name=”realname” id=”realname”/>’)[0];
  5. for (var i=0; i<unscanned .length; i++) {
  6. select.options[i] = new Option(unscanned[i][1], i);
  7. }
  8. $(‘#realname’).before(select).remove();
  9. $(“#archive”).attr(“disabled”,“disabled”);
  10. // process selection
  11. $(‘#realname’).focus().change(function() {
  12. var icla = unscanned[$(“#realname option:selected”).val()];
  13. $(“#realname”).before(‘<input type=”text” ‘ +
  14. ‘id=”realname” name=”realname”/>’).remove();
  15. $(“#realname”).val(icla[1]);
  16. $(“#pubname”).val(icla[2]);
  17. $(“#email”).val(icla[3]);
  18. $(“#replaces”).val(icla[0] + ‘:’ + icla[3]);
  19. $(“#filename”).val().focus();
  20. $(“#archive”).removeAttr(“disabled”);
  21. });
  22. });
  23. return false;
  24. });

Those that love jQuery, love the API.

John himself had an example in the comments:

  1. $(‘:radio[name=is_user]’)
  2. .change(function(){ $(‘.depends-isuser’)[ this.value == 1 ? ‘show’ : ‘hide’ ](); })
  3. .change();

jQuery 1.3 beta 1 has been released with John and the team asking for testing help.

This is a big release as a lot has been changed:

  • Sizzle has been integrated
  • No more browser testing: For example, no more if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { which is replaced with if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
  • Live event delegration: Reglib’s claim to fame was how event delegation was “live” meaning that if you added elements later on, they would also fall into the same delegations. With $("#foo > div").live("click", someFn); you get the same in jQuery
  • $(this).closest("div");: Returns this or closest ancestor that matches selector
  • .offset() rewrite – significantly faster, uses no browser sniffing.
  • .hide()/.show() rewrite – 50% – 200% faster.
  • .append/prepend/before/after rewrite – 10-15x faster.
Tags:

I like getting data from the web and I love JSON – as it is easy to use. The issue is that not many things on the web come as JSON from the get-go. Hence we need converters. You can use cURL and beautiful soup or roll your own hell of regular expressions. Alternatively you can use Yahoo Pipes to build your converter. Pipes is the bomb but a lot of people complained that there is no version control and that you need to use the very graphical interface to get to your data (which was the point of Pipes but let’s not go there).

AlasRejoice for there is a solution now available and it is called YQL. YQL is a SQL-style language to get information from all kind of web services, and – using oAuth – even Yahoo’s social graph. There is a test console available for you to get to grips with all the information it gives you access to (which is a lot!):

The YQL console

Here comes the kicker though: for all the open services that don’t need authentication you can use these YQL statements as a REST API with JSON output and an optional callback function for JSON-P by adding it to http://query.yahooapis.com/v1/public/yql?. For example to get the latest three headlines from Ajaxian’s RSS feed as JSON and wrap it in a function called leechajaxian do the following: Read the rest of this entry »


VJ’s Warez