-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfabtabulous.js
More file actions
55 lines (50 loc) · 1.65 KB
/
fabtabulous.js
File metadata and controls
55 lines (50 loc) · 1.65 KB
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
/*
* Fabtabulous! Simple tabs using Prototype
* http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/
* Andrew Tetlaw
* version 1.1 2006-05-06
* http://creativecommons.org/licenses/by-sa/2.5/
*/
if (typeof Class != "undefined"){ /* lukas: issue 40 */
var Fabtabs = Class.create();
Fabtabs.prototype = {
initialize : function(element) {
this.element = $(element);
var options = Object.extend({}, arguments[1] || {});
if(this.element){ /* lukas: issue 40 */
this.menu = $A(this.element.getElementsByTagName('a'));
this.show(this.getInitialTab());
this.menu.each(this.setupTab.bind(this));
}
},
setupTab : function(elm) {
Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
},
activate : function(ev) {
var elm = Event.findElement(ev, "a");
Event.stop(ev);
this.show(elm);
this.menu.without(elm).each(this.hide.bind(this));
},
hide : function(elm) {
$(elm).removeClassName('active-tab');
$(this.tabID(elm)).removeClassName('active-tab-body');
},
show : function(elm) {
$(elm).addClassName('active-tab');
$(this.tabID(elm)).addClassName('active-tab-body');
},
tabID : function(elm) {
return elm.href.match(/#(\w.+)/)[1];
},
getInitialTab : function() {
if(document.location.href.match(/#(\w.+)/)) {
var loc = RegExp.$1;
var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
return elm || this.menu.first();
} else {
return this.menu.first();
}
}
}
}