Guest User

Untitled

a guest
May 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. $(function() {
  2. $areas = $('#areas');
  3. if ($areas) {
  4. add_tabs({
  5. 'my-event': "My first tab",
  6. 'another-event': "My second tab"
  7. })
  8. }
  9. });
  10.  
  11. function add_tabs(tabs) {
  12. if ( typeof(tabs) == "object" ) {
  13. $.each(tabs, function(event, text) {
  14. $new_tab = $('<li><a href="?event=' + event + '">' + text + '</li>');
  15. $areas.append(is_active(event, $new_tab));
  16. });
  17. }
  18. else
  19. throw 'Tabs must be a hash';
  20. }
  21.  
  22. function is_active(event, $tab) {
  23. tab_active = (document.location.href.indexOf(event) != -1) ? true : false;
  24. if ( tab_active )
  25. $tab.addClass("active");
  26. return $tab;
  27. }
Add Comment
Please, Sign In to add comment