quicktabs_bbq.js 970 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @file
  3. * Implements history using the BBQ plugin.
  4. * See http://benalman.com/code/projects/jquery-bbq/examples/fragment-jquery-ui-tabs
  5. */
  6. (function($) {
  7. Drupal.quicktabsBbq = function($tabset, clickSelector, changeSelector) {
  8. changeSelector = changeSelector || clickSelector;
  9. // Define our own click handler for the tabs, overriding the default.
  10. $(clickSelector, $tabset).each(function(i, el){
  11. this.tabIndex = i;
  12. $(this).click(function(e){
  13. e.preventDefault();
  14. var state = {},
  15. id = $tabset.attr('id'), // qt container id
  16. idx = this.tabIndex; // tab index
  17. state[id] = idx;
  18. $.bbq.pushState(state);
  19. });
  20. });
  21. $(window).bind('hashchange', function(e) {
  22. $tabset.each(function() {
  23. var idx = $.bbq.getState(this.id, true);
  24. var $active_link = $(this).find(changeSelector).eq(idx);
  25. $active_link.triggerHandler('change');
  26. });
  27. });
  28. $(window).trigger('hashchange');
  29. }
  30. })(jQuery);