Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 12, 2010 19:01
Show Gist options
  • Save ryanflorence/399005 to your computer and use it in GitHub Desktop.
Save ryanflorence/399005 to your computer and use it in GitHub Desktop.
Tabs.Ajax = new Class({
Extends: Tabs, // makes this a sub class of `Tabs`
// can add some new options w/o losing the ones from Tab
options: {
loadingHTML: '<p>Loading...</p>'
},
// give it a new jQuery prototype method
jQuery: 'ajaxTabs',
// change a single method to add wildly different functionality
show: function(index){
var href = jQuery(this.tabs[index]).attr('href');
// detach tabs and prevent default browser behavior
this.detach().tabs.bind('click.stop',function(event){
event.preventDefault();
});
// this.parent calls the `show` method of the parent class
this.parent(index);
var self = this; // for use in ajax callback
this.currentTab.html(this.options.loadingHTML).load(href, function(){
self.attach().fireEvent('ajaxComplete').tabs.unbind('click.stop');
// could have used $.proxy, but storing `this` in `self` is easy enough
});
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment