jQuery Plugin for using default value as label

Wrote a little plugin for using the default value in text elements as label, you know. Look at the right hand side in the newsletter form for an example.

[sourcecode language='javascript']
$.fn.label = function(options){

var default_settings = {
clearLabels : true
};

var settings = $.extend(default_settings, options);

return this.each(function(){
var elm = $(this);
if($(this).val().length > 0) {
$.data(elm, ‘default’, $(this).val());
elm.focus(function(){
if($(this).val() == $.data(elm, ‘default’)) {
$(this).val(”);
}
}).blur(function(){
if($(this).val() == ”) {
$(this).val($.data(elm, ‘default’));
}
});

if(settings.clearLabels) {
$(this.form).submit(function(){
if($(this).val() == $.data(elm, ‘default’)) {
$(this).val(”);
}
});
}
}
});
}
[/sourcecode]

jQuery, Thickbox and Google Analytics

Today I had to find some way to track the links within a page using Google Analytics, jQuery and Thickbox. With the new ga.js it is pretty straight forward:

[sourcecode language='javascript']
$(function(){
if(typeof(pageTracker) != ‘undefined’) {
$(‘a.thickbox, area.thickbox, input.thickbox’)
.click(
function(){
pageTracker._trackPageview(
$(this).attr(‘href’)
);
}
);
}
}
);
[/sourcecode]