Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created January 4, 2012 08:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagemusha/1559115 to your computer and use it in GitHub Desktop.
Save kagemusha/1559115 to your computer and use it in GitHub Desktop.
jQuery UI Tabs - Basic Setup (Haml,Coffeescript)
Tested on: jquery-ui-1.8.16
To set up, need:
1) an HTML div enclosing the tabs (as a ul) and pages,
2) Javascript initialization function $("..").tabs({options})
HTML:
- consists of enclosing div, a %ul which has links to pages, and tab pages as divs
- link hrefs correspond to tab page ids
(the html in haml)
#tabs
%ul
%li
%a{:href=>"#someTab1"}
%span Some Tab Page
%li
%a{:href=>"#someTab2"}
%span Another Tab Page
#someTab1
I am the first tab page
#someTab2
I am the other tab page
Coffeescript:
#most simple setup
$( "#tabs" ).tabs()
or
#with custom settings
$( "#tabs" ).tabs
#i.e. do something on show tab
show: (event, ui) ->
#optional if want to do something based on tab selection
whichSelected = $("#tabs").tabs('option', 'selected')
#do something
Troubleshooting
1. Make sure jquery and jquery ui javascript files and jquery ui css files installed
2. Make sure all ids are correct
3. Make sure all your list item links are correctly formatted
%li
%a
Reference:
http://jqueryui.com/demos/tabs/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment