Guest User

Untitled

a guest
Jul 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1.  
  2. var Tabs = new SuperClass;
  3.  
  4. (function($){
  5.  
  6. Tabs.include({
  7. init: function(element){
  8. this.element = $(element);
  9. this.element.delegate("li", "click", this.proxy(this.click));
  10. this.activate(this.tabs(":first"));
  11. },
  12.  
  13. tabs: function(sel){
  14. this.element.find("li" + (sel || ""));
  15. },
  16.  
  17. click: function(e){
  18. this.activate($(e.target));
  19. },
  20.  
  21. activate: function(tab){
  22. this.tabs().removeClass("active");
  23. tab.addClass("active");
  24. this.element.change();
  25. }
  26. });
  27.  
  28. $.fn.tabs = function(){
  29. new Tabs(this);
  30. return this;
  31. };
  32.  
  33. })(jQuery);
  34.  
  35.  
  36. var HistoryTabs = new SuperClass(Tabs);
  37.  
  38. (function($){
  39.  
  40. HistoryTabs.include({
  41. init: function(element){
  42. this._super(element);
  43. $(window).bind("hashchange", this.proxy(this.hashChange));
  44. },
  45.  
  46. activate: function(tab){
  47. this._super(tab);
  48. window.location.hash = tab.attr("data-name");
  49. },
  50.  
  51. tabByName: function(name){
  52. return(this.tabs("[data-name='" + name + "']"));
  53. },
  54.  
  55. hashChange: function(){
  56. var tabName = window.location.hash.match(/#(\w+)/)[1];
  57. var tab = this.tabByName(tabName);
  58. if (tab[0]) this.activate(tab);
  59. }
  60. });
  61.  
  62. $.fn.tabs = function(){
  63. new HistoryTabs(this);
  64. return this;
  65. };
  66.  
  67. })(jQuery);
Add Comment
Please, Sign In to add comment