We had a turnout of 6 tonight and we covered jQuery and some related JavaScript type things. First we covered the basics of jQuery and using CSS selectors for finding and manipulating elements on the page. Then we talked about unobtrusive JavaScript and the benefits of keeping the javascript out of the HTML and applying behavior to the page separately. He's a code snippet we ended up with to do a few things with chaining various calls:
jQuery(function($){
$('.section')
.css('background-color', '#ccc')
.find('img')
.fadeIn()
.click(function(){
$(this).fadeOut()
})
.attr('alt', 'woah!')
.css('padding', 25)
})
Then we looked into using jQuery's implementation of JSONP to add tweets about about rubynation to the page using just client-side JavaScript. Here's the code:
jQuery(function($){
var addTweets = function(data) {
$.each(data.results, function(i){
$('#content').prepend($('<div/>').text('@'+this.from_user+': '+this.text))
})
}
$.getJSON("
http://search.twitter.com/search.json?q=rubynation&jsoncallback=?", addTweets)
})
At one point we were hacking our way through the internals of jQuery to figure out how it makes JSONP work. For those interested, here's an explanation that a think makes some of the code we were looking at more clear:
What it looks like is that all of the jQuery AJAX functions like get, post, getJSON, etc. end up calling the ajax function, which has a few more parameters, one's that match up with some of the variables that we saw when stepping through the code with the Firebug Deubgger.
JSONP is a really neat technique to pull data from servers other than the one the original document was loaded from.
Anyway, topic for next week is still kind of up in the air, maybe Jonathan discussing ExtJS? Maybe Mootools? What about getting into V8?
http://code.google.com/p/v8/I would love to play around with using V8, maybe seeing if we can get it to compile for the iPhone? Would be could to run V8 within iPhone apps.