Lalit (owner)

Fork Of

Revisions

gist: 119762 Download_button fork
public
Public Clone URL: git://gist.github.com/119762.git
Embed All Files: show embed
methodCallStyle.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
On the page, there will be a number of tabs. Each of the tabs will correspond with a panel.
When a tab is selected, it becomes "active" -- the previously active tab becomes inactive.
When a tab becomes active, its associated panel is shown. When a tab becomes inactive, its
associated panel is hidden.
By default, the first tab is active when the tabs are created.
*/
 
var tabs = new $.Widget("ul.tabs");
 
// Base events
var tab = tabs.newType("tab", "a");
 
tab.listen({
  selected: function(tab) {
    tabs.activeTab.deactivate();
    tab.activate();
    tabs.activeTab = tab;
  },
  deactivate: function(tab) {
    tabs.panels.get(tab).hide();
  }
})
 
tabs.listen("default", "initialize", function() {
  tabs.list.first.activate();
});
 
// Default display logic
var panel = tabs.newType("panel", "div");
 
panel.listen("default", {
  show: function(panel) {
    panel.show();
  },
  hide: function(panel) {
    panel.hide();
  }
});
 
tab.listen("default", {
  activate: function(tab) {
    tab.addClass("active");
  },
  deactivate: function(tab) {
    tab.removeClass("active");
  }
});
 
// Setup
tabs.list = new tabs.Array;
 
tabs.find("a").each(function() {
  tabs.panels = new tabs.Hash
  tabs.panels(this, $(this.attr("href"));
  tabs.list.push(this);
}).click(function() {
  tab(this).selected();
});
 
/* AJAX EXTENSION */
 
panel.listen("ajax", "show", function(panel) {
  panel.html("<div class='loading'></div>").load(panel.attr("data-href"));
});
 
/* HASH EXTENSION */
 
tabs.stopListening("default", "initialize")
  .listen("hash", "initialize", function() {
    tab("a[href='" + window.location.hash + "']").activate();
  })
 
tab.listen("hash", "activate", function(tab) {
  window.location.hash = tab.attr("href");
});