Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created August 14, 2011 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/1145031 to your computer and use it in GitHub Desktop.
Save walterdavis/1145031 to your computer and use it in GitHub Desktop.
var box = $('yourHTMLBox');
var tabs = box.select('h3');
var bodies = box.select('p,ul,dl,table');
var tabStyle = 'background-color:#ccc';
var tabSelected = 'background-color: #dd9'
tabs.invoke('setStyle','display:inline; padding:4px 8px; ' + tabStyle + '; margin:0; cursor:pointer');
bodies.each(function(elm){
elm.hide();
elm._tab = elm.previous('h3');
box.insert({bottom:elm.remove()});
});
tabs.first().setStyle(tabSelected);
tabs.invoke('observe','click',function(evt){
bodies.invoke('hide');
tabs.invoke('setStyle',tabStyle);
var tab = this;
tab.setStyle(tabSelected);
var bods = bodies.findAll(function(elm){
return elm._tab == tab;
});
bods.invoke('show');
});
bodies.findAll(function(elm){
return elm._tab == tabs.first();
}).invoke('show');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment